core and utils

Sergey [2009-02-25 19:51:22]
core and utils
Filename
cxconfig.py
cxcore.py
cxlogger.py
cxutils.py
diff --git a/cxconfig.py b/cxconfig.py
new file mode 100644
index 0000000..e69de29
diff --git a/cxcore.py b/cxcore.py
new file mode 100644
index 0000000..79242bc
--- /dev/null
+++ b/cxcore.py
@@ -0,0 +1,27 @@
+# centrixd core
+# author: Sergey Shakshin
+# jid: rigid_mgn@jabber.ru
+
+
+from cxutils import log
+from cxlogger import CXLogger
+from pydispatch import dispatcher
+from time import sleep
+
+mCycle = True
+def on_shutdown():
+    mCycle = False
+
+dispatcher.connect(on_shutdown,"shutdown")
+
+logger = CXLogger()
+logger.start()
+
+try:
+    while(mCycle):
+        sleep(1)
+
+except KeyboardInterrupt:
+    log("Ctrl-C pressed at console - exiting")
+    print "\nCtrl-C pressed at console - exiting\n"
+    dispatcher.send("shutdown")
diff --git a/cxlogger.py b/cxlogger.py
new file mode 100644
index 0000000..fabe2e6
--- /dev/null
+++ b/cxlogger.py
@@ -0,0 +1,33 @@
+# centrixd logger
+# author: Sergey Shakshin
+# jid: rigid_mgn@jabber.ru
+
+from Queue import Queue, Empty
+from pydispatch import dispatcher
+from threading import Thread
+from syslog import *
+
+class CXLogger(Thread):
+    __pool = Queue()
+    __active = True
+
+    def on_shutdown(self):
+        self.__active = False
+
+    def on_log(self, message):
+        self.__pool.put(message)
+
+    def run(self):
+        dispatcher.connect(self.on_shutdown,"shutdown")
+        dispatcher.connect(self.on_log,"log")
+        openlog("centrixd")
+        while (self.__active):
+            msg='';
+            try:
+                msg=self.__pool.get(block=True, timeout=1)
+                syslog(msg)
+            except Empty:
+                msg=''
+
+        closelog()
+
diff --git a/cxutils.py b/cxutils.py
new file mode 100644
index 0000000..84931da
--- /dev/null
+++ b/cxutils.py
@@ -0,0 +1,5 @@
+from pydispatch import dispatcher
+
+def log(msg):
+    dispatcher.send("log",message=msg)
+
ViewGit