git: do not track vim swo temp file.
[dabba.git] / dabbad / rpc.c
blobd05d03c30611c850ce500452b47e420e8bc4ef94
1 /**
2 * \file rpc.c
3 * \author written by Emmanuel Roullit emmanuel.roullit@gmail.com (c) 2013
4 * \date 2013
5 */
7 #include <stdio.h>
8 #include <string.h>
9 #include <sys/stat.h>
10 #include <errno.h>
12 #include <libdabba-rpc/rpc.h>
13 #include <dabbad/interface.h>
14 #include <dabbad/interface-status.h>
15 #include <dabbad/interface-driver.h>
16 #include <dabbad/interface-pause.h>
17 #include <dabbad/interface-offload.h>
18 #include <dabbad/interface-settings.h>
19 #include <dabbad/interface-coalesce.h>
20 #include <dabbad/interface-capabilities.h>
21 #include <dabbad/interface-statistics.h>
22 #include <dabbad/thread.h>
23 #include <dabbad/capture.h>
24 #include <dabbad/replay.h>
26 /**
27 * \brief Protobuf service structure used by dabbad
30 static Dabba__DabbaService_Service dabba_service =
31 DABBA__DABBA_SERVICE__INIT(dabbad_);
33 /**
34 * \brief Destroy a new dabbad RPC server instance
35 * \param[in] server Pointer to the server context
38 void dabbad_rpc_server_stop(ProtobufC_RPC_Server * server)
40 if (server)
41 protobuf_c_rpc_server_destroy(server, 0);
44 /**
45 * \brief Create a new dabbad RPC server instance
46 * \param[in] name String to RPC server address
47 * \param[in] type Tell if the RPC server listens to Unix or TCP sockets
48 * \return Pointer to RPC server context on success, \c NULL on failure
51 ProtobufC_RPC_Server *dabbad_rpc_server_start(const char *const name,
52 const ProtobufC_RPC_AddressType
53 type)
55 int rc = 0;
56 ProtobufC_RPC_Server *server;
58 assert(name);
59 assert(strlen(name));
60 assert(type == PROTOBUF_C_RPC_ADDRESS_LOCAL
61 || type == PROTOBUF_C_RPC_ADDRESS_TCP);
63 server = protobuf_c_rpc_server_new(type, name,
64 (ProtobufCService *) & dabba_service,
65 NULL);
67 if (server && type == PROTOBUF_C_RPC_ADDRESS_LOCAL) {
68 rc = chmod(name, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
70 if (rc) {
71 dabbad_rpc_server_stop(server);
72 server = NULL;
76 return server;
79 /**
80 * \brief Poll server for new RPC queries to process
81 * \note This function polls for new RPC queries endlessly
84 int dabbad_rpc_msg_poll(void)
86 for (;;)
87 protobuf_c_dispatch_run(protobuf_c_dispatch_default());
89 return 0;