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