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