X-Git-Url: http://git.pjr.cc/?p=CBFWR.git;a=blobdiff_plain;f=libcbfwr%2Fcomms.php;h=b0c4f041c91617881504977d7b45c3856d4f57a0;hp=808d1f84387a0944aeda8c5a41c48b84a49fbd7e;hb=c184472f1c4206a3bcd76ff8e9d27dc2eb1a4c4c;hpb=db4f63e0e2c434ded60cd1fd324be62a2aadcae1 diff --git a/libcbfwr/comms.php b/libcbfwr/comms.php index 808d1f8..b0c4f04 100644 --- a/libcbfwr/comms.php +++ b/libcbfwr/comms.php @@ -1,10 +1,75 @@ semres = sem_get($LOCKING_KEY, 0666); + $this->msgres = msg_get_queue($MESSAGE_KEY, 0666); + } + + function getConfig($type=0) + { + global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY, $CONF_STORE_SIZE; + sem_acquire($this->semres); + $shm_space = shm_attach($STORE_KEY, $CONF_STORE_SIZE); + $config = shm_get_var($shm_space, $type); + sem_release($this->semres); + + return $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, $CONF_STORE_SIZE; + sem_acquire($this->semres); + $shm_space = shm_attach($STORE_KEY, $CONF_STORE_SIZE); + 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($msg) + { + global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY; + $queue = msg_get_queue($MESSAGE_KEY); + msg_send($queue, 1, $msg); + + } + + private $semres, $msgres; + +} ?> \ No newline at end of file