comms stuff (ipc that is)
[CBFWR.git] / libcbfwr / comms.php
index 0098db1..b1195c9 100644 (file)
@@ -1,10 +1,52 @@
 <?php
 // C = msg key
 // L = locking key
-$message_key = ftok(realpath(dirname(__FILE__)), "c");
-$locking_key = ftok(realpath(dirname(__FILE__)), "l");
-$store_key = ftok(realpath(dirname(__FILE__)), "s");
+$MESSAGE_KEY = ftok(realpath(dirname(__FILE__)), "c");
+$LOCKING_KEY = ftok(realpath(dirname(__FILE__)), "l");
+$STORE_KEY = ftok(realpath(dirname(__FILE__)), "s");
 
-echo "comms key: $message_key, $locking_key, $store_key\n";
+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