le_messaging.h
Go to the documentation of this file.
14 * be combined in one executable, and essentially mediates the direct function calls between them.50 * a server to deny service to other clients. Also, if a client started a blocking request-response57 * client-side and server-side interfaces are identified by name, but the names don't have to match122 * When the session opens, the Event Loop will call the "session open handler" call-back function137 * Before sending a message, the client must first allocate the message from the session's message149 * At this point, the client has handed off the message to the messaging system, and the messaging165 * If the client expects an immediate response from the server, and the client wants to block until168 * block all event handlers that share that thread. That's why le_msg_RequestSyncResponse() should191 * When a server sends a message to the client that is not a response to a request from the client,199 * The payload of a received message can be accessed using le_msg_GetPayloadPtr(), and the client235 * When the client is done using a service, it can close the session using le_msg_CloseSession().251 * automatically closed and deleted by the Legato framework, so there's no need to register process255 * notified when a session gets closed by the server. Servers often keep state on behalf of their256 * clients, and if the server closes the session (or if the system closes the session because the270 * @note If the client closes the session, the client-side session close handler will not be called,278 * (i.e., the thread that called le_msg_CreateSession()). That thread will then call any callbacks283 * To work around this, move the session creation to another thread that that uses the Legato event376 * -# Create a Service object using le_msg_CreateService(), passing in the protocol reference and378 * -# Call le_msg_SetServiceRecvHandler() to register a function to handle messages received from422 * the thread that registered those handlers (which must also be the same thread that created the449 * to that message by calling le_msg_Respond() on that message. le_msg_Respond() sends the message473 * Alternatively, the request payload structure and the response payload structure could be placed498 * @warning Of course, once you've started writing the response payload into the buffer, the request payload505 * through which the client sent it. A reference to the session can be retrieved from the message,507 * server's internal data structures that need to be cleaned up when the client closes the session560 * to ask to be notified when clients close sessions with a given service. This allows the server562 * (or when the system closes the session because the client died). The close handler is passed a594 * To work around this, you could move the service to another thread that that runs the Legato event648 * solve the age-old problem of coordinating the start-up sequence of processes that interact with649 * each other. Far too often, the start-up sequence of multiple interacting processes is addressed651 * waste a lot of CPU cycles and battery power, slow down start-up, and (in the case of arbitrary654 * In Legato, a messaging client can attempt to open a session before the server process has even658 * In this way, clients are guaranteed to wait for the servers they use, without the inefficiency661 * a session with the server, the client is allowed to do that work in parallel with the start-up667 * Message buffer memory is allocated and controlled behind the scenes, inside the Messaging API.691 * server-side interface (service). The binding thereby provides configuration of both routing and694 * Neither the client-side nor the server-side IPC sockets are named. Therefore, no process other696 * connections to the appropriate server based on the binding configuration of the client's interface.766 * @warning DO NOT SEND DIRECTORY FILE DESCRIPTORS. They can be exploited and used to break out of788 * That would reduce the amount of code required in the common case. However, we chose to require789 * that the client release the message explicitly in all cases, because the consequences of using827 //--------------------------------------------------------------------------------------------------831 //--------------------------------------------------------------------------------------------------834 //--------------------------------------------------------------------------------------------------838 //--------------------------------------------------------------------------------------------------841 //--------------------------------------------------------------------------------------------------845 //--------------------------------------------------------------------------------------------------848 //--------------------------------------------------------------------------------------------------852 //--------------------------------------------------------------------------------------------------855 //--------------------------------------------------------------------------------------------------859 //--------------------------------------------------------------------------------------------------862 //--------------------------------------------------------------------------------------------------866 //--------------------------------------------------------------------------------------------------869 //--------------------------------------------------------------------------------------------------874 //--------------------------------------------------------------------------------------------------877 //--------------------------------------------------------------------------------------------------888 //--------------------------------------------------------------------------------------------------890 (896 //--------------------------------------------------------------------------------------------------907 //--------------------------------------------------------------------------------------------------909 (915 //--------------------------------------------------------------------------------------------------927 //--------------------------------------------------------------------------------------------------929 (937 //--------------------------------------------------------------------------------------------------941 //--------------------------------------------------------------------------------------------------952 //--------------------------------------------------------------------------------------------------956 //--------------------------------------------------------------------------------------------------963 //--------------------------------------------------------------------------------------------------967 //--------------------------------------------------------------------------------------------------976 //--------------------------------------------------------------------------------------------------985 //--------------------------------------------------------------------------------------------------999 //--------------------------------------------------------------------------------------------------1003 //--------------------------------------------------------------------------------------------------1010 le_msg_ResponseCallback_t completionCallback; ///< Function to be called when transaction done.1017 //--------------------------------------------------------------------------------------------------1021 //--------------------------------------------------------------------------------------------------1029 //--------------------------------------------------------------------------------------------------1035 //--------------------------------------------------------------------------------------------------1043 //--------------------------------------------------------------------------------------------------1049 //--------------------------------------------------------------------------------------------------1056 //--------------------------------------------------------------------------------------------------1062 //--------------------------------------------------------------------------------------------------1073 //--------------------------------------------------------------------------------------------------1084 //--------------------------------------------------------------------------------------------------1092 //--------------------------------------------------------------------------------------------------1099 //--------------------------------------------------------------------------------------------------1106 //--------------------------------------------------------------------------------------------------1108 * Sets an opaque context value (void pointer) that can be retrieved from that session later using1111 //--------------------------------------------------------------------------------------------------1120 //--------------------------------------------------------------------------------------------------1128 //--------------------------------------------------------------------------------------------------1135 //--------------------------------------------------------------------------------------------------1144 //--------------------------------------------------------------------------------------------------1151 //--------------------------------------------------------------------------------------------------1162 //--------------------------------------------------------------------------------------------------1171 //--------------------------------------------------------------------------------------------------1183 * - This is a client-only function. Servers are expected to use le_msg_AddServiceCloseHandler()1186 //--------------------------------------------------------------------------------------------------1195 //--------------------------------------------------------------------------------------------------1200 //--------------------------------------------------------------------------------------------------1210 //--------------------------------------------------------------------------------------------------1223 //--------------------------------------------------------------------------------------------------1233 //--------------------------------------------------------------------------------------------------1245 //--------------------------------------------------------------------------------------------------1252 //--------------------------------------------------------------------------------------------------1254 * Synchronously open a session with a service. Does not wait for the session to become available1267 * - LE_NOT_FOUND if the server is not currently offering the service to which the client is bound.1268 * - LE_NOT_PERMITTED if the client interface is not bound to any service (doesn't have a binding).1277 //--------------------------------------------------------------------------------------------------1284 //--------------------------------------------------------------------------------------------------1288 //--------------------------------------------------------------------------------------------------1295 //--------------------------------------------------------------------------------------------------1299 //--------------------------------------------------------------------------------------------------1306 //--------------------------------------------------------------------------------------------------1312 //--------------------------------------------------------------------------------------------------1319 //--------------------------------------------------------------------------------------------------1325 //--------------------------------------------------------------------------------------------------1331 //--------------------------------------------------------------------------------------------------1340 //--------------------------------------------------------------------------------------------------1347 //--------------------------------------------------------------------------------------------------1356 //--------------------------------------------------------------------------------------------------1363 //--------------------------------------------------------------------------------------------------1372 //--------------------------------------------------------------------------------------------------1386 //--------------------------------------------------------------------------------------------------1399 //--------------------------------------------------------------------------------------------------1406 //--------------------------------------------------------------------------------------------------1410 //--------------------------------------------------------------------------------------------------1417 //--------------------------------------------------------------------------------------------------1419 * Releases a message object, decrementing its reference count. If the reference count has reached1422 //--------------------------------------------------------------------------------------------------1429 //--------------------------------------------------------------------------------------------------1440 //--------------------------------------------------------------------------------------------------1447 //--------------------------------------------------------------------------------------------------1455 //--------------------------------------------------------------------------------------------------1462 //--------------------------------------------------------------------------------------------------1468 //--------------------------------------------------------------------------------------------------1475 //--------------------------------------------------------------------------------------------------1484 //--------------------------------------------------------------------------------------------------1492 //--------------------------------------------------------------------------------------------------1496 * @return The file descriptor, or -1 if no file descriptor was sent with this message or if the1499 //--------------------------------------------------------------------------------------------------1506 //--------------------------------------------------------------------------------------------------1510 //--------------------------------------------------------------------------------------------------1516 //--------------------------------------------------------------------------------------------------1522 //--------------------------------------------------------------------------------------------------1529 //--------------------------------------------------------------------------------------------------1544 //--------------------------------------------------------------------------------------------------1553 //--------------------------------------------------------------------------------------------------1580 //--------------------------------------------------------------------------------------------------1587 //--------------------------------------------------------------------------------------------------1599 //--------------------------------------------------------------------------------------------------1610 //--------------------------------------------------------------------------------------------------1618 //--------------------------------------------------------------------------------------------------1626 //--------------------------------------------------------------------------------------------------1630 * This must be called before any client can connect to the service, for example in COMPONENT_INIT1633 //--------------------------------------------------------------------------------------------------1642 //--------------------------------------------------------------------------------------------------1648 //--------------------------------------------------------------------------------------------------1654 //--------------------------------------------------------------------------------------------------1660 //--------------------------------------------------------------------------------------------------1668 //--------------------------------------------------------------------------------------------------1675 //--------------------------------------------------------------------------------------------------1683 //--------------------------------------------------------------------------------------------------1690 //--------------------------------------------------------------------------------------------------1697 //--------------------------------------------------------------------------------------------------1704 //--------------------------------------------------------------------------------------------------1713 //--------------------------------------------------------------------------------------------------1720 //--------------------------------------------------------------------------------------------------1730 //--------------------------------------------------------------------------------------------------1740 //--------------------------------------------------------------------------------------------------1747 //--------------------------------------------------------------------------------------------------1753 //--------------------------------------------------------------------------------------------------1760 //--------------------------------------------------------------------------------------------------1767 //--------------------------------------------------------------------------------------------------1774 //--------------------------------------------------------------------------------------------------1782 //--------------------------------------------------------------------------------------------------1789 //--------------------------------------------------------------------------------------------------1795 //--------------------------------------------------------------------------------------------------1802 //--------------------------------------------------------------------------------------------------1807 * @return Reference to the message being handled, or NULL if no Service message receive handler1810 //--------------------------------------------------------------------------------------------------1817 //--------------------------------------------------------------------------------------------------1822 * - if the caller is not running a server-side IPC function, kills the caller (doesn't return).1824 //--------------------------------------------------------------------------------------------------le_msg_MessageRef_t le_msg_GetServiceRxMsg(void)void le_msg_AddRef(le_msg_MessageRef_t msgRef)bool le_msg_NeedsResponse(le_msg_MessageRef_t msgRef)LE_FULL_API le_msg_InterfaceRef_t le_msg_GetSessionInterface(le_msg_SessionRef_t sessionRef)void * contextPtrOpaque value to be passed to handler function.Definition: le_messaging.h:1011void le_msg_ReleaseMsg(le_msg_MessageRef_t msgRef)le_result_t le_msg_GetClientUserCreds(le_msg_SessionRef_t sessionRef, uid_t *userIdPtr, pid_t *processIdPtr)LE_FULL_API void le_msg_DeleteService(le_msg_ServiceRef_t serviceRef)Definition: le_messaging.h:968void le_msg_SetServiceRecvHandler(le_msg_ServiceRef_t serviceRef, le_msg_ReceiveHandler_t handlerFunc, void *contextPtr)le_msg_SessionRef_t le_msg_CreateLocalSession(le_msg_LocalService_t *servicePtr)void(* le_msg_SessionEventHandler_t)(le_msg_SessionRef_t sessionRef, void *contextPtr)Definition: le_messaging.h:890le_result_t le_msg_TryOpenSessionSync(le_msg_SessionRef_t sessionRef)void le_msg_AdvertiseService(le_msg_ServiceRef_t serviceRef)Definition: le_messaging.h:942void le_msg_DeleteSession(le_msg_SessionRef_t sessionRef)void le_msg_SetSessionRecvHandler(le_msg_SessionRef_t sessionRef, le_msg_ReceiveHandler_t handlerFunc, void *contextPtr)void * le_msg_GetPayloadPtr(le_msg_MessageRef_t msgRef)void le_msg_GetSessionCloseHandler(le_msg_SessionRef_t sessionRef, le_msg_SessionEventHandler_t *handlerFunc, void **contextPtr)le_msg_ServiceRef_t le_msg_InitLocalService(le_msg_LocalService_t *servicePtr, const char *serviceNameStr, le_mem_PoolRef_t messagingPoolRef)LE_FULL_API void le_msg_SetServiceContextPtr(le_msg_ServiceRef_t serviceRef, void *contextPtr)LE_FULL_API le_msg_SessionEventHandlerRef_t le_msg_AddServiceOpenHandler(le_msg_ServiceRef_t serviceRef, le_msg_SessionEventHandler_t handlerFunc, void *contextPtr)struct le_msg_ClientInterface * le_msg_ClientInterfaceRef_tDefinition: le_messaging.h:853Definition: le_messaging.h:1004size_t le_msg_GetMaxPayloadSize(le_msg_MessageRef_t msgRef)le_msg_SessionRef_t le_msg_GetSession(le_msg_MessageRef_t msgRef)LE_FULL_API le_msg_ProtocolRef_t le_msg_GetSessionProtocol(le_msg_SessionRef_t sessionRef)void le_msg_SetFd(le_msg_MessageRef_t msgRef, int fd)void(* le_msg_ReceiveHandler_t)(le_msg_MessageRef_t msgRef, void *contextPtr)Definition: le_messaging.h:909LE_FULL_API void * le_msg_GetSessionContextPtr(le_msg_SessionRef_t sessionRef)void le_msg_Send(le_msg_MessageRef_t msgRef)struct le_msg_SessionEventHandler * le_msg_SessionEventHandlerRef_tDefinition: le_messaging.h:875LE_FULL_API void le_msg_SetSessionContextPtr(le_msg_SessionRef_t sessionRef, void *contextPtr)le_thread_Ref_t threadThread on which receive should be processes.Definition: le_messaging.h:970void le_msg_CloseSession(le_msg_SessionRef_t sessionRef)bool serviceReadyIndicate if service is ready.Definition: le_messaging.h:992le_mem_PoolRef_t messagePoolPool for messages on this service.Definition: le_messaging.h:995le_msg_ReceiveHandler_t handlerHandler function which should be called on thread.Definition: le_messaging.h:971int fdFile descriptor sent with message (via Get/SetFd)Definition: le_messaging.h:1007LE_FULL_API le_msg_SessionRef_t le_msg_CreateSession(le_msg_ProtocolRef_t protocolRef, const char *interfaceName)LE_FULL_API const char * le_msg_GetInterfaceName(le_msg_InterfaceRef_t interfaceRef)le_msg_MessageRef_t le_msg_CreateMsg(le_msg_SessionRef_t sessionRef)void le_msg_CloseSessionLocked(le_msg_SessionRef_t sessionRef)int le_msg_GetFd(le_msg_MessageRef_t msgRef)void le_msg_RequestResponse(le_msg_MessageRef_t msgRef, le_msg_ResponseCallback_t handlerFunc, void *contextPtr)Definition: le_messaging.h:986le_result_t le_msg_GetClientProcessId(le_msg_SessionRef_t sessionRef, pid_t *processIdPtr)void le_msg_OpenSession(le_msg_SessionRef_t sessionRef, le_msg_SessionEventHandler_t callbackFunc, void *contextPtr)le_msg_LocalReceiver_t receiverServer destination.Definition: le_messaging.h:994LE_FULL_API void * le_msg_GetServiceContextPtr(le_msg_ServiceRef_t serviceRef)le_msg_ResponseCallback_t completionCallbackFunction to be called when transaction done.Definition: le_messaging.h:1010void * contextPtrContext pointer to pass to the handler.Definition: le_messaging.h:972void le_msg_Respond(le_msg_MessageRef_t msgRef)LE_FULL_API void le_msg_HideService(le_msg_ServiceRef_t serviceRef)LE_FULL_API le_msg_ProtocolRef_t le_msg_GetProtocolRef(const char *protocolId, size_t largestMsgSize)LE_FULL_API void le_msg_SetSessionCloseHandler(le_msg_SessionRef_t sessionRef, le_msg_SessionEventHandler_t handlerFunc, void *contextPtr)void(* le_msg_ResponseCallback_t)(le_msg_MessageRef_t msgRef, void *contextPtr)Definition: le_messaging.h:929le_result_t le_msg_GetClientUserId(le_msg_SessionRef_t sessionRef, uid_t *userIdPtr)LE_FULL_API le_msg_ProtocolRef_t le_msg_GetInterfaceProtocol(le_msg_InterfaceRef_t interfaceRef)le_msg_MessageRef_t le_msg_RequestSyncResponse(le_msg_MessageRef_t msgRef)LE_FULL_API void le_msg_RemoveServiceHandler(le_msg_SessionEventHandlerRef_t handlerRef)le_sem_Ref_t responseReadySemaphore which will be set when response is ready.Definition: le_messaging.h:1008void le_msg_OpenSessionSync(le_msg_SessionRef_t sessionRef)LE_FULL_API le_msg_ServiceRef_t le_msg_CreateService(le_msg_ProtocolRef_t protocolRef, const char *interfaceName)LE_FULL_API const char * le_msg_GetProtocolIdStr(le_msg_ProtocolRef_t protocolRef)le_msg_SessionRef_t sessionRefSession for this message.Definition: le_messaging.h:959LE_FULL_API size_t le_msg_GetProtocolMaxMsgSize(le_msg_ProtocolRef_t protocolRef)Definition: le_messaging.h:957le_msg_SessionEventHandlerRef_t le_msg_AddServiceCloseHandler(le_msg_ServiceRef_t serviceRef, le_msg_SessionEventHandler_t handlerFunc, void *contextPtr)bool needsResponseTrue if message needs a response.Definition: le_messaging.h:1009