running configuration and deltas and shit
[CBFWR.git] / libcbfwr / comms.php
index b1195c9..a11f9b3 100644 (file)
@@ -15,33 +15,55 @@ class Comms {
                $this->msgres = msg_get_queue($MESSAGE_KEY, 0666);
        }
        
-       function getConfig()
+       function getConfig($type=0)
        {
                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);
+               $config = shm_get_var($shm_space, $type);
                sem_release($this->semres);
                
                return $config;
        }
        
-       function putConfig($config)
+       function lockConfigs()
+       {
+               sem_acquire($this->semres);
+       }
+       
+       function unlockConfigs()
+       {
+               sem_release($this->semres);
+       }
+       
+       
+       // type = 0 for the fs config
+       // type = 1 for the boot hardware config
+       // type = 2 for running config
+       // type = 3 for web config
+       function putConfig($config, $type=0)
        {
                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);
+               shm_put_var($shm_space, $type, $config);
                sem_release($this->semres);             
        }
        
        function waitForMessage()
        {
+               global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
+               $queue = msg_get_queue($MESSAGE_KEY);
+               msg_receive($queue, 0, $msgtype, 1024, $msg);
                
+               return $msg;
        }
        
-       function sendMessage()
+       function sendMessage($msg)
        {
+               global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
+               $queue = msg_get_queue($MESSAGE_KEY);
+               msg_send($queue, 1, $msg);
                
        }