Index: fact/tools/PyDimCtrl/fpydim.py
===================================================================
--- fact/tools/PyDimCtrl/fpydim.py	(revision 13789)
+++ fact/tools/PyDimCtrl/fpydim.py	(revision 13793)
@@ -19,9 +19,12 @@
 
 class FactDimServer( object ):
-
     def __init__(self, name):
         """ sets name of instance to name of server, all uppercase
         """
         self.name = name.upper()
+        self.print_state = False
+        self.print_msg = False
+        self.reg_state_cb()
+        self.reg_msg_cb()
 
     def _cmd(self, cmdstr, *args):
@@ -80,5 +83,48 @@
         return True
 
-
+    def state_callback(self, state):
+        self.sts = state
+        try:
+            self.stn = int(state[state.find('[')+1 : state.find(']')]) 
+        except ValueError:
+            self.stn = None
+        if self.print_state: 
+            print state
+
+    def msg_callback(self, msg):
+        if self.print_msg:
+            print msg
+
+    def reg_state_cb(self):
+        if not hasattr(self, 'state'):
+            raise TypeError(self.name+' has no CMD called STATE')
+        service_name = self.name.upper()+'/STATE'
+        self.state_sid = pydim.dic_info_service(service_name, "C", self.state_callback)
+        if not self.state_sid:
+            del self.state_sid
+            raise IOError('could not register STATE client')
+
+    def reg_msg_cb(self):
+        if not hasattr(self, 'state'):
+            raise TypeError(self.name+' has no CMD called STATE')
+        service_name = self.name.upper()+'/MESSAGE'
+        self.msg_sid = pydim.dic_info_service(service_name, "C", self.msg_callback)
+        if not self.msg_sid:
+            del self.msg_sid
+            raise IOError('could not register MESSAGE client')
+
+    def unreg_state_cb(self):
+        if hasattr(self, 'state_sid'):
+            pydim.dic_release_service(self.state_sid)
+            del self.state_sid
+
+    def unreg_msg_cb(self):
+        if hasattr(self, 'msg_sid'):
+            pydim.dic_release_service(self.msg_sid)
+            del self.msg_sid
+
+    def __del__(self):
+        self.unreg_state_cb()
+        self.unreg_msg_cb()
 
 # utility functions for dynamic addid of methods to classes
@@ -168,5 +214,5 @@
 # the values are not needed, so it might be any iteratable python listlike type 
 # to be precise
-def ParseServersServiceList( servers )
+def ParseServersServiceList( servers ):
     
     services = {}
@@ -225,9 +271,9 @@
                 services[server][service[0]] = (
                         service[1], service[2], dd[service[0]])
-    return services
+    return services, dd
 
 
 servers = ParseDnsServerList()
-services = ParseServersServiceList( servers )
+services, dd = ParseServersServiceList( servers )
 
 # create one class for each Fact Dim Server
@@ -236,4 +282,11 @@
     FactDimServerClasses.append( 
             types.ClassType( server_name, (FactDimServer,), {}) )
+    for cmd in services[server_name]:
+        if 'CMD' in services[server_name][cmd][1]:
+            cmdname = cmd.split('/')[1]
+            add_command(FactDimServerClasses[-1], cmd)
+        elif not services[server_name][cmd][1]:
+            cmdname = cmd.split('/')[1]
+            add_getter(FactDimServerClasses[-1], cmd)
 
 # create an instace of each of the classes
@@ -241,27 +294,12 @@
 # all the ServerClass instances are collected in a list
 # so one can get a quick overview --> print dims
-all_dims = []
+dims = []
 for i,server_name in enumerate(servers):
+    if server_name == 'DIS_DNS':
+        continue
     new_instance = FactDimServerClasses[i](server_name)
-    all_dims.append( new_instance )
+    dims.append( new_instance )
+    globals()[server_name.lower()] = new_instance
 del new_instance
-
-dims = []
-#print "connecting to Dim Servers... "
-for dim in all_dims:
-#    print dim.name.lower()
-    if dim.name == 'DIS_DNS':
-        continue
-    globals()[dim.name.lower()] = dim
-    dims.append(dim)
-
-for i,dim in enumerate(all_dims):
-    for cmd in services[dim.name]:
-        if 'CMD' in services[dim.name][cmd][1]:
-            cmdname = cmd.split('/')[1]
-            add_command(FactDimServerClasses[i], cmd)
-        elif not services[dim.name][cmd][1]:
-            cmdname = cmd.split('/')[1]
-            add_getter(FactDimServerClasses[i], cmd)
 
 ##############################################################################
