[netperf-dev] netperf4 commit notice r217 - branches/gobject_migration/src

raj at netperf.org raj at netperf.org
Thu Mar 15 14:27:09 PST 2007


Author: raj
Date: 2007-03-15 14:27:08 -0800 (Thu, 15 Mar 2007)
New Revision: 217

Modified:
   branches/gobject_migration/src/netperf-control.c
   branches/gobject_migration/src/netperf-control.h
   branches/gobject_migration/src/netperf-netserver.c
   branches/gobject_migration/src/netperf-netserver.h
Log:
eghads we can connect a netserver and be in the correct state

Modified: branches/gobject_migration/src/netperf-control.c
===================================================================
--- branches/gobject_migration/src/netperf-control.c	2007-03-15 21:52:04 UTC (rev 216)
+++ branches/gobject_migration/src/netperf-control.c	2007-03-15 22:27:08 UTC (rev 217)
@@ -58,7 +58,8 @@
   CONTROL_PROP_REMOTEFAMILY,
   CONTROL_PROP_LOCALHOST,
   CONTROL_PROP_LOCALPORT,
-  CONTROL_PROP_LOCALFAMILY
+  CONTROL_PROP_LOCALFAMILY,
+  CONTROL_PROP_NETSERVER
 };
 
 /* some forward declarations to make the compiler happy regardless of
@@ -137,6 +138,7 @@
   GParamSpec *localhost_param;
   GParamSpec *localport_param;
   GParamSpec *localfamily_param;
+  GParamSpec *netserver_param;
 
   /* and on with the show */
   GObjectClass *g_object_class;
@@ -212,6 +214,12 @@
 		      AF_UNSPEC,
 		      G_PARAM_READWRITE);
 
+  netserver_param = 
+    g_param_spec_pointer("netserver",
+			 "owning netserver",
+			 "pointer to the owning netserver object",
+			 G_PARAM_READWRITE);
+
   /* overwrite the base object methods with our own get and set
      property routines */
 
@@ -255,6 +263,10 @@
 				  CONTROL_PROP_LOCALFAMILY,
 				  localfamily_param);
 
+  g_object_class_install_property(g_object_class,
+				  CONTROL_PROP_NETSERVER,
+				  netserver_param);
+
   /* we would set the signal handlers for the class here. we might
      have a signal say for the arrival of a complete message or
      perhaps the cotnrol connection going down or somesuch. */
@@ -333,7 +345,12 @@
 
   /* REVISIT - do the g_io_channel stuff here */
 
+  /* REVISIT this should be conditional on all the control connection stuff
+     being successful */
+  g_signal_emit_by_name(control->netserver,"control_connected");
+
 }
+
 /* get and set property routines */
 static void netperf_control_set_property(GObject *object,
 					   guint prop_id,
@@ -379,6 +396,10 @@
     control->localfamily = g_value_get_uint(value);
     break;
 
+  case CONTROL_PROP_NETSERVER:
+    control->netserver = g_value_get_pointer(value);
+    break;
+
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
     break;
@@ -427,6 +448,10 @@
     g_value_set_uint(value, control->localfamily);
     break;
 
+  case CONTROL_PROP_NETSERVER:
+    g_value_set_pointer(value, control->netserver);
+    break;
+
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
     break;

Modified: branches/gobject_migration/src/netperf-control.h
===================================================================
--- branches/gobject_migration/src/netperf-control.h	2007-03-15 21:52:04 UTC (rev 216)
+++ branches/gobject_migration/src/netperf-control.h	2007-03-15 22:27:08 UTC (rev 217)
@@ -49,6 +49,11 @@
   /* the parent object - in this case a GObject object */
   GObject parent_instance;
 
+  /* one wonders if this should be something other than void * */
+  void *netserver; /* the object pointer of the netserver which "owns"
+		      this control object. used to allow us to send it
+		      signals like "connected" and the like */
+
   /* the rest of the control stuff goes here.  how much should be
      "public" and how much "private" I've no idea... */
   control_state_t  state;     /* the present state of the control */

Modified: branches/gobject_migration/src/netperf-netserver.c
===================================================================
--- branches/gobject_migration/src/netperf-netserver.c	2007-03-15 21:52:04 UTC (rev 216)
+++ branches/gobject_migration/src/netperf-netserver.c	2007-03-15 22:27:08 UTC (rev 217)
@@ -169,10 +169,10 @@
 			 working happened to do so... */
 };
 
