]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/transport_client.h
3d02add05a7eabdb479fedb056ab68ad193ee1a9
[OpenSRF.git] / include / opensrf / transport_client.h
1 #include "transport_session.h"
2 #include <time.h>
3
4 #ifdef DMALLOC
5 #include "dmalloc.h"
6 #endif
7
8 #ifndef TRANSPORT_CLIENT_H
9 #define TRANSPORT_CLIENT_H
10
11 #define MESSAGE_LIST_HEAD 1
12 #define MESSAGE_LIST_ITEM 2
13
14
15 // ---------------------------------------------------------------------------
16 // Represents a node in a linked list.  The node holds a pointer to the next
17 // node (which is null unless set), a pointer to a transport_message, and
18 // and a type variable (which is not really curently necessary).
19 // ---------------------------------------------------------------------------
20 struct message_list_struct {
21         struct message_list_struct* next;
22         transport_message* message;
23         int type;
24 };
25
26 typedef struct message_list_struct transport_message_list;
27 typedef struct message_list_struct transport_message_node;
28
29 // ---------------------------------------------------------------------------
30 // Our client struct.  We manage a list of messages and a controlling session
31 // ---------------------------------------------------------------------------
32 struct transport_client_struct {
33         transport_message_list* m_list;
34         transport_session* session;
35 };
36 typedef struct transport_client_struct transport_client;
37
38 // ---------------------------------------------------------------------------
39 // Allocates and initializes and transport_client.  This does no connecting
40 // The user must call client_free(client) when finished with the allocated
41 // object.
42 // ---------------------------------------------------------------------------
43 transport_client* client_init( char* server, int port );
44
45 // ---------------------------------------------------------------------------
46 // Connects to the Jabber server with the provided information. Returns 1 on
47 // success, 0 otherwise.
48 // ---------------------------------------------------------------------------
49 int client_connect( transport_client* client, 
50                 char* username, char* password, char* resource, int connect_timeout );
51
52 int client_disconnect( transport_client* client );
53
54 // ---------------------------------------------------------------------------
55 // De-allocates memory associated with a transport_client object.  Users
56 // must use this method when finished with a client object.
57 // ---------------------------------------------------------------------------
58 int client_free( transport_client* client );
59
60 // ---------------------------------------------------------------------------
61 //  Sends the given message.  The message must at least have the recipient
62 // field set.
63 // ---------------------------------------------------------------------------
64 int client_send_message( transport_client* client, transport_message* msg );
65
66 // ---------------------------------------------------------------------------
67 // Returns 1 if this client is currently connected to the server, 0 otherwise
68 // ---------------------------------------------------------------------------
69 int client_connected( transport_client* client );
70
71 // ---------------------------------------------------------------------------
72 // This is the message handler required by transport_session.  This handler
73 // takes all incoming messages and puts them into the back of a linked list
74 // of messages.  
75 // ---------------------------------------------------------------------------
76 void client_message_handler( void* client, transport_message* msg );
77
78 // ---------------------------------------------------------------------------
79 // If there are any message in the message list, the 'oldest' message is
80 // returned.  If not, this function will wait at most 'timeout' seconds 
81 // for a message to arrive.  Specifying -1 means that this function will not
82 // return unless a message arrives.
83 // ---------------------------------------------------------------------------
84 transport_message* client_recv( transport_client* client, int timeout );
85
86
87 #endif