RPC
plantimager.commons.RPC Link
NoResult Link
NoResult(error, traceback)
Represents an outcome with no result, typically used to indicate an operation failure along with associated error details.
This class encapsulates the error message and traceback information to provide a structured representation of operation failures, useful for logging or debugging purposes.
This class is Falsey
Attributes:
Name | Type | Description |
---|---|---|
error |
str
|
A string containing the error message describing the nature of the failure. |
traceback |
str
|
A string containing the traceback or detailed information about where and why the failure occurred. |
Source code in plantimager/commons/RPC.py
59 60 61 |
|
RPCClient Link
RPCClient(context, url)
Abstract class for RPC clients.
To use, create a class inheriting from the interface and this.
This new class must be decorated with @RPCClient.register_interface
Source code in plantimager/commons/RPC.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
RPCProperty Link
RPCProperty(fget=None, fset=None, fdel=None, doc=None, notify=None)
Bases: property
Declares a property for RPC usage. When the notify signal is emitted the proxy on the RPC Client is updated. The signal provided in notify must be emitted in the setter when the property changes.
Source code in plantimager/commons/RPC.py
93 94 95 |
|
RPCServer Link
RPCServer(context, url)
RPCServer to use in combination with RPCClient.
The server holds the concrete implementation of an interface that is made available on the network.
To create an RPCServer create a class inheriting from an interface and RPCServer. Callable
methods must be decorated using RPCServer.register_method_buffer
or RPCServer.register_method_json
.
The server is also capable of sending signals defined by the RPCSignal class and proxying properties
defined with RPCProperty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
Context
|
ZMQ context used to make the various sockets necessary for communicating with the client. |
required |
url
|
str
|
Url where the RPCServer should listen. It should be of the form "tcp:// |
required |
Attributes:
Name | Type | Description |
---|---|---|
context |
Context
|
ZMQ context used to make the various sockets necessary for communicating with the client. |
url |
str
|
Url where the RPCServer is opened. |
port |
int
|
Port where the RPCServer is opened. |
name |
int
|
Name of the RPCServer as given by the deviceregistry once registered |
uuid |
str
|
Unique identifier of this RPCServer given by the registry once registered.. |
peer_addr |
str
|
Ip address of the client once connected. |
Source code in plantimager/commons/RPC.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
|
register_method_buffer
staticmethod
Link
register_method_buffer(timeout=10000)
Registers this method as remote callable procedure which will transmit its output as a buffer-like object as well as a buffer_info dictionary.
method
may take any input which will be serialized via json and must output a 2-tuple:
(memoryview or bytes, dict).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout
|
int | None
|
Specifies how much time in ms a client is expected to wait for the method to finish. If None, waits indefinitely. |
10000
|
Returns:
Name | Type | Description |
---|---|---|
decorator |
Callable[Callable[..., tuple[memoryview | bytes, dict]], Callable[..., tuple[memoryview | bytes, dict]]]
|
|
Source code in plantimager/commons/RPC.py
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
|
register_method_json
staticmethod
Link
register_method_json(timeout=10000)
Registers this method as remote callable procedure which will transmit its output via json. It is advised to only send basic types and containers as output (int, float, str, bool, list, tuple, dict, ...) Arguments are also serialized via json.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout
|
int | None
|
Specifies how much time in ms a client is expected to wait for the method to finish. If None, waits indefinitely. |
10000
|
Returns:
Name | Type | Description |
---|---|---|
decorator |
Callable[Callable[..., Any], Callable[..., Any]]
|
|
Source code in plantimager/commons/RPC.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
|
register_to_registry Link
register_to_registry(type_, name, registry_url)
Register this RPCServer to the registry at registry_address
as a device of type type_
and name name
.
Note: The name not be accepted as is and may be modified by the registry to avoid duplicate. This method returns the accepted name of this device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_
|
str
|
Name of the device type. |
required |
name
|
str
|
Proposed name of the device. |
required |
registry_url
|
str
|
Url of the device registry. Must have the form "tcp:// |
required |
Returns:
Name | Type | Description |
---|---|---|
accepted_name |
str
|
Name of this device as accepted by the registry. |
Source code in plantimager/commons/RPC.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
|
serve_forever Link
serve_forever()
Starts serving requests for this RPCServer.
Source code in plantimager/commons/RPC.py
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 |
|
RPCSignalReceiver Link
RPCSignalReceiver(context, url, signals)
Bases: Thread
A receiver thread for RPCClient to listen for and receive RPC Signals from the server and in turn emit the same signals in the proxy.
Source code in plantimager/commons/RPC.py
106 107 108 109 110 111 112 113 114 |
|