]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_app_session.h
1. Add a buffer to osrfAppSession structure; for future use
[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
38 /**
39         @brief Representation of a session with another application.
40
41         An osrfAppSession is a list of lists.  It includes a list of osrfAppRequests
42         representing outstanding requests.  Each osrfAppRequest includes a list of
43         responses.
44 */
45 struct osrf_app_session_struct {
46
47         /** Our message passing object */
48         transport_client* transport_handle;
49
50         /** The original remote id of the remote service we're talking to */
51         char* orig_remote_id;
52         /** The current remote id of the remote service we're talking to */
53         char* remote_id;
54
55         /** Whom we're talking to if we're a client;
56                 what app we're serving if we're a server */
57         char* remote_service;
58
59         /** The current request thread_trace */
60         int thread_trace;
61         /** Our ID */
62         char* session_id;
63
64         /** Boolean; true if this session does not require connect messages.
65             Assigned a value depending on the compile-time macro ASSUME_STATELESS. */
66         int stateless;
67
68         /** The connect state */
69         enum OSRF_SESSION_STATE state;
70
71         /** SERVER or CLIENT */
72         enum OSRF_SESSION_TYPE type;
73
74         /** the current locale for this session. **/
75         char* session_locale;
76
77         /** let the user use the session to store their own session data. */
78         void* userData;
79
80         /** Callback function for freeing user's session data. */
81         void (*userDataFree) (void*);
82
83         int transport_error;
84
85         /** Hash table of pending requests. */
86         osrfAppRequest* request_hash[ OSRF_REQUEST_HASH_SIZE ];
87
88         /** Boolean: true if the app wants to terminate the process.  Typically this means that */
89         /** a drone has lost its database connection and can therefore no longer function.      */
90         int panic;
91
92         /** Buffer used by server drone to collect outbound response messages */
93         growing_buffer* outbuf;
94 };
95 typedef struct osrf_app_session_struct osrfAppSession;
96
97 // --------------------------------------------------------------------------
98 // PUBLIC API ***
99 // --------------------------------------------------------------------------
100
101 osrfAppSession* osrfAppSessionClientInit( const char* remote_service );
102
103 osrfAppSession* osrf_app_server_session_init(
104                 const char* session_id, const char* our_app, const char* remote_id );
105
106 char* osrf_app_session_set_locale( osrfAppSession*, const char* );
107
108 osrfAppSession* osrf_app_session_find_session( const char* session_id );
109
110 /* DEPRECATED; use osrfAppSessionSendRequest() instead. */
111 int osrfAppSessionMakeRequest(
112                 osrfAppSession* session, const jsonObject* params,
113                 const char* method_name, int protocol, osrfStringArray* param_strings);
114
115 int osrfAppSessionSendRequest(
116                  osrfAppSession* session, const jsonObject* params,
117                  const char* method_name, int protocol );
118
119 void osrf_app_session_set_complete( osrfAppSession* session, int request_id );
120
121 int osrf_app_session_request_complete( const osrfAppSession* session, int request_id );
122
123 osrfMessage* osrfAppSessionRequestRecv(
124                 osrfAppSession* session, int request_id, int timeout );
125
126 void osrf_app_session_request_finish( osrfAppSession* session, int request_id );
127
128 int osrf_app_session_request_resend( osrfAppSession*, int request_id );
129
130 int osrfSendTransportPayload( osrfAppSession* session, const char* payload );
131
132 void osrf_app_session_reset_remote( osrfAppSession* );
133
134 void osrf_app_session_set_remote( osrfAppSession* session, const char* remote_id );
135
136 void osrf_app_session_push_queue( osrfAppSession*, osrfMessage* msg );
137
138 int osrfAppSessionConnect( osrfAppSession* );
139
140 int osrf_app_session_disconnect( osrfAppSession* );
141
142 int osrf_app_session_queue_wait( osrfAppSession*, int timeout, int* recvd );
143
144 void osrfAppSessionFree( osrfAppSession* );
145
146 void osrf_app_session_request_reset_timeout( osrfAppSession* session, int req_id );
147
148 int osrfAppRequestRespond( osrfAppSession* ses, int requestId, const jsonObject* data );
149
150 int osrfAppRequestRespondComplete(
151                 osrfAppSession* ses, int requestId, const jsonObject* data );
152
153 int osrfAppSessionStatus( osrfAppSession* ses, int type,
154                 const char* name, int reqId, const char* message );
155
156 void osrfAppSessionCleanup( void );
157
158 void osrfAppSessionPanic( osrfAppSession* ses );
159
160 #ifdef __cplusplus
161 }
162 #endif
163
164 #endif