]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_transgroup.h
Commit autotools patch from Kevin Beswick
[OpenSRF.git] / include / opensrf / osrf_transgroup.h
1 #include <opensrf/transport_client.h>
2 #include <opensrf/transport_message.h>
3 #include <opensrf/osrf_list.h>
4 #include <opensrf/osrf_hash.h>
5 #include <opensrf/osrfConfig.h>
6 #include <opensrf/utils.h>
7 #include <time.h>
8
9 /**
10   Maintains a set of transport clients 
11   */
12
13 struct __osrfTransportGroupStruct {
14         osrfHash* nodes;                                                /* our hash of nodes keyed by domain */
15         osrfHashIterator* itr;                          /* points to the next node in the list */
16 };
17 typedef struct __osrfTransportGroupStruct osrfTransportGroup;
18
19
20 struct __osrfTransportGroupNode {
21         transport_client* connection;           /* our connection to the network */
22         char* domain;                                                   /* the domain we're connected to */
23         char* username;                                         /* username used to connect to the group of servers */
24         char* password;                                         /* password used to connect to the group of servers */
25         char* resource;                                         /* the login resource */
26         int port;                                                               /* port used to connect to the group of servers */
27
28         int active;                                                             /* true if we're able to send data on this connection */
29         time_t lastsent;                                                /* the last time we sent a message */
30 };
31 typedef struct __osrfTransportGroupNode osrfTransportGroupNode;
32
33
34 /**
35   Creates a new group node
36   @param domain The domain we're connecting to
37   @param port The port to connect on
38   @param username The login name
39   @param password The login password
40   @param resource The login resource
41   @return A new transport group node
42   */
43 osrfTransportGroupNode* osrfNewTransportGroupNode( 
44                 char* domain, int port, char* username, char* password, char* resource );
45
46
47 /**
48   Allocates and initializes a new transport group.
49   The first node in the array is the default node for client connections.
50   @param nodes The nodes in the group.
51   */
52 osrfTransportGroup* osrfNewTransportGroup( osrfTransportGroupNode* nodes[], int count );
53
54 /**
55   Attempts to connect all of the nodes in this group.
56   @param grp The transport group
57   @return The number of nodes successfully connected
58   */
59 int osrfTransportGroupConnectAll( osrfTransportGroup* grp );
60
61 void osrfTransportGroupDisconnectAll( osrfTransportGroup* grp );
62
63
64 /**
65   Sends a transport message by going to the next domain in the set.
66   if we have a connection for the recipient domain, then we consider it to be
67   a 'local' message.  Local messages have their recipient domains re-written to
68   match the domain of the next server in the set and they are sent directly to 
69   that server.  If we do not have a connection for the recipient domain, it is 
70   considered a 'remote' message and the message is sent directly (unchanged)
71   to the next connection in the set.
72
73   @param grp The transport group
74   @param msg The message to send 
75   @return 0 on normal successful send.  
76   Returns -1 if the message cannot be sent.  
77   */
78 int osrfTransportGroupSend( osrfTransportGroup* grp, transport_message* msg );
79
80 /**
81   Sends the message to the exact recipient.  No failover is attempted.
82   @return 0 on success, -1 on error.
83   */
84 int osrfTransportGroupSendMatch( osrfTransportGroup* grp, transport_message* msg );
85
86
87 int _osrfTGServerSend( osrfTransportGroup* grp, char* domain, transport_message* msg );
88 int _osrfTGClientSend( osrfTransportGroup* grp, char* domain, transport_message* msg );
89
90 /**
91   Waits on all connections for inbound data.
92   @param grp The transport group
93   @param timeout How long to wait for data.  0 means check for data
94   but don't wait, a negative number means to wait indefinitely
95   @return The received message or NULL if the timeout occurred before a 
96   message was received 
97  */
98 transport_message* osrfTransportGroupRecvAll( osrfTransportGroup* grp, int timeout );
99
100 /**
101   Waits for data from a single domain
102   @param grp The transport group
103   @param domain The domain to wait for data on
104   @param timeout see osrfTransportGroupRecvAll
105   */
106 transport_message* osrfTransportGroupRecv( osrfTransportGroup* grp, char* domain, int timeout );
107
108 /**
109   Tells the group that a message to the given domain failed
110   domain did not make it through;
111   @param grp The transport group
112   @param comain The failed domain
113   */
114 void osrfTransportGroupSetInactive( osrfTransportGroup* grp, char* domain );
115
116
117 /**
118   Finds a node in our list of nodes 
119   */
120 osrfTransportGroupNode* __osrfTransportGroupFindNode( osrfTransportGroup* grp, char* domain );
121
122