[Opensrf-commits] r1838 - trunk/src/router (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Nov 2 18:21:59 EST 2009


Author: scottmk
Date: 2009-11-02 18:21:52 -0500 (Mon, 02 Nov 2009)
New Revision: 1838

Modified:
   trunk/src/router/osrf_router.c
   trunk/src/router/osrf_router.h
Log:
1. Move the declaration of osrfRouter out of the header
and into osrf_router.c.  There's no need for any other
source file to know about the internals.

2. Eliminate the ROUTER_SOCKFD macro in favor of the new
client_sock_fd() function.  Reason: it needlessly coupled
the osrfRouter and osrfRouterClass structures by requiring
each of them to have a member named "connection".

3. Further tinkering with the comments.

M    src/router/osrf_router.h
M    src/router/osrf_router.c


Modified: trunk/src/router/osrf_router.c
===================================================================
--- trunk/src/router/osrf_router.c	2009-11-02 22:59:43 UTC (rev 1837)
+++ trunk/src/router/osrf_router.c	2009-11-02 23:21:52 UTC (rev 1838)
@@ -5,6 +5,25 @@
 	@brief Implementation of osrfRouter.
 */
 
+/* a router maintains a list of server classes */
+struct osrfRouterStruct {
+
+	osrfHash* classes;    /**< our list of server classes */
+	char* domain;         /**< Domain name of Jabber server. */
+	char* name;           /**< Router's username for the Jabber logon. */
+	char* resource;       /**< Router's resource name for the Jabber logon. */
+	char* password;       /**< Router's password for the Jabber logon. */
+	int port;             /**< Jabber's port number. */
+	sig_atomic_t stop;    /**< To be set by signal handler to interrupt main loop */
+
+	/** Array of client domains that we allow to send requests through us. */
+	osrfStringArray* trustedClients;
+	/** Array of server domains that we allow to register, etc. with us. */
+	osrfStringArray* trustedServers;
+
+	transport_client* connection;
+};
+
 /**
 	@brief Maintains a set of server nodes belonging to the same class.
 */
@@ -61,11 +80,9 @@
 static int osrfRouterHandleMethodNFound( osrfRouter* router, transport_message* msg,
 		osrfMessage* omsg );
 
-#define ROUTER_SOCKFD connection->session->sock_id
 #define ROUTER_REGISTER "register"
 #define ROUTER_UNREGISTER "unregister"
 
-
 #define ROUTER_REQUEST_CLASS_LIST "opensrf.router.info.class.list"
 #define ROUTER_REQUEST_STATS_NODE_FULL "opensrf.router.info.stats.class.node.all"
 #define ROUTER_REQUEST_STATS_CLASS_FULL "opensrf.router.info.stats.class.all"
@@ -91,8 +108,8 @@
 	@param resource Router's resource name for the Jabber logon.
 	@param password Router's password for the Jabber logon.
 	@param port Jabber's port number.
-	@param trustedClients The array of client domains that we allow to send requests through us.
-	@param trustedServers The array of server domains that we allow to register, etc. with us.
+	@param trustedClients Array of client domains that we allow to send requests through us.
+	@param trustedServers Array of server domains that we allow to register, etc. with us.
 	@return Pointer to the newly allocated osrfRouter.
 
 	Don't connect to Jabber yet.  We'll do that later, upon a call to osrfRouterConnect().
@@ -145,12 +162,24 @@
 	return 0;
 }
 
+/**
+	@brief Enter endless loop to receive and respond to input.
+	@param router Pointer to the osrfRouter that's looping.
+	@return 
+
+	On each iteration: wait for incoming messages to arrive on any of our sockets -- i.e.
+	either the top level socket belong to the router or any of the lower level sockets
+	belonging to the classes.  React to the incoming activity as needed.
+
+	We don't exit the loop until we receive a signal to stop.
+*/
 void osrfRouterRun( osrfRouter* router ) {
 	if(!(router && router->classes)) return;
 
-	int routerfd = router->ROUTER_SOCKFD;
+	int routerfd = client_sock_fd( router->connection );
 	int selectret = 0;
 
+	// Loop until a signal handler sets router->stop
 	while( ! router->stop ) {
 
 		fd_set set;
@@ -194,7 +223,7 @@
 
 					osrfLogDebug( OSRF_LOG_MARK, "Checking %s for activity...", classname );
 
-					int sockfd = class->ROUTER_SOCKFD;
+					int sockfd = client_sock_fd( class->connection );
 					if(FD_ISSET( sockfd, &set )) {
 						osrfLogDebug( OSRF_LOG_MARK, "Socket is active: %d", sockfd );
 						numhandled++;
@@ -654,7 +683,7 @@
 	if(!(router && router->classes && set)) return -1;
 
 	FD_ZERO(set);
-	int maxfd = router->ROUTER_SOCKFD;
+	int maxfd = client_sock_fd( router->connection );
 	FD_SET(maxfd, set);
 
 	int sockid;
@@ -666,7 +695,7 @@
 		const char* classname = osrfHashIteratorKey(itr);
 
 		if( classname && (class = osrfRouterFindClass( router, classname )) ) {
-			sockid = class->ROUTER_SOCKFD;
+			sockid = client_sock_fd( class->connection );
 
 			if( osrfUtilsCheckFileDescriptor( sockid ) ) {
 

Modified: trunk/src/router/osrf_router.h
===================================================================
--- trunk/src/router/osrf_router.h	2009-11-02 22:59:43 UTC (rev 1837)
+++ trunk/src/router/osrf_router.h	2009-11-02 23:21:52 UTC (rev 1838)
@@ -20,25 +20,9 @@
 extern "C" {
 #endif
 
-/* a router maintains a list of server classes */
-struct _osrfRouterStruct {
+struct osrfRouterStruct;
+typedef struct osrfRouterStruct osrfRouter;
 
-	osrfHash* classes;    /**< our list of server classes */
-	char* domain;         /**< Domain name of Jabber server. */
-	char* name;           /**< Router's username for the Jabber logon. */
-	char* resource;       /**< Router's resource name for the Jabber logon. */
-	char* password;       /**< Router's password for the Jabber logon. */
-	int port;             /**< Jabber's port number. */
-	sig_atomic_t stop;    /**< To be set by signal handler to interrupt main loop */
-
-	osrfStringArray* trustedClients;
-	osrfStringArray* trustedServers;
-
-	transport_client* connection;
-};
-
-typedef struct _osrfRouterStruct osrfRouter;
-
 /**
   Allocates a new router.  
   @param domain The jabber domain to connect to
@@ -54,9 +38,6 @@
 	const char* password, int port, osrfStringArray* trustedClients,
 	osrfStringArray* trustedServers );
 
-/**
-  Connects the given router to the network
-  */
 int osrfRouterConnect( osrfRouter* router );
 
 /**
@@ -73,16 +54,6 @@
   */
 void osrfRouterFree( osrfRouter* router );
 
-/**
-  Handles connects, disconnects, etc.
-  */
-//int osrfRouterHandeStatusMessage( osrfRouter* router, transport_message* msg );
-
-/**
-  Handles REQUEST messages 
-  */
-//int osrfRouterHandleRequestMessage( osrfRouter* router, transport_message* msg );
-
 #ifdef __cplusplus
 }
 #endif



More information about the opensrf-commits mailing list