comms stuff (ipc that is)
authorpaulr <me@pjr.cc>
Mon, 19 Sep 2011 18:02:38 +0000 (04:02 +1000)
committerpaulr <me@pjr.cc>
Mon, 19 Sep 2011 18:02:38 +0000 (04:02 +1000)
bin/cbfwrd.php
libcbfwr/comms.php
libcbfwr/config.php
unittests/readconfigfromshm.php [new file with mode: 0644]

index 6f49afe..b5a91b3 100644 (file)
@@ -20,4 +20,18 @@ glcas_pluginLoader();
 error_log("CBFWRD starting");
 
 $config = new Config();
+
+// now we got into daemon modes
+$cont = true;
+
+// setup our sem/shm stuff
+
+// this stuff needs to go in comms
+while($cont) {
+       $comms = new Comms;
+       
+       $comms->putConfig($config->getConfig());
+       
+       $cont = false;
+}
 ?>
\ No newline at end of file
index 808d1f8..b1195c9 100644 (file)
@@ -7,4 +7,46 @@ $STORE_KEY = ftok(realpath(dirname(__FILE__)), "s");
 
 global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
 
+class Comms {
+       function __construct()
+       {
+               global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
+               $this->semres = sem_get($LOCKING_KEY, 0666);
+               $this->msgres = msg_get_queue($MESSAGE_KEY, 0666);
+       }
+       
+       function getConfig()
+       {
+               global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
+               sem_acquire($this->semres);
+               $shm_space = shm_attach($STORE_KEY, 16*1024*1024);
+               $config = shm_get_var($shm_space, 0);
+               sem_release($this->semres);
+               
+               return $config;
+       }
+       
+       function putConfig($config)
+       {
+               global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
+               sem_acquire($this->semres);
+               $shm_space = shm_attach($STORE_KEY, 16*1024*1024);
+               shm_put_var($shm_space, 0, $config);
+               sem_release($this->semres);             
+       }
+       
+       function waitForMessage()
+       {
+               
+       }
+       
+       function sendMessage()
+       {
+               
+       }
+       
+       private $semres, $msgres;
+       
+}
+
 ?>
\ No newline at end of file
index d9a8eb2..94cf1b3 100644 (file)
@@ -78,6 +78,11 @@ class Config {
                }
        }
        
+       function getConfig()
+       {
+               return $this->config;
+       }
+       
        function applyConfig()
        {
                global $AM_DAEMON;
diff --git a/unittests/readconfigfromshm.php b/unittests/readconfigfromshm.php
new file mode 100644 (file)
index 0000000..f05849b
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+$CMD_ROOT_FS = realpath(dirname(__FILE__));
+$AM_DAEMON = false;
+
+global $CMD_ROOT_FS;
+global $AM_DAEMON;
+
+// add libglcas as if it were a path in ../libglcas
+if(file_exists("../libcbfwr")) {
+       $path = realpath($CMD_ROOT_FS."/../");
+       error_log("added cbfwr path as $path");
+       set_include_path(get_include_path().PATH_SEPARATOR.$path);
+}
+
+// include the based library
+require_once("libcbfwr/lib.php");
+
+glcas_pluginLoader();
+
+$comms = new Comms();
+
+$conf = $comms->getConfig();
+
+print_r($conf);
+
+?>
\ No newline at end of file