cluck 1.0.1
The cluster lock service.
cluck_status.cpp
Go to the documentation of this file.
1// Copyright (c) 2016-2025 Made to Order Software Corp. All Rights Reserved
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16
17// self
18//
19#include "cluck/cluck_status.h"
20
21#include "cluck/exception.h"
22#include "cluck/names.h"
23
24
25// communicator
26//
27#include <communicator/names.h>
28
29
30// eventdispatcher
31//
32#include <eventdispatcher/names.h>
33
34
35// last include
36//
37#include <snapdev/poison.h>
38
39
40
77namespace cluck
78{
79
80namespace
81{
82
83
84
103bool g_lock_ready = false;
104
105
116 ed::message & msg
117 , ed::connection_with_send_message::weak_t messenger)
118{
119 snapdev::NOT_USED(msg);
120
121 // messenger still available?
122 //
123 ed::connection_with_send_message::pointer_t m(messenger.lock());
124 if(m == nullptr)
125 {
126 return;
127 }
128
129 ed::message lock_status_msg;
130 lock_status_msg.set_command(g_name_cluck_cmd_lock_status);
131 lock_status_msg.set_service(g_name_cluck_service_name);
132 lock_status_msg.add_parameter(
133 communicator::g_name_communicator_param_cache
134 , communicator::g_name_communicator_value_no);
135 m->send_message(lock_status_msg);
136}
137
138
161 ed::message & msg
162 , typename ed::dispatcher_match::execute_callback_t callback)
163{
164 g_lock_ready = msg.get_command() == g_name_cluck_cmd_lock_ready;
165
166 if(callback != nullptr)
167 {
168 callback(msg);
169 }
170}
171
172
173
174}
175// no name namespace
176
177
178
179
180
181
202 ed::connection_with_send_message::pointer_t messenger
203 , ed::dispatcher::pointer_t dispatcher
204 , typename ed::dispatcher_match::execute_callback_t callback)
205{
206 {
207 ed::dispatcher_match lock_ready(ed::define_match(
208 ed::Expression(g_name_cluck_cmd_lock_ready)
209 , ed::Callback(std::bind(&msg_lock_status, std::placeholders::_1, callback))));
210 dispatcher->add_match(lock_ready);
211 }
212
213 {
214 ed::dispatcher_match no_lock(ed::define_match(
215 ed::Expression(g_name_cluck_cmd_no_lock)
216 , ed::Callback(std::bind(&msg_lock_status, std::placeholders::_1, callback))));
217 dispatcher->add_match(no_lock);
218 }
219
220 {
221 ed::connection_with_send_message::weak_t m(messenger);
222 ed::dispatcher_match ready(ed::define_match(
223 ed::Expression(ed::g_name_ed_cmd_ready)
224 , ed::Callback(std::bind(&msg_ready, std::placeholders::_1, m))
225 , ed::MatchFunc(&ed::one_to_one_callback_match)
226 , ed::Priority(ed::dispatcher_match::DISPATCHER_MATCH_CALLBACK_PRIORITY)));
227 dispatcher->add_match(ready);
228 }
229
230}
231
232
260{
261 return g_lock_ready;
262}
263
264
265
266} // namespace cluck
267// vim: ts=4 sw=4 et
bool g_lock_ready
Record the current status of the cluck daemon.
void msg_ready(ed::message &msg, ed::connection_with_send_message::weak_t messenger)
Also register for the READY message.
void msg_lock_status(ed::message &msg, typename ed::dispatcher_match::execute_callback_t callback)
Setup the lock status.
void listen_to_cluck_status(ed::connection_with_send_message::pointer_t messenger, ed::dispatcher::pointer_t dispatcher, typename ed::dispatcher_match::execute_callback_t callback)
Start listening to changes in the cluck status.
bool is_lock_ready()
Check the current status of the cluck daemon.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.