-static void netperf_netserver_connect(NetperfNetserver *netserver);
 static void netperf_netserver_new_message(NetperfNetserver *netserver, gpointer message);
 static void netperf_netserver_control_closed(NetperfNetserver *netserver);
 static void netperf_netserver_connect_control(NetperfNetserver *netserver);
+static void netperf_netserver_control_connected(NetperfNetserver *netserver);
 
 /* a place to stash the id's returned by g_signal_new should we ever
    need to refer to them by their ID. */ 
@@ -295,6 +295,7 @@
   klass->new_message = netperf_netserver_new_message;
   klass->control_closed = netperf_netserver_control_closed;
   klass->connect_control = netperf_netserver_connect_control;
+  klass->control_connected = netperf_netserver_control_connected;
 
   netperf_netserver_signals[NEW_MESSAGE] = 
     g_signal_new("new_message",            /* signal name */
@@ -333,6 +334,17 @@
 		 g_cclosure_marshal_VOID__VOID,
 		 G_TYPE_NONE,
 		 0);
+
+  netperf_netserver_signals[CONTROL_CONNECTED] = 
+    g_signal_new("control_connected",
+		 TYPE_NETPERF_NETSERVER,
+		 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
+		 G_STRUCT_OFFSET(NetperfNetserverClass, control_connected),
+		 NULL,
+		 NULL,
+		 g_cclosure_marshal_VOID__VOID,
+		 G_TYPE_NONE,
+		 0);
 		 
 }
 
@@ -1453,52 +1465,89 @@
   int      localfamily;
   int      remotefamily;
 
-  /* validation means that we know that the host informaion is in attributes
-     of the netserver element. The xml parser checked them and initialized
-     any optional attributes which where not present.  sgb 2003-10-11 */
+  if (NETSERVER_PREINIT == server->state) {
+    /* validation means that we know that the host informaion is in
+       attributes of the netserver element. The xml parser checked
+       them and initialized any optional attributes which where not
+       present.  sgb 2003-10-11 */
+    
+    /* pull the remote address family, service and host attributes */
+    remotefamily = strtofam(xmlGetProp(server->node,(const xmlChar *)"family"));
+    remoteport   = xmlGetProp(server->node,(const xmlChar *)"remote_service");
+    remotehost   = xmlGetProp(server->node,(const xmlChar *)"remote_host");
+    
+    /* for the time being, the netserver element definition provides only
+       one family attribute - this means no mixed family stuff, which should
+       not be a problem for the moment.  since getaddrinfo() takes a servname
+       parm as an ASCII string we will just pass the string. sgb 2003-10-11 */
+    
+    /* now pull the local address family, service and host attributes */
+    localfamily  = strtofam(xmlGetProp(server->node,(const xmlChar *)"family"));
+    localport    = xmlGetProp(server->node,(const xmlChar *)"local_service");
+    localhost    = xmlGetProp(server->node,(const xmlChar *)"local_host");
+    
+    g_print("server %s asking for new control object with remote %s %s %d local %s %s %d\n",
+	    server->id,
+	    remotehost, 
+	    remoteport,
+	    remotefamily,
+	    localhost,
+	    localport,
+	    localfamily);
+    
+    /* armed with this information, create a control object and give it
+       what it needs to do its work, then tell it to go ahead and
+       connect. should this become a g_object_weak_pointer reference? */
+    server->control_object= g_object_new(TYPE_NETPERF_CONTROL,
+					 "remotefamily", remotefamily,
+					 "remotehost", remotehost,
+					 "remoteport", remoteport,
+					 "localfamily", localfamily,
+					 "localhost", localhost,
+					 "localport", localport,
+					 "netserver", server,
+					 NULL);
+    /* set our desired state correctly so when we receive the signal
+       we are connected the right things can happen */
+    server->state_req = NETSERVER_CONNECTED;
+    /* and now signal it to connect-up */
+    g_signal_emit_by_name(server->control_object,
+			  "connect");
+  }
+  else {
+    /* just what should we do if we are signaled to connect and we are
+       not in NETSERVER_PREINIT? */
+    g_print("%s Yo! netserver at %p id %s was asked to connect when it was in state %s rather than NETSERVER_PREINIT!\n",
+	    __func__,
+	    server,
+	    server->id,
+	    server->state);
+  }
+    
+}
 
