Skip to content

Commit d50966b

Browse files
mikeprosserniMike Prosser
andauthored
PythonPanelService.GetValue() and .TryGetValue() (#112)
* rename to TryGetValue * test___no_value___try_get_value___gets_no_value * client.get_value() and .try_get_value() * cleanup * cleanup * joe's feedback * TryGetValueRequest * _PanelClient should not be public --------- Co-authored-by: Mike Prosser <[email protected]>
1 parent 098c4b2 commit d50966b

11 files changed

+309
-103
lines changed

protos/ni/pythonpanel/v1/python_panel_service.proto

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ option ruby_package = "NI::PythonPanel::V1";
1818
service PythonPanelService {
1919
// Start a panel (or connect to if it has already been started)
2020
// Status Codes for errors:
21-
// - INVALID_ARGUMENT: The specified identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
22-
// - NOT_FOUND: the file for the panel was not found
21+
// - INVALID_ARGUMENT:
22+
// - The panel script filename doesn't end in .py.
23+
// - The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
24+
// - NOT_FOUND:
25+
// - The panel script file was not found.
26+
// - The python executable file was not found.
2327
rpc StartPanel(StartPanelRequest) returns (StartPanelResponse);
2428

2529
// Stop a panel
2630
// Status Codes for errors:
27-
// - INVALID_ARGUMENT: The specified identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
31+
// - INVALID_ARGUMENT:
32+
// - The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
2833
rpc StopPanel(StopPanelRequest) returns (StopPanelResponse);
2934

3035
// Enumerate the panels available in the system, including information about the state of the panels and what values they have.
@@ -33,12 +38,25 @@ service PythonPanelService {
3338

3439
// Get a value for a control on the panel
3540
// Status Codes for errors:
36-
// - INVALID_ARGUMENT: The specified identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
41+
// - INVALID_ARGUMENT:
42+
// - The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
43+
// - The value identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
44+
// - NOT_FOUND:
45+
// - The value with the specified identifier was not found.
3746
rpc GetValue(GetValueRequest) returns (GetValueResponse);
3847

48+
// Try to get a value for a control on the panel
49+
// Status Codes for errors:
50+
// - INVALID_ARGUMENT:
51+
// - The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
52+
// - The value identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
53+
rpc TryGetValue(TryGetValueRequest) returns (TryGetValueResponse);
54+
3955
// Set a value for a control on the panel
4056
// Status Codes for errors:
41-
// - INVALID_ARGUMENT: The specified identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
57+
// - INVALID_ARGUMENT:
58+
// - The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
59+
// - The value identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
4260
rpc SetValue(SetValueRequest) returns (SetValueResponse);
4361
}
4462

@@ -98,6 +116,19 @@ message GetValueRequest {
98116

99117
message GetValueResponse {
100118
// The value
119+
google.protobuf.Any value = 1;
120+
}
121+
122+
message TryGetValueRequest {
123+
// Unique ID of the panel
124+
string panel_id = 1;
125+
126+
// Unique ID of value
127+
string value_id = 2;
128+
}
129+
130+
message TryGetValueResponse {
131+
// The value, if it was found
101132
optional google.protobuf.Any value = 1;
102133
}
103134

src/ni/pythonpanel/v1/python_panel_service_pb2.py

Lines changed: 12 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ni/pythonpanel/v1/python_panel_service_pb2.pyi

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,45 @@ class GetValueResponse(google.protobuf.message.Message):
166166
def value(self) -> google.protobuf.any_pb2.Any:
167167
"""The value"""
168168

169+
def __init__(
170+
self,
171+
*,
172+
value: google.protobuf.any_pb2.Any | None = ...,
173+
) -> None: ...
174+
def HasField(self, field_name: typing.Literal["value", b"value"]) -> builtins.bool: ...
175+
def ClearField(self, field_name: typing.Literal["value", b"value"]) -> None: ...
176+
177+
global___GetValueResponse = GetValueResponse
178+
179+
@typing.final
180+
class TryGetValueRequest(google.protobuf.message.Message):
181+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
182+
183+
PANEL_ID_FIELD_NUMBER: builtins.int
184+
VALUE_ID_FIELD_NUMBER: builtins.int
185+
panel_id: builtins.str
186+
"""Unique ID of the panel"""
187+
value_id: builtins.str
188+
"""Unique ID of value"""
189+
def __init__(
190+
self,
191+
*,
192+
panel_id: builtins.str = ...,
193+
value_id: builtins.str = ...,
194+
) -> None: ...
195+
def ClearField(self, field_name: typing.Literal["panel_id", b"panel_id", "value_id", b"value_id"]) -> None: ...
196+
197+
global___TryGetValueRequest = TryGetValueRequest
198+
199+
@typing.final
200+
class TryGetValueResponse(google.protobuf.message.Message):
201+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
202+
203+
VALUE_FIELD_NUMBER: builtins.int
204+
@property
205+
def value(self) -> google.protobuf.any_pb2.Any:
206+
"""The value, if it was found"""
207+
169208
def __init__(
170209
self,
171210
*,
@@ -175,7 +214,7 @@ class GetValueResponse(google.protobuf.message.Message):
175214
def ClearField(self, field_name: typing.Literal["_value", b"_value", "value", b"value"]) -> None: ...
176215
def WhichOneof(self, oneof_group: typing.Literal["_value", b"_value"]) -> typing.Literal["value"] | None: ...
177216

178-
global___GetValueResponse = GetValueResponse
217+
global___TryGetValueResponse = TryGetValueResponse
179218

180219
@typing.final
181220
class SetValueRequest(google.protobuf.message.Message):

src/ni/pythonpanel/v1/python_panel_service_pb2_grpc.py

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def __init__(self, channel):
3535
request_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.GetValueRequest.SerializeToString,
3636
response_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.GetValueResponse.FromString,
3737
)
38+
self.TryGetValue = channel.unary_unary(
39+
'/ni.pythonpanel.v1.PythonPanelService/TryGetValue',
40+
request_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.TryGetValueRequest.SerializeToString,
41+
response_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.TryGetValueResponse.FromString,
42+
)
3843
self.SetValue = channel.unary_unary(
3944
'/ni.pythonpanel.v1.PythonPanelService/SetValue',
4045
request_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.SetValueRequest.SerializeToString,
@@ -49,8 +54,12 @@ class PythonPanelServiceServicer(object):
4954
def StartPanel(self, request, context):
5055
"""Start a panel (or connect to if it has already been started)
5156
Status Codes for errors:
52-
- INVALID_ARGUMENT: The specified identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
53-
- NOT_FOUND: the file for the panel was not found
57+
- INVALID_ARGUMENT:
58+
- The panel script filename doesn't end in .py.
59+
- The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
60+
- NOT_FOUND:
61+
- The panel script file was not found.
62+
- The python executable file was not found.
5463
"""
5564
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
5665
context.set_details('Method not implemented!')
@@ -59,7 +68,8 @@ def StartPanel(self, request, context):
5968
def StopPanel(self, request, context):
6069
"""Stop a panel
6170
Status Codes for errors:
62-
- INVALID_ARGUMENT: The specified identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
71+
- INVALID_ARGUMENT:
72+
- The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
6373
"""
6474
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
6575
context.set_details('Method not implemented!')
@@ -76,7 +86,22 @@ def EnumeratePanels(self, request, context):
7686
def GetValue(self, request, context):
7787
"""Get a value for a control on the panel
7888
Status Codes for errors:
79-
- INVALID_ARGUMENT: The specified identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
89+
- INVALID_ARGUMENT:
90+
- The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
91+
- The value identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
92+
- NOT_FOUND:
93+
- The value with the specified identifier was not found.
94+
"""
95+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
96+
context.set_details('Method not implemented!')
97+
raise NotImplementedError('Method not implemented!')
98+
99+
def TryGetValue(self, request, context):
100+
"""Try to get a value for a control on the panel
101+
Status Codes for errors:
102+
- INVALID_ARGUMENT:
103+
- The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
104+
- The value identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
80105
"""
81106
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
82107
context.set_details('Method not implemented!')
@@ -85,7 +110,9 @@ def GetValue(self, request, context):
85110
def SetValue(self, request, context):
86111
"""Set a value for a control on the panel
87112
Status Codes for errors:
88-
- INVALID_ARGUMENT: The specified identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
113+
- INVALID_ARGUMENT:
114+
- The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
115+
- The value identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
89116
"""
90117
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
91118
context.set_details('Method not implemented!')
@@ -114,6 +141,11 @@ def add_PythonPanelServiceServicer_to_server(servicer, server):
114141
request_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.GetValueRequest.FromString,
115142
response_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.GetValueResponse.SerializeToString,
116143
),
144+
'TryGetValue': grpc.unary_unary_rpc_method_handler(
145+
servicer.TryGetValue,
146+
request_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.TryGetValueRequest.FromString,
147+
response_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.TryGetValueResponse.SerializeToString,
148+
),
117149
'SetValue': grpc.unary_unary_rpc_method_handler(
118150
servicer.SetValue,
119151
request_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.SetValueRequest.FromString,
@@ -198,6 +230,23 @@ def GetValue(request,
198230
options, channel_credentials,
199231
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
200232

233+
@staticmethod
234+
def TryGetValue(request,
235+
target,
236+
options=(),
237+
channel_credentials=None,
238+
call_credentials=None,
239+
insecure=False,
240+
compression=None,
241+
wait_for_ready=None,
242+
timeout=None,
243+
metadata=None):
244+
return grpc.experimental.unary_unary(request, target, '/ni.pythonpanel.v1.PythonPanelService/TryGetValue',
245+
ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.TryGetValueRequest.SerializeToString,
246+
ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.TryGetValueResponse.FromString,
247+
options, channel_credentials,
248+
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
249+
201250
@staticmethod
202251
def SetValue(request,
203252
target,

0 commit comments

Comments
 (0)