yumapro  23.10T-7
YumaPro SDK
Loading...
Searching...
No Matches
ycontrol.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 - 2012, Andy Bierman, All Rights Reserved.
3 * Copyright (c) 2012 - 2021, YumaWorks, Inc., All Rights Reserved.
4 *
5 * Unless required by applicable law or agreed to in writing,
6 * software distributed under the License is distributed on an
7 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 * KIND, either express or implied. See the License for the
9 * specific language governing permissions and limitations
10 * under the License.
11 */
12#ifndef _H_ycontrol
13#define _H_ycontrol
14
15/* FILE: ycontrol.h
16*********************************************************************
17* *
18* P U R P O S E *
19* *
20*********************************************************************/
21
28/*********************************************************************
29* *
30* C H A N G E H I S T O R Y *
31* *
32*********************************************************************
33
34date init comment
35----------------------------------------------------------------------
3615-mar-14 abb Begun
37*/
38
39#include <time.h>
40#include <sys/time.h>
41
42// TBD: remove dependency on xmlstring.h for xmlChar */
43#include <xmlstring.h>
44
45#ifndef _H_ncxtypes
46#include "ncxtypes.h"
47#endif
48
49#ifndef _H_obj
50#include "obj.h"
51#endif
52
53#ifndef _H_ses
54#include "ses.h"
55#endif
56
57#ifndef _H_status_enum
58#include "status_enum.h"
59#endif
60
61#ifndef _H_val
62#include "val.h"
63#endif
64
65#ifndef _H_tstamp
66#include "tstamp.h"
67#endif
68
69#ifndef _H_ycontrol_types
70#include "ycontrol_types.h"
71#endif
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77
78
79
106/********************************************************************
107* *
108* C O N S T A N T S *
109* *
110*********************************************************************/
111
112
114#define YCONTROL_DEF_RETRY_INTERVAL 5000
115
117#define YCONTROL_DEF_MAX_RETRIES 5000
118
120#define SHUTDOWN_STATE(ST) \
121 ((ST) == YCONTROL_ST_SHUTDOWN_REQ || \
122 (ST) == YCONTROL_ST_DISCONNECTING || \
123 (ST) == YCONTROL_ST_SHUTDOWN)
124
128#define YCONTROL_MAX_SERVICES 2
129
131#define YCONTROL_MOD (const xmlChar *)"yumaworks-ycontrol"
132
134#define YCONTROL_OBJ (const xmlChar *)"ycontrol"
135
136
137/********************************************************************
138* *
139* T Y P E S *
140* *
141*********************************************************************/
142
143
152typedef status_t
153 (*ycontrol_service_start_t) (void);
154
155
165typedef status_t
167
168
169
170
188typedef status_t
190 (ses_cb_t *scb,
191 ycontrol_msgtype_t msgtype,
192 uint32 msgid,
193 const xmlChar *server_id,
194 ycontrol_msgbody_t msgbody_type,
195 val_value_t *msgbody,
196 boolean *response_sent);
197
198
209typedef void
211
212
213
214
220typedef void
221 (*ycontrol_timer_handler_t) (void);
222
223
224
232typedef void
234
235
237typedef enum ycontrol_state_t_ {
240
243
246
249
252
255
258
261
264
268
269
271typedef struct ycontrol_service_t_ {
273 xmlChar *service_name;
274
277
280
283
286
289
291
292
294typedef struct ycontrol_profile_t_ {
295
297 xmlChar *subsys_id;
298
300 xmlChar *server_id;
301
306
309
312
315
318
321
324
328 boolean is_standby;
329
332
334 struct timeval retry_timestamp;
335
338
341
344
347
350
353
356
359
362
365
368
373
376
379
381
382
383
387/********************************************************************
388* *
389* F U N C T I O N S *
390* *
391*********************************************************************/
392
393
394
421extern status_t
422 ycontrol_init (int argc,
423 char *argv[],
424 const xmlChar *subsys_id);
425
426
442extern status_t
443 ycontrol_init_ex (int argc,
444 char *argv[],
445 const xmlChar *subsys_id,
446 boolean is_standby);
447
448
466extern status_t
467 ycontrol_init_ex2 (int argc,
468 char *argv[],
469 const xmlChar *subsys_id,
470 boolean is_standby,
471 boolean quiet_mode);
472
473
481extern status_t
482 ycontrol_init2 (void);
483
484
498extern status_t
499 ycontrol_init2_ha (const char *server_id,
500 const char *server_addr,
501 uint16 server_port);
502
503#ifdef PTHREADS
511extern void
513#endif // PTHREADS
514
515
522extern void
523 ycontrol_cleanup (void);
524
525
537extern void
538 ycontrol_cleanup_ex (boolean do_ncx_cleanup);
539
540
548extern status_t
549 ycontrol_check_io (void);
550
551
557extern boolean
558 ycontrol_is_ready (void);
559
560
567extern void
569
570
576extern boolean
578
579
597extern status_t
598 ycontrol_register_service (const xmlChar *service_name,
599 ycontrol_service_start_t service_start,
600 ycontrol_service_stop_t service_stop,
601 ycontrol_service_msg_rcvr_t service_rcvr,
602 ycontrol_service_shutdown_t service_shut);
603
604
627extern status_t
628 ycontrol_register_service2 (const xmlChar *service_name,
629 ycontrol_service_start_t service_start,
630 ycontrol_service_stop_t service_stop,
631 ycontrol_service_msg_rcvr_t service_rcvr,
632 ycontrol_service_shutdown_t service_shut,
633 ycontrol_service_reconnect_t service_reconnect);
634
635
636
637
643extern void
644 ycontrol_unregister_service (const xmlChar *service_name);
645
646
652extern void
654
655
661extern void
663
664
671extern obj_template_t *
672 ycontrol_get_service_object (const xmlChar *service_name);
673
674
689extern status_t
690 ycontrol_send (const xmlChar *service_id,
691 uint32 *msgid,
692 ycontrol_msgtype_t msgtype,
693 val_value_t *service_payload,
694 status_t msg_status);
695
696
712extern status_t
713 ycontrol_send_ex (const xmlChar *service_id,
714 uint32 *msgid,
715 ycontrol_msgtype_t msgtype,
716 val_value_t *service_payload,
717 status_t msg_status,
718 const xmlChar *txid_str);
719
720
737extern status_t
738 ycontrol_send_ex2 (const xmlChar *service_id,
739 uint32 *msgid,
740 ycontrol_msgtype_t msgtype,
741 val_value_t *service_payload,
742 status_t msg_status,
743 boolean with_origin,
744 const xmlChar *txid_str);
745
746
760extern status_t
761 ycontrol_send_error (const xmlChar *service_id,
762 uint32 *msgid,
763 status_t msg_status,
764 uint32 error_index,
765 const xmlChar *error_message,
766 const xmlChar *txid_str);
767
768
778extern status_t
779 ycontrol_send_ok (const xmlChar *service_id,
780 uint32 *msgid,
781 const xmlChar *txid_str);
782
783
793extern boolean
795
796
803extern void
805
806
814extern boolean
816
817
825extern void
827
828
835extern void
836 ycontrol_set_retry_interval (int retry_int);
837
838
844extern const xmlChar *
846
847
848
854extern void
855 ycontrol_set_retry_limit (uint16 retry_limit);
856
857
867extern status_t
868 ycontrol_set_server_root (const char *server_root);
869
870
876extern void
878
879
884#ifdef __cplusplus
885} /* end extern 'C' */
886#endif
887
888#endif /* _H_ycontrol */
status_t
global error return code
Definition: status_enum.h:210
boolean ycontrol_shutdown_now(void)
Check if the YControl subsystem has shut down because a <shutdown-event> was received from the server...
Definition: ycontrol.c:1467
void ycontrol_cleanup_ex(boolean do_ncx_cleanup)
Cleanup ycontrol layer (extended)
Definition: ycontrol.c:790
void ycontrol_service_stop(void)
Stop the registered services.
Definition: ycontrol.c:1114
status_t ycontrol_send(const xmlChar *service_id, uint32 *msgid, ycontrol_msgtype_t msgtype, val_value_t *service_payload, status_t msg_status)
Send a YControl message.
Definition: ycontrol.c:1178
status_t ycontrol_send_error(const xmlChar *service_id, uint32 *msgid, status_t msg_status, uint32 error_index, const xmlChar *error_message, const xmlChar *txid_str)
Send a YControl <error> message.
Definition: ycontrol.c:1300
void ycontrol_unregister_service(const xmlChar *service_name)
Unregister a specific service.
Definition: ycontrol.c:1059
void ycontrol_request_shutdown(void)
Request a control message handler shutdown.
Definition: ycontrol.c:944
void ycontrol_init2_ha_thd(thd_tcb_t *tcb)
Setup scb->tcb for ycontrol session.
Definition: ycontrol.c:758
status_t ycontrol_init(int argc, char *argv[], const xmlChar *subsys_id)
Initialize the YControl library.
Definition: ycontrol.c:492
status_t ycontrol_register_service2(const xmlChar *service_name, ycontrol_service_start_t service_start, ycontrol_service_stop_t service_stop, ycontrol_service_msg_rcvr_t service_rcvr, ycontrol_service_shutdown_t service_shut, ycontrol_service_reconnect_t service_reconnect)
Register a specific service with the YumaPro control message manager Add a reconnect callback.
Definition: ycontrol.c:1011
void ycontrol_set_retry_interval(int retry_int)
Set the re-connect retry interval.
Definition: ycontrol.c:1500
status_t ycontrol_send_ex(const xmlChar *service_id, uint32 *msgid, ycontrol_msgtype_t msgtype, val_value_t *service_payload, status_t msg_status, const xmlChar *txid_str)
Send a YControl message (extended)
Definition: ycontrol.c:1215
void ycontrol_setup_reconnect(void)
Setup the YControl profile to reconnect after the retry interval with the incoming message from the s...
Definition: ycontrol.c:1442
status_t ycontrol_init2(void)
Phase 2 initialization.
Definition: ycontrol.c:659
const xmlChar * ycontrol_get_subsys_id(void)
Get the subsystem ID string.
Definition: ycontrol.c:1518
status_t ycontrol_init2_ha(const char *server_id, const char *server_addr, uint16 server_port)
Phase 2 initialization for HA.
Definition: ycontrol.c:680
void ycontrol_service_reconnect(void)
Start the main server reconnect for the registered services.
Definition: ycontrol.c:1589
status_t ycontrol_send_ex2(const xmlChar *service_id, uint32 *msgid, ycontrol_msgtype_t msgtype, val_value_t *service_payload, status_t msg_status, boolean with_origin, const xmlChar *txid_str)
Send a YControl message (extended2)
Definition: ycontrol.c:1259
void ycontrol_service_start(void)
Start the registered services.
Definition: ycontrol.c:1083
status_t ycontrol_send_ok(const xmlChar *service_id, uint32 *msgid, const xmlChar *txid_str)
Send a YControl <ok> message.
Definition: ycontrol.c:1335
boolean ycontrol_shutdown_requested(void)
Check if a control message handler shutdown is in progress.
Definition: ycontrol.c:963
status_t ycontrol_check_io(void)
Check for input/output.
Definition: ycontrol.c:847
boolean ycontrol_is_ready(void)
Check if the ycontrol ready is up and ready to be used.
Definition: ycontrol.c:912
obj_template_t * ycontrol_get_service_object(const xmlChar *service_name)
Get the service object from the payload container.
Definition: ycontrol.c:1150
void ycontrol_set_retry_limit(uint16 retry_limit)
Set the re-connect retry limit.
Definition: ycontrol.c:1533
void ycontrol_set_timer_handler(ycontrol_timer_handler_t timer_handler)
Set the timer callback handler.
Definition: ycontrol.c:1483
void ycontrol_cleanup(void)
Cleanup ycontrol layer.
Definition: ycontrol.c:777
status_t ycontrol_register_service(const xmlChar *service_name, ycontrol_service_start_t service_start, ycontrol_service_stop_t service_stop, ycontrol_service_msg_rcvr_t service_rcvr, ycontrol_service_shutdown_t service_shut)
Register a specific service with the YumaPro control message manager.
Definition: ycontrol.c:981
status_t ycontrol_init_ex2(int argc, char *argv[], const xmlChar *subsys_id, boolean is_standby, boolean quiet_mode)
Setup global vars before accepting any requests; extended 2.
Definition: ycontrol.c:552
boolean ycontrol_dispatch_msg(ses_cb_t *scb)
Find the appropriate service handler and call it with the incoming message from the server.
Definition: ycontrol.c:1368
status_t ycontrol_set_server_root(const char *server_root)
Set the server-root when running in Multi-Instance Mode.
Definition: ycontrol.c:1554
status_t ycontrol_init_ex(int argc, char *argv[], const xmlChar *subsys_id, boolean is_standby)
Initialize the YControl library.
Definition: ycontrol.c:520
status_t(* ycontrol_service_start_t)(void)
YControl Service Layer Start Callback Function.
Definition: ycontrol.h:153
ycontrol_msgbody_t
YControl message body types.
Definition: ycontrol_types.h:85
void(* ycontrol_timer_handler_t)(void)
YControl Service Layer Timer Handler Function.
Definition: ycontrol.h:221
void(* ycontrol_service_reconnect_t)(void)
YControl Service Layer Reconnect Callback Function.
Definition: ycontrol.h:233
ycontrol_msgtype_t
ycontrol message type
Definition: ycontrol_types.h:60
ycontrol_state_t
ycontrol manager connection state enumerations
Definition: ycontrol.h:237
void(* ycontrol_service_shutdown_t)(void)
YControl Service Layer Shutdown Callback Function.
Definition: ycontrol.h:210
#define YCONTROL_MAX_SERVICES
this constant needs to be updated as more service types are implemented; currently only sil-sa,...
Definition: ycontrol.h:128
status_t(* ycontrol_service_stop_t)(ses_cb_t *scb)
YControl Service Layer Stop Callback Function.
Definition: ycontrol.h:166
status_t(* ycontrol_service_msg_rcvr_t)(ses_cb_t *scb, ycontrol_msgtype_t msgtype, uint32 msgid, const xmlChar *server_id, ycontrol_msgbody_t msgbody_type, val_value_t *msgbody, boolean *response_sent)
YControl Service Layer Message Receiver Callback Function.
Definition: ycontrol.h:190
@ YCONTROL_ST_NONE
not set
Definition: ycontrol.h:239
@ YCONTROL_ST_CONNECTING
connecting to the server
Definition: ycontrol.h:248
@ YCONTROL_ST_CONNECT
need a socket connection to server
Definition: ycontrol.h:245
@ YCONTROL_ST_SHUTDOWN
in the process of shutting down
Definition: ycontrol.h:263
@ YCONTROL_ST_SHUTDOWN_DONE
shutdown complete
Definition: ycontrol.h:266
@ YCONTROL_ST_WAIT_CONNECT_RETRY
connect failed and waiting for a retry
Definition: ycontrol.h:251
@ YCONTROL_ST_CONNECTED
active state, ready to receive requests and start service layers
Definition: ycontrol.h:254
@ YCONTROL_ST_DISCONNECTING
disconnecting from the server
Definition: ycontrol.h:260
@ YCONTROL_ST_SHUTDOWN_REQ
got an application shutdown request
Definition: ycontrol.h:257
@ YCONTROL_ST_INIT
YControl initializing.
Definition: ycontrol.h:242
YANG module data structures Many internal representations of YANG module constructs.
Data Object Support.
NETCONF Session Common definitions module.
global error status code enumerations
representation of one module or submodule during and after parsing
Definition: ncxtypes.h:1134
One YANG data-def-stmt.
Definition: obj.h:1209
Session Control Block.
Definition: ses.h:573
Thread control block (TCB)
Definition: thd.h:175
one value to match one type
Definition: val.h:911
control block for 1 ycontrol manager (only 1 used)
Definition: ycontrol.h:294
obj_template_t * ycontrol_obj
YControl message YANG object.
Definition: ycontrol.h:352
val_value_t * ycontrol_txid
cached transaction ID
Definition: ycontrol.h:358
int connect_retries
connect retries done
Definition: ycontrol.h:314
fd_set active_fd_set
socket active FD set
Definition: ycontrol.h:340
fd_set read_fd_set
socket read FD set
Definition: ycontrol.h:343
int connect_retry_interval
number of milliseconds to wait before connect retry
Definition: ycontrol.h:320
val_value_t * ycontrol_payload
cached payload to reload and save time
Definition: ycontrol.h:361
xmlChar * server_id
malloced server ID that this subsystem connected to
Definition: ycontrol.h:300
fd_set write_fd_set
socket write FD set
Definition: ycontrol.h:346
boolean shutdown_requested
flag shutdown requested by the application
Definition: ycontrol.h:323
boolean is_standby
internal flag to identify special subsystem that is a server connecting to another server
Definition: ycontrol.h:328
char * server_root
malloced server root ID used in server Multi-Instance Mode set from the –server-root CLI parameter
Definition: ycontrol.h:305
status_t ycontrol_res
last operation result
Definition: ycontrol.h:311
int connect_max_retries
connect retries allowed
Definition: ycontrol.h:317
ses_cb_t * ycontrol_scb
session control block for connection to server
Definition: ycontrol.h:337
val_value_t * ycontrol_msg
cached message subtree to save time
Definition: ycontrol.h:355
ncx_module_t * ycontrol_mod
parsed and saved YANG module for YControl messages
Definition: ycontrol.h:349
time_t boot_timestamp
timestamp of the connection attempt
Definition: ycontrol.h:331
val_value_t * ycontrol_ok
cached OK message ready to reload and send
Definition: ycontrol.h:364
val_value_t * ycontrol_error
cached error message ready to reload and send
Definition: ycontrol.h:367
ycontrol_timer_handler_t timer_handler
timer callback for periodic checks like reconnect
Definition: ycontrol.h:375
ycontrol_state_t ycontrol_state
current YControl protocol state
Definition: ycontrol.h:308
xmlChar * subsys_id
malloced subsystem ID to use
Definition: ycontrol.h:297
uint32 next_msgid
next message ID, incremented when subsystem initiates the message
Definition: ycontrol.h:372
callback functions for a service that registers with ycontrol
Definition: ycontrol.h:271
ycontrol_service_start_t service_start
service start callback
Definition: ycontrol.h:276
ycontrol_service_stop_t service_stop
service stop callback
Definition: ycontrol.h:279
ycontrol_service_shutdown_t service_shutdown
service shutdown callback
Definition: ycontrol.h:285
xmlChar * service_name
service name (list key)
Definition: ycontrol.h:273
ycontrol_service_reconnect_t service_reconnect
service reconnect callback
Definition: ycontrol.h:288
ycontrol_service_msg_rcvr_t service_msg_rcvr
service message receiver callback
Definition: ycontrol.h:282
Timestamp utilities.
Value Node Basic Support.
Some YControl data types.