comms stuff (ipc that is)
[CBFWR.git] / libcbfwr / comms.php
1 <?php
2 // C = msg key
3 // L = locking key
4 $MESSAGE_KEY = ftok(realpath(dirname(__FILE__)), "c");
5 $LOCKING_KEY = ftok(realpath(dirname(__FILE__)), "l");
6 $STORE_KEY = ftok(realpath(dirname(__FILE__)), "s");
7
8 global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
9
10 class Comms {
11         function __construct()
12         {
13                 global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
14                 $this->semres = sem_get($LOCKING_KEY, 0666);
15                 $this->msgres = msg_get_queue($MESSAGE_KEY, 0666);
16         }
17         
18         function getConfig()
19         {
20                 global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
21                 sem_acquire($this->semres);
22                 $shm_space = shm_attach($STORE_KEY, 16*1024*1024);
23                 $config = shm_get_var($shm_space, 0);
24                 sem_release($this->semres);
25                 
26                 return $config;
27         }
28         
29         function putConfig($config)
30         {
31                 global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
32                 sem_acquire($this->semres);
33                 $shm_space = shm_attach($STORE_KEY, 16*1024*1024);
34                 shm_put_var($shm_space, 0, $config);
35                 sem_release($this->semres);             
36         }
37         
38         function waitForMessage()
39         {
40                 
41         }
42         
43         function sendMessage()
44         {
45                 
46         }
47         
48         private $semres, $msgres;
49         
50 }
51
52 ?>