Compare commits

..

No commits in common. "ad1f798ae6019bed3ff369d25dca90e7af1c88ea" and "ea744d31e28c03283ff6a6f2391a168b5fddbaf4" have entirely different histories.

4 changed files with 25 additions and 25 deletions

View file

@ -1 +1 @@
v3.5.4
v3.5.2

View file

@ -23,6 +23,7 @@ class Phone extends AbstractDaemon
private $read_delay = 20 / 0.5;
private $read_tick = 0;
private $msg_queue;
private $msg_queue_id;
private $webhook_queue;
private $last_message_at;
private $phone;
@ -37,6 +38,7 @@ class Phone extends AbstractDaemon
public function __construct(array $phone)
{
$this->phone = $phone;
$this->msg_queue_id = (int) (QUEUE_ID_PHONE_PREFIX . $this->phone['id']);
$name = 'RaspiSMS Daemon Phone ' . $this->phone['id'];
$logger = new Logger($name);
@ -85,7 +87,7 @@ class Phone extends AbstractDaemon
//Set last message at to construct time
$this->last_message_at = microtime(true);
$this->msg_queue = msg_get_queue(QUEUE_ID_PHONE);
$this->msg_queue = msg_get_queue($this->msg_queue_id);
//Instanciate adapter
$adapter_class = $this->phone['adapter'];
@ -96,7 +98,11 @@ class Phone extends AbstractDaemon
public function on_stop()
{
$this->logger->info('Stopping Phone daemon with pid ' . getmypid());
//Delete queue on daemon close
$this->logger->info('Closing queue : ' . $this->msg_queue_id);
msg_remove_queue($this->msg_queue);
$this->logger->info('Stopping Phone daemon with pid ' . getmypid());
}
public function handle_other_signals($signal)
@ -119,10 +125,8 @@ class Phone extends AbstractDaemon
$maxsize = 409600;
$message = null;
// Message type is forged from a prefix concat with the phone ID
$message_type = (int) QUEUE_TYPE_SEND_MSG_PREFIX . $this->phone['id'];
$error_code = null;
$success = msg_receive($this->msg_queue, $message_type, $msgtype, $maxsize, $message, true, MSG_IPC_NOWAIT, $error_code); //MSG_IPC_NOWAIT == dont wait if no message found
$success = msg_receive($this->msg_queue, QUEUE_TYPE_SEND_MSG, $msgtype, $maxsize, $message, true, MSG_IPC_NOWAIT, $error_code); //MSG_IPC_NOWAIT == dont wait if no message found
if (!$success && MSG_ENOMSG !== $error_code)
{

View file

@ -23,7 +23,7 @@ class Sender extends AbstractDaemon
private $internal_scheduled;
private $internal_received;
private $bdd;
private $msg_queue;
private $queues = [];
public function __construct()
{
@ -62,14 +62,15 @@ class Sender extends AbstractDaemon
{
foreach ($smss_per_scheduled as $id_scheduled => $smss)
{
//If queue not already exists
if (!msg_queue_exists(QUEUE_ID_PHONE) || !isset($this->queue))
{
$this->msg_queue = msg_get_queue(QUEUE_ID_PHONE);
}
foreach ($smss as $sms)
{
//If queue not already exists
$queue_id = (int) (QUEUE_ID_PHONE_PREFIX . $sms['id_phone']);
if (!msg_queue_exists($queue_id) || !isset($queues[$queue_id]))
{
$this->queues[$queue_id] = msg_get_queue($queue_id);
}
$msg = [
'id_user' => $sms['id_user'],
'id_scheduled' => $sms['id_scheduled'],
@ -81,10 +82,8 @@ class Sender extends AbstractDaemon
'medias' => $sms['medias'] ?? [],
];
// Message type is forged from a prefix concat with the phone ID
$message_type = (int) QUEUE_TYPE_SEND_MSG_PREFIX . $sms['id_phone'];
msg_send($this->msg_queue, $message_type, $msg);
$this->logger->info('Transmit sms send signal to phone ' . $sms['id_phone'] . ' on queue ' . QUEUE_ID_PHONE . ' with message type ' . $message_type . '.');
msg_send($this->queues[$queue_id], QUEUE_TYPE_SEND_MSG, $msg);
$this->logger->info('Transmit sms send signal to phone ' . $sms['id_phone'] . ' on queue ' . $queue_id . '.');
}
$this->logger->info('Scheduled ' . $id_scheduled . ' treated and deleted.');
@ -100,10 +99,6 @@ class Sender extends AbstractDaemon
public function on_stop()
{
//Delete queue on daemon close
$this->logger->info('Closing queue : ' . $this->msg_queue);
msg_remove_queue($this->msg_queue);
$this->logger->info('Stopping Sender with pid ' . getmypid());
}

View file

@ -53,16 +53,17 @@
],
//Phone messages types
'QUEUE_ID_PHONE' => ftok(__FILE__, 'p'),
'QUEUE_TYPE_SEND_MSG_PREFIX' => 100,
'QUEUE_ID_PHONE_PREFIX' => ftok(__FILE__, 'p'),
'QUEUE_TYPE_SEND_MSG' => 1,
'QUEUE_TYPE_RECEIVE_MSG' => 2,
//Queues ids
'QUEUE_ID_WEBHOOK' => ftok(__FILE__, 'w'),
'QUEUE_TYPE_WEBHOOK' => 100,
'QUEUE_TYPE_WEBHOOK' => 3,
//Queue email
'QUEUE_ID_EMAIL' => ftok(__FILE__, 'e'),
'QUEUE_TYPE_EMAIL' => 100,
'QUEUE_TYPE_EMAIL' => 3,
//User default settings
'USER_DEFAULT_SETTINGS' => [