-  /* pull the remote address family, service and host attributes */
-  remotefamily = strtofam(xmlGetProp(server->node,(const xmlChar *)"family"));
-  remoteport   = xmlGetProp(server->node,(const xmlChar *)"remote_service");
-  remotehost   = xmlGetProp(server->node,(const xmlChar *)"remote_host");
+static void netperf_netserver_control_connected(NetperfNetserver *netserver)
+{
 
-  /* for the time being, the netserver element definition provides only
-     one family attribute - this means no mixed family stuff, which should
-     not be a problem for the moment.  since getaddrinfo() takes a servname
-     parm as an ASCII string we will just pass the string. sgb 2003-10-11 */
+  /* since we are connected, we can transition to the CONNECTED state
+     - REVISIT - should we be checking against the current state? */
 
-  /* now pull the local address family, service and host attributes */
-  localfamily  = strtofam(xmlGetProp(server->node,(const xmlChar *)"family"));
-  localport    = xmlGetProp(server->node,(const xmlChar *)"local_service");
-  localhost    = xmlGetProp(server->node,(const xmlChar *)"local_host");
-
-  g_print("server %s asking for new control object with remote %s %s %d local %s %s %d\n",
-	  server->id,
-	  remotehost, 
-	  remoteport,
-	  remotefamily,
-	  localhost,
-	  localport,
-	  localfamily);
-
-  /* armed with this information, create a control object and give it
-     what it needs to do its work, then tell it to go ahead and
-     connect. should this become a g_object_weak_pointer reference? */
-  server->control_object= g_object_new(TYPE_NETPERF_CONTROL,
-				       "remotefamily", remotefamily,
-				       "remotehost", remotehost,
-				       "remoteport", remoteport,
-				       "localfamily", localfamily,
-				       "localhost", localhost,
-				       "localport", localport,
-				       NULL);
-
-  /* and now signal it to connect-up */
-  g_signal_emit_by_name(server->control_object,
-			"connect");
-
+  if (NETSERVER_PREINIT == netserver->state) {
+    g_print("%s Netserver %p has been informed that the control connection is connected\n",
+	    __func__,
+	    netserver);
+    netserver->state = NETSERVER_CONNECTED;
+    /* REVISIT - do we need to make sure that netserver->state_req is
+       suitably set? */
+  }
+  else {
+    g_print("%s received unexpected control_connected signal for server %p id %s\n",
+	    __func__,
+	    netserver,
+	    netserver->id);
+  }
+  
 }
-
 static void netperf_netserver_set_state(NetperfNetserver *netserver, guint req_state) 
 {
 

Modified: branches/gobject_migration/src/netperf-netserver.h
===================================================================
--- branches/gobject_migration/src/netperf-netserver.h	2007-03-15 21:52:04 UTC (rev 216)
+++ branches/gobject_migration/src/netperf-netserver.h	2007-03-15 22:27:08 UTC (rev 217)
@@ -130,6 +130,7 @@
   void (*new_message)(NetperfNetserver *netserver, gpointer message);
   void (*control_closed)(NetperfNetserver *netserver);
   void (*connect_control)(NetperfNetserver *netserver);
+  void (*control_connected)(NetperfNetserver *netserver);
 
   /* methods */
 };



More information about the netperf-dev mailing list