EII Message Bus C Reference
protocol.h
Go to the documentation of this file.
1 // Copyright (c) 2019 Intel Corporation.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 
27 #ifndef _EII_MESSAGE_BUS_PROTOCOL_H
28 #define _EII_MESSAGE_BUS_PROTOCOL_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include "eii/msgbus/msgbus.h"
35 
39 typedef struct {
40  void* proto_ctx;
41  config_t* config;
42 
43  void (*destroy)(void* ctx);
44  msgbus_ret_t (*publisher_new)(
45  void* ctx, const char* topic, void** pub_ctx);
46  msgbus_ret_t (*publisher_publish)(
47  void* ctx, void* pub_ctx, msg_envelope_t* msg);
48  void (*publisher_destroy)(void* ctx, void* pub_ctx);
49  msgbus_ret_t (*subscriber_new)(
50  void* ctx, const char* topic, void** subscriber);
51  void (*recv_ctx_destroy)(void* ctx, void* recv_ctx);
52  msgbus_ret_t (*request)(
53  void* ctx, void* service_ctx, msg_envelope_t* message);
54  msgbus_ret_t (*response)(
55  void* ctx, void* service_ctx, msg_envelope_t* message);
56  msgbus_ret_t (*service_get)(
57  void* ctx, const char* service_name, void** service_ctx);
58  msgbus_ret_t (*service_new)(
59  void* ctx, const char* service_name, void** service_ctx);
60  msgbus_ret_t (*recv_wait)(
61  void* ctx, void* recv_ctx, msg_envelope_t** message);
62  msgbus_ret_t (*recv_timedwait)(
63  void* ctx, void* recv_ctx, int timeout, msg_envelope_t** message);
64  msgbus_ret_t (*recv_nowait)(
65  void* ctx, void* recv_ctx, msg_envelope_t** message);
66 } protocol_t;
67 
88 typedef struct {
89  protocol_t* (*initialize)(const char*, config_t*);
91 
100 #define EII_MSGBUS_PROTO(proto_name) \
101  protocol_t* proto_##proto_name##_initialize(const char*, config_t*); \
102  void proto_##proto_name##_destroy(void* ctx); \
103  msgbus_ret_t proto_##proto_name##_publisher_new( \
104  void* ctx, const char* topic, void** pub_ctx); \
105  msgbus_ret_t proto_##proto_name##_publisher_publish( \
106  void* ctx, void* pub_ctx, msg_envelope_t* msg); \
107  void proto_##proto_name##_publisher_destroy(void* ctx, void* pub_ctx); \
108  msgbus_ret_t proto_##proto_name##_subscriber_new( \
109  void* ctx, const char* topic, void** subscriber); \
110  void proto_##proto_name##_recv_ctx_destroy(void* ctx, void* recv_ctx); \
111  msgbus_ret_t proto_##proto_name##_recv_wait( \
112  void* ctx, void* recv_ctx, msg_envelope_t** message); \
113  msgbus_ret_t proto_##proto_name##_recv_timedwait( \
114  void* ctx, void* recv_ctx, int timeout, msg_envelope_t** message); \
115  msgbus_ret_t proto_##proto_name##_recv_nowait( \
116  void* ctx, void* recv_ctx, msg_envelope_t** message); \
117  msgbus_ret_t proto_##proto_name##_service_get( \
118  void* ctx, const char* service_name, void** service_ctx); \
119  msgbus_ret_t proto_##proto_name##_service_new( \
120  void* ctx, const char* service_name, void** service_ctx); \
121  msgbus_ret_t proto_##proto_name##_request( \
122  void* ctx, void* service_ctx, msg_envelope_t* msg); \
123  msgbus_ret_t proto_##proto_name##_response( \
124  void* ctx, void* service_ctx, msg_envelope_t* message); \
125  protocol_exports_t PROTO_EXPORTS = { \
126  .initialize=proto_##proto_name##_initialize };
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif // _EII_MESSAGE_BUS_PROTOCOL_H
msgbus_ret_t
msgbus_ret_t
Definition: msgbusret.h:36
msg_envelope_t
Definition: msg_envelope.h:111
protocol_t
Definition: protocol.h:39
protocol_exports_t
Definition: protocol.h:88
msgbus.h
Messaging abstraction interface.