]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_app_session.h
9c9efadb12e221b85407337cae094ae280db37db
[OpenSRF.git] / include / opensrf / osrf_app_session.h
1 /**
2         @file osrf_app_session.h
3         @brief Header for osrfAppSession.
4 */
5
6 #ifndef OSRF_APP_SESSION_H
7 #define OSRF_APP_SESSION_H
8
9 #include "opensrf/transport_client.h"
10 #include "opensrf/osrf_message.h"
11 #include "opensrf/osrf_system.h"
12 #include "opensrf/string_array.h"
13 #include "opensrf/osrfConfig.h"
14 #include "opensrf/osrf_hash.h"
15 #include "opensrf/osrf_list.h"
16 #include "opensrf/osrf_json.h"
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 enum OSRF_SESSION_STATE {
23         OSRF_SESSION_CONNECTING,
24         OSRF_SESSION_CONNECTED,
25         OSRF_SESSION_DISCONNECTED
26 };
27
28 enum OSRF_SESSION_TYPE {
29         OSRF_SESSION_SERVER,
30         OSRF_SESSION_CLIENT
31 };
32
33 struct osrf_app_request_struct;
34 typedef struct osrf_app_request_struct osrfAppRequest;
35
36 #define OSRF_REQUEST_HASH_SIZE 64
37 #define OSRF_MSG_CHUNK_SIZE    104858 /* 0.1 MB */
38
39 /**
40         @brief Representation of a session with another application.
41
42         An osrfAppSession is a list of lists.  It includes a list of osrfAppRequests
43         representing outstanding requests.  Each osrfAppRequest includes a list of
44         responses.
45 */
46 struct osrf_app_session_struct {
47
48         /** Our message passing object */
49         transport_client* transport_handle;
50
51         /** The original remote id of the remote service we're talking to */
52         char* orig_remote_id;
53         /** The current remote id of the remote service we're talking to */
54         char* remote_id;
55
56         /** Whom we're talking to if we're a client;
57                 what app we're serving if we're a server */
58         char* remote_service;
59
60         /** The current request thread_trace */
61         int thread_trace;
62         /** Our ID */
63         char* session_id;
64
65         /** Boolean; true if this session does not require connect messages.
66             Assigned a value depending on the compile-time macro ASSUME_STATELESS. */
67         int stateless;
68
69         /** The connect state */
70         enum OSRF_SESSION_STATE state;
71
72         /** SERVER or CLIENT */
73         enum OSRF_SESSION_TYPE type;
74
75         /** the current locale for this session. **/
76         char* session_locale;
77
78         /** the current TZ for this session. **/
79         char* session_tz;
80
81         /** let the user use the session to store their own session data. */
82         void* userData;
83
84         /** Callback function for freeing user's session data. */
85         void (*userDataFree) (void*);
86
87         int transport_error;
88
89         /** Hash table of pending requests. */
90         osrfAppRequest* request_hash[ OSRF_REQUEST_HASH_SIZE ];
91
92         /** Boolean: true if the app wants to terminate the process.  Typically this means that */
93         /** a drone has lost its database connection and can therefore no longer function.      */
94         int panic;
95
96         /** Buffer used by server drone to collect outbound response messages */
97         growing_buffer* outbuf;
98 };
99 typedef struct osrf_app_session_struct osrfAppSession;
100
101 // --------------------------------------------------------------------------
102 // PUBLIC API ***
103 // --------------------------------------------------------------------------
104
105 osrfAppSession* osrfAppSessionClientInit( const char* remote_service );
106
107 osrfAppSession* osrf_app_server_session_init(
108                 const char* session_id, const char* our_app, const char* remote_id );
109
110 char* osrf_app_session_set_locale( osrfAppSession*, const char* );
111
112 char* osrf_app_session_set_tz( osrfAppSession*, const char* );
113
114 /* ingress used by all sessions until replaced */
115 char* osrfAppSessionSetIngress( const char* );
116
117 const char* osrfAppSessionGetIngress();
118
119 osrfAppSession* osrf_app_session_find_session( const char* session_id );
120
121 /* DEPRECATED; use osrfAppSessionSendRequest() instead. */
122 int osrfAppSessionMakeRequest(
123                 osrfAppSession* session, const jsonObject* params,
124                 const char* method_name, int protocol, osrfStringArray* param_strings);
125
126 int osrfAppSessionSendRequest(
127                  osrfAppSession* session, const jsonObject* params,
128                  const char* method_name, int protocol );
129
130 void osrf_app_session_set_complete( osrfAppSession* session, int request_id );
131
132 int osrf_app_session_request_complete( const osrfAppSession* session, int request_id );
133
134 osrfMessage* osrfAppSessionRequestRecv(
135                 osrfAppSession* session, int request_id, int timeout );
136
137 void osrf_app_session_request_finish( osrfAppSession* session, int request_id );
138
139 int osrf_app_session_request_resend( osrfAppSession*, int request_id );
140
141 int osrfSendTransportPayload( osrfAppSession* session, const char* payload );
142
143 void osrf_app_session_reset_remote( osrfAppSession* );
144
145 void osrf_app_session_set_remote( osrfAppSession* session, const char* remote_id );
146
147 void osrf_app_session_push_queue( osrfAppSession*, osrfMessage* msg );
148
149 int osrfAppSessionConnect( osrfAppSession* );
150
151 int osrf_app_session_disconnect( osrfAppSession* );
152
153 int osrf_app_session_queue_wait( osrfAppSession*, int timeout, int* recvd );
154
155 void osrfAppSessionFree( osrfAppSession* );
156
157 void osrf_app_session_request_reset_timeout( osrfAppSession* session, int req_id );
158
159 int osrfAppRequestRespond( osrfAppSession* ses, int requestId, const jsonObject* data );
160
161 int osrfAppRequestRespondComplete(
162                 osrfAppSession* ses, int requestId, const jsonObject* data );
163
164 int osrfAppSessionStatus( osrfAppSession* ses, int type,
165                 const char* name, int reqId, const char* message );
166
167 void osrfAppSessionCleanup( void );
168
169 void osrfAppSessionPanic( osrfAppSession* ses );
170
171 #ifdef __cplusplus
172 }
173 #endif
174
175 #endif