1 /*
2  *
3  *   Copyright (C) 2012-2018 by C.H. Huang
4  *   plushuang.tw@gmail.com
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2.1 of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  *  ---
21  *
22  *  In addition, as a special exception, the copyright holders give
23  *  permission to link the code of portions of this program with the
24  *  OpenSSL library under certain conditions as described in each
25  *  individual source file, and distribute linked combinations
26  *  including the two.
27  *  You must obey the GNU Lesser General Public License in all respects
28  *  for all of the code used other than OpenSSL.  If you modify
29  *  file(s) with this exception, you may extend this exception to your
30  *  version of the file(s), but you are not obligated to do so.  If you
31  *  do not wish to do so, delete this exception statement from your
32  *  version.  If you delete this exception statement from all source
33  *  files in the program, then also delete it here.
34  *
35  */
36 
37 #ifndef UG_JSONRPC_SOCKET_H
38 #define UG_JSONRPC_SOCKET_H
39 
40 #include <UgJsonrpc.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 typedef struct UgJsonrpcSocket   UgJsonrpcSocket;
47 typedef struct UgSocketServer    UgSocketServer;
48 
49 // ----------------------------------------------------------------------------
50 // UgJsonrpcSocket: JSON-RPC over Socket
51 
52 //           +-----------------------------+
53 //           |       UgJsonrpcSocket       |    UgJsonrpcArray
54 // buffer <--+--> UgJson <--> UgJsonrpc <--+-->       or
55 //           |                             |    UgJsonrpcObject
56 //           +-----------------------------+
57 
58 #define UG_JSONRPC_SOCKET_MEMBERS  \
59 	UgJson           json;         \
60 	UgJsonrpc        rpc;          \
61 	UgBuffer         buffer;       \
62 	int              socket
63 
64 struct  UgJsonrpcSocket
65 {
66 	UG_JSONRPC_SOCKET_MEMBERS;
67 /*	// ------ UgJsonrpcSocket members ------
68 	UgJson           json;
69 	UgJsonrpc        rpc;
70 	UgBuffer         buffer;
71 	int              socket;
72  */
base_lask_spheroidboost::geometry::projections::detail::lask::base_lask_spheroid73 };
74 
75 void  ug_jsonrpc_socket_init (UgJsonrpcSocket* jrsock);
76 void  ug_jsonrpc_socket_final (UgJsonrpcSocket* jrsock);
77 
78 // ------------------------------------
fwdboost::geometry::projections::detail::lask::base_lask_spheroid79 // Client API
80 void  ug_jsonrpc_socket_close (UgJsonrpcSocket* jrsock);
81 int   ug_jsonrpc_socket_connect (UgJsonrpcSocket* jrsock,
82                                  const char* addr,
83                                  const char* port_or_serv);
84 
85 #if !(defined _WIN32 || defined _WIN64)
86 int   ug_jsonrpc_socket_connect_unix (UgJsonrpcSocket* jrsock,
87                                       const char* path, int path_len);
88 #endif // ! (_WIN32 || _WIN64)
89 
get_nameboost::geometry::projections::detail::lask::base_lask_spheroid90 int   ug_jsonrpc_socket_send (UgJsonrpcSocket* jrsock);
91 int   ug_jsonrpc_socket_receive (UgJsonrpcSocket* jrsock);
92 
93 // ------------------------------------
94 // Server API
95 
96 // one thread handle all connection
97 void  ug_jsonrpc_socket_use_server (UgJsonrpcSocket* jrsock,
98                                     UgSocketServer* server,
setup_lask(Parameters & par)99                                     UgJsonrpcServerFunc callback,
100                                     void* data, void* data2);
101 
102 // one thread handle one connection
103 void  ug_socket_server_run_jsonrpc (UgSocketServer* server,
104                                     UgJsonrpcServerFunc callback,
105                                     void* data, void* data2);
106 
107 #ifdef __cplusplus
108 }
109 #endif
110 
111 #endif  // UG_JSONRPC_SOCKET_H
112 
113