### Install PYTIBRV Source: https://github.com/arienchen/pytibrv/blob/master/README.md Export the PYTHONPATH to include the custom library directory where pytibrv is placed. ```shell export PYTHONPATH=$HOME/my_lib ``` -------------------------------- ### Python ctypes Data Type Example (Overflow) Source: https://github.com/arienchen/pytibrv/blob/master/README.md Shows how Python's ctypes can handle C data types but warns about the lack of overflow checking, leading to unexpected results. ```Python # In Python # 0xFFF = int(4095) status = tibrvMsg_UpdateI8(msg, 'I8', 0xFFF) # -> I8 = -1 status = tibrvMsg_UpdateU8(msg, 'U8', 0xFFF) # -> U8 = 255 ``` -------------------------------- ### Tibrv Initialization and Version Source: https://github.com/arienchen/pytibrv/blob/master/README.md Functions for opening, closing, and retrieving the version of the Tibrv connection. ```APIDOC ## Tibrv Initialization and Version ### Description Provides functions to manage the Tibrv connection, including opening, closing, and checking the library version. ### PYTIBRV/API - `tibrv_Open()`: Opens a Tibrv connection. - `tibrv_Close()`: Closes the Tibrv connection. - `tibrv_Version()`: Retrieves the Tibrv library version. ### PYTIBRV/Object - `Tibrv.open()`: Opens a Tibrv connection using the object-oriented interface. - `Tibrv.close()`: Closes the Tibrv connection using the object-oriented interface. - `Tibrv.version()`: Retrieves the Tibrv library version using the object-oriented interface. ### Example Usage (PYTIBRV/API) ```Python status = tibrv_Open() if status != TIBRV_OK: print('ERROR', status, tibrvStatus_GetText(status)) sys.exit(-1) ``` ### Example Usage (PYTIBRV/Object) ```Python status = Tibrv.open() if status != TIBRV_OK: print('ERROR', status, TibrvStatus.text(status)) sys.exit(-1) ``` ``` -------------------------------- ### C Callback Declaration and Usage Source: https://github.com/arienchen/pytibrv/blob/master/README.md Defines a callback function signature and demonstrates its creation in TIBRV/C. ```C typedef void (*tibrvEventCallback) ( tibrvEvent event, tibrvMsg message, void* closure ); ... void my_callback(tibrvEvent event, tibrvMsg message, void * closure) { // do what you need ... } ... status = tibrvEvent_CreateListener(&event, que, my_callback, tx, "_RV. மேம்பட்டது", NULL); ``` -------------------------------- ### Python Callback with Closure for Class Reference Source: https://github.com/arienchen/pytibrv/blob/master/README.md Demonstrates the recommended pattern of using the 'closure' parameter to pass a class instance to a module-level callback function. ```Python # in Python, use closure for your own reference. def my_callback(event, message, closure): my_app = closure if my_app.flags == 0: ... class MyApp: def __init__(self): self.flags = 0 ... def init_rv(slef): # pass self as closure, to be accessed in callback status, listener = tibrvEvent_CreateListener(que, my_callback, tx, '_RV.>', self) ``` -------------------------------- ### Python Callback Implementation Source: https://github.com/arienchen/pytibrv/blob/master/README.md Demonstrates a dynamic callback implementation in Python for TIBRV, without explicit function typedefs. ```Python # Python def my_callback(event: int, messgae: int, closure: object): # do what you need status, sz = tibrvMsg_GetString(message, 'DATA') ... status, listener = tibrvEvent_CreateListener(que, my_callback, tx, '_RV.>', None) ``` -------------------------------- ### PYTIBRV/API Message Creation Source: https://github.com/arienchen/pytibrv/blob/master/README.md Demonstrates how PYTIBRV/API wraps the C API for message creation, returning status and message object as a tuple. This mimics C's pointer return by using Python's tuple return. ```python # PYTIBRV/API def tibrvMsg_Create() -> (tibrv_status, tibrvMsg): # calling C API by ctypes msg = ctypes.c_void_p() status = _rvlib.tibrvMsg_Create(ctypes.byref(msg)) return status, msg.value ... # error handling if status != TIBRV_OK: status, msg = tibrvMsg_Create() # return as tuple [] status = tibrvMsg_UpdateI32(msg, 'AMOUNT', amt) ``` -------------------------------- ### TIBRV Message Creation (C API) Source: https://github.com/arienchen/pytibrv/blob/master/README.md Demonstrates the C API pattern for creating a TIBRV message and updating an integer field. Note the use of pointers for output parameters. ```c // C in tibrv/msg.h tibrv_status tibrvMsg_Create(tibrvMsg * msg) // in your code tibrv_status status; tibrvMsg msg; tibrv_i32 amt = 12345; status = tibrvMsg_Create(&msg) if (TIBRV_OK != status) { // error handling } status = tibrvMsg_UpdateI32(msg, "AMOUNT", amt); ... ``` -------------------------------- ### Open TIBRV Connection Source: https://github.com/arienchen/pytibrv/blob/master/README.md Import necessary functions from pytibrv.api and open a TIBRV connection. ```python from pytibrv.api import * status = tibrv_Open() ``` -------------------------------- ### Open TIBRV Connection (API) Source: https://github.com/arienchen/pytibrv/blob/master/README.md Opens a connection using the PYTIBRV API. Checks for errors and prints status if unsuccessful. ```Python # PYTIBRV/API status = tibrv_Open() if status != TIBRV_OK: print('ERROR', status, tibrvStatus_GetText(status)) sys.exit(-1) ``` -------------------------------- ### PYTIBRV Object Exception Handling (try/except) Source: https://github.com/arienchen/pytibrv/blob/master/README.md Shows how to enable and use exception handling (try/except) for TibrvError in PYTIBRV by setting TibrvStatus.exception(True). ```Python # PYTIBRV/Object # enable exception handling TibrvStatus.exception(True) try: tx = TibrvTx() tx.create(None, None, None) tx.description = 'TEST' except TibrvErrr as er: # error handling print('ERROR', er.code(), er.text()) ``` -------------------------------- ### Python Integer Type Source: https://github.com/arienchen/pytibrv/blob/master/README.md Illustrates that Python integers are objects and demonstrates type checking. ```python >>> x = int(123) >>> type(x) >>> ``` -------------------------------- ### Open TIBRV Connection (Object) Source: https://github.com/arienchen/pytibrv/blob/master/README.md Opens a connection using the PYTIBRV object-oriented interface. Checks for errors and prints status if unsuccessful. ```Python #PYTIBRV/Object status = Tibrv.open() if status != TIBRV_OK: print('ERROR', status, TibrvStatus.text(status)) sys.exit(-1) ``` -------------------------------- ### PYTIBRV Object Error Handling (Return Code) Source: https://github.com/arienchen/pytibrv/blob/master/README.md Demonstrates checking the return status code after calling PYTIBRV object methods for error handling. ```Python # PYTIBRV/Object tx = TibrvTx() status = tx.create(None, None, None) # check return code if status != TIBRV_OK: # erro handling # there is no return code for property tx.description = 'TEST' if tx.error() is not None: # error handling print('ERROR', tx.error().code(), tx.error().text()) ``` -------------------------------- ### Python 3.6+ Callback with Typing Source: https://github.com/arienchen/pytibrv/blob/master/README.md Utilizes Python 3.6's typing module (NewType, Callable) for more explicit callback type hinting. ```Python # Python from typing import NewType, Callable tibrv_status = NewType('tibrv_status', int) # int tibrvId = NewType('tibrvId', int) # int tibrvMsg = NewType('tibrvMsg', int) # c_void_p tibrvEvent = NewType('tibrvEvent', int) # tibrvId tibrvDispatchable = NewType('tibrvDispatchable', int) # tibrvId tibrvQueue = NewType('tibrvQueue', int) # tibrvId ... tibrvEventCallback = Callable[[tibrvEvent, tibrvMsg, object], None] def tibrvEvent_CreateListener(que: tibrvQueue, callback: tibrvEventCallback, tx: tibrvTransport, subj: str, closure: object) -> tibrv_status: ... def my_callback(event: tibrvEvent, messgae: tibrvMsg, closure: object): # do what you need status, sz = tibrvMsg_GetString(message, 'DATA') ... status, listener = tibrvEvent_CreateListener(que, my_callback, tx, '_RV.>', None) ``` -------------------------------- ### Python Class Method as Callback (Incorrect Usage) Source: https://github.com/arienchen/pytibrv/blob/master/README.md Illustrates why a Python class method cannot be directly used as a TIBRV callback due to the implicit 'self' parameter. ```Python # in Python class MyApp: def my_callback(self, event, message, closure): # THIS IS NOT WORK ``` -------------------------------- ### Queue Operations Source: https://github.com/arienchen/pytibrv/blob/master/README.md Functions for creating, managing, and dispatching events within Tibrv queues. ```APIDOC ## Queue Operations ### Description Provides functions for managing Tibrv queues, including creation, destruction, dispatching, and configuration of policies. ### PYTIBRV/API - `tibrvQueue_Create()`: Creates a new Tibrv queue. - `tibrvQueue_Destroy(queue)`: Destroys a Tibrv queue. - `tibrvQueue_Dispatch(queue)`: Dispatches events from a Tibrv queue. - `tibrvQueue_GetCount(queue)`: Gets the number of events in a queue. - `tibrvQueue_GetLimitPolicy(queue)`: Gets the limit policy of a queue. - `tibrvQueue_GetName(queue)`: Gets the name of a queue. - `tibrvQueue_GetPriority(queue)`: Gets the priority of a queue. - `tibrvQueue_Poll(queue)`: Polls for events in a Tibrv queue. - `tibrvQueue_SetLimitPolicy(queue, policy)`: Sets the limit policy of a queue. - `tibrvQueue_SetName(queue, name)`: Sets the name of a queue. - `tibrvQueue_SetPriority(queue, priority)`: Sets the priority of a queue. - `tibrvQueue_TimedDispatch(queue, timeout)`: Dispatches events from a Tibrv queue with a timeout. ### PYTIBRV/Object - `TibrvQueue.create()`: Creates a new Tibrv queue. - `TibrvQueue.destroy()`: Destroys a Tibrv queue. - `TibrvQueue.dispatch()`: Dispatches events from a Tibrv queue. - `TibrvQueue.count()`: Gets the number of events in a queue. - `TibrvQueue.policy()`: Gets the limit policy of a queue. - `TibrvQueue.maxEvents()`: Gets the maximum number of events allowed in the queue. - `TibrvQueue.discardAmount()`: Gets the discard amount for the queue policy. - `TibrvQueue.name` (getter/setter): Gets or sets the name of a queue. - `TibrvQueue.priority` (getter/setter): Gets or sets the priority of a queue. - `TibrvQueue.poll()`: Polls for events in a Tibrv queue. - `TibrvQueue.setPolicy(policy)`: Sets the limit policy of a queue. - `TibrvQueue.timedDispatch` (getter/setter): Gets or sets the timed dispatch behavior of a queue. ### Notes - `tibrvQueue_SetHook()`, `tibrvQueue_GetHook()`, and `tibrvQueue_RemoveHook()` are not available in PYTIBRV. ``` -------------------------------- ### Status Handling Source: https://github.com/arienchen/pytibrv/blob/master/README.md Functions for retrieving text descriptions of Tibrv status codes and handling errors. ```APIDOC ## Status Handling ### Description Provides methods for interpreting Tibrv status codes and managing exceptions. ### PYTIBRV/API - `tibrvStatus_GetText(status)`: Retrieves the text description for a given Tibrv status code. ### PYTIBRV/Object - `TibrvStatus.text(status)`: Retrieves the text description for a given Tibrv status code. - `TibrvStatus.error()`: Returns the last error encountered. - `TibrvStatus.exception()`: Returns the last exception encountered. ### Exception Class - `class TibrvError(Exception)`: Custom exception class for Tibrv errors. ``` -------------------------------- ### Message Operations Source: https://github.com/arienchen/pytibrv/blob/master/README.md Functions for creating, manipulating, and managing Tibrv messages. ```APIDOC ## Message Operations ### Description Provides a comprehensive set of functions for creating, destroying, copying, and manipulating fields within Tibrv messages. ### PYTIBRV/API - `tibrvMsg_Create()`: Creates a new Tibrv message. - `tibrvMsg_Destroy(msg)`: Destroys a Tibrv message. - `tibrvMsg_CreateCopy(msg)`: Creates a copy of a Tibrv message. - `tibrvMsg_Detach(msg)`: Detaches a Tibrv message. - `tibrvMsg_GetCurrentTime()`: Gets the current Tibrv time. - `tibrvMsg_GetNumFields(msg)`: Gets the number of fields in a message. - `tibrvMsg_GetSendSubject(msg)`: Gets the send subject of a message. - `tibrvMsg_SetSendSubject(msg, subject)`: Sets the send subject of a message. - `tibrvMsg_GetReplySubject(msg)`: Gets the reply subject of a message. - `tibrvMsg_SetReplySubject(msg, subject)`: Sets the reply subject of a message. - `tibrvMsg_Reset(msg)`: Resets a Tibrv message. - `tibrvMsg_AddI8(msg, fieldName, value)`: Adds an 8-bit integer field. - `tibrvMsg_AddU8(msg, fieldName, value)`: Adds an unsigned 8-bit integer field. - `tibrvMsg_AddI16(msg, fieldName, value)`: Adds a 16-bit integer field. - `tibrvMsg_AddU16(msg, fieldName, value)`: Adds an unsigned 16-bit integer field. - `tibrvMsg_AddI32(msg, fieldName, value)`: Adds a 32-bit integer field. - `tibrvMsg_AddU32(msg, fieldName, value)`: Adds an unsigned 32-bit integer field. - `tibrvMsg_AddI64(msg, fieldName, value)`: Adds a 64-bit integer field. - `tibrvMsg_AddU64(msg, fieldName, value)`: Adds an unsigned 64-bit integer field. - `tibrvMsg_AddF32(msg, fieldName, value)`: Adds a 32-bit float field. - `tibrvMsg_AddF64(msg, fieldName, value)`: Adds a 64-bit float field. - `tibrvMsg_AddString(msg, fieldName, value)`: Adds a string field. - `tibrvMsg_AddMsg(msg, fieldName, value)`: Adds a nested message field. - `tibrvMsg_AddDateTime(msg, fieldName, value)`: Adds a datetime field. - `tibrvMsg_AddField(msg, fieldName, type)`: Adds a field with a specified type. - `tibrvMsg_UpdateI8(msg, fieldName, value)`: Updates an existing 8-bit integer field. - `tibrvMsg_UpdateU8(msg, fieldName, value)`: Updates an existing unsigned 8-bit integer field. - `tibrvMsg_UpdateI16(msg, fieldName, value)`: Updates an existing 16-bit integer field. - `tibrvMsg_UpdateU16(msg, fieldName, value)`: Updates an existing unsigned 16-bit integer field. - `tibrvMsg_UpdateI32(msg, fieldName, value)`: Updates an existing 32-bit integer field. - `tibrvMsg_UpdateU32(msg, fieldName, value)`: Updates an existing unsigned 32-bit integer field. - `tibrvMsg_UpdateI64(msg, fieldName, value)`: Updates an existing 64-bit integer field. - `tibrvMsg_UpdateU64(msg, fieldName, value)`: Updates an existing unsigned 64-bit integer field. - `tibrvMsg_UpdateF32(msg, fieldName, value)`: Updates an existing 32-bit float field. - `tibrvMsg_UpdateF64(msg, fieldName, value)`: Updates an existing 64-bit float field. - `tibrvMsg_UpdateString(msg, fieldName, value)`: Updates an existing string field. - `tibrvMsg_UpdateStringArray(msg, fieldName, value)`: Updates an existing string array field. - `tibrvMsg_UpdateMsg(msg, fieldName, value)`: Updates an existing nested message field. - `tibrvMsg_UpdateDateTime(msg, fieldName, value)`: Updates an existing datetime field. - `tibrvMsg_UpdateField(msg, fieldName, value)`: Updates an existing field (Deprecated). ### PYTIBRV/Object - `TibrvMsg.create()`: Creates a new Tibrv message. - `TibrvMsg.destroy()`: Destroys a Tibrv message. - `TibrvMsg.copy()`: Creates a copy of a Tibrv message. - `TibrvMsg.detach()`: Detaches a Tibrv message. - `TibrvMsg.now()`: Gets the current Tibrv time. - `TibrvMsg.count()`: Gets the number of fields in a message. - `TibrvMsg.sendSubject` (getter/setter): Gets or sets the send subject of a message. - `TibrvMsg.replySubject` (getter/setter): Gets or sets the reply subject of a message. - `TibrvMsg.reset()`: Resets a Tibrv message. - `TibrvMsg.addI8(fieldName, value)`: Adds an 8-bit integer field. - `TibrvMsg.addU8(fieldName, value)`: Adds an unsigned 8-bit integer field. - `TibrvMsg.addI16(fieldName, value)`: Adds a 16-bit integer field. - `TibrvMsg.addU16(fieldName, value)`: Adds an unsigned 16-bit integer field. - `TibrvMsg.addI32(fieldName, value)`: Adds a 32-bit integer field. - `TibrvMsg.addU32(fieldName, value)`: Adds an unsigned 32-bit integer field. - `TibrvMsg.addI64(fieldName, value)`: Adds a 64-bit integer field. - `TibrvMsg.addU64(fieldName, value)`: Adds an unsigned 64-bit integer field. - `TibrvMsg.addF32(fieldName, value)`: Adds a 32-bit float field. - `TibrvMsg.addF64(fieldName, value)`: Adds a 64-bit float field. - `TibrvMsg.addStr(fieldName, value)`: Adds a string field. - `TibrvMsg.addMsg(fieldName, value)`: Adds a nested message field. - `TibrvMsg.addDateTime(fieldName, value)`: Adds a datetime field. - `TibrvMsg.addField(fieldName, type)`: Adds a field with a specified type. - `TibrvMsg.setI8(fieldName, value)`: Updates an existing 8-bit integer field. - `TibrvMsg.setU8(fieldName, value)`: Updates an existing unsigned 8-bit integer field. - `TibrvMsg.setI16(fieldName, value)`: Updates an existing 16-bit integer field. - `TibrvMsg.setU16(fieldName, value)`: Updates an existing unsigned 16-bit integer field. - `TibrvMsg.setI32(fieldName, value)`: Updates an existing 32-bit integer field. - `TibrvMsg.setU32(fieldName, value)`: Updates an existing unsigned 32-bit integer field. - `TibrvMsg.setI64(fieldName, value)`: Updates an existing 64-bit integer field. - `TibrvMsg.setU64(fieldName, value)`: Updates an existing unsigned 64-bit integer field. - `TibrvMsg.setF32(fieldName, value)`: Updates an existing 32-bit float field. - `TibrvMsg.setF64(fieldName, value)`: Updates an existing 64-bit float field. - `TibrvMsg.setStr(fieldName, value)`: Updates an existing string field. - `TibrvMsg.setMsg(fieldName, value)`: Updates an existing nested message field. - `TibrvMsg.setDateTime(fieldName, value)`: Updates an existing datetime field. - `TibrvMsg.setField(fieldName, value)`: Updates an existing field (Deprecated). ``` -------------------------------- ### Python Function Call by Reference Behavior Source: https://github.com/arienchen/pytibrv/blob/master/README.md Shows that Python's 'call by reference of object' is often immutable, and reassignment within a function does not affect the original variable. ```python # Python def change(x): x = 'ABC' ... # y is still '123' print(y) y = '123' change(y) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.