yumapro  24.10-11
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 - 2025, 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
424extern status_t
425 ycontrol_init (int argc,
426 char *argv[],
427 const xmlChar *subsys_id);
428
429
445extern status_t
446 ycontrol_init_ex (int argc,
447 char *argv[],
448 const xmlChar *subsys_id,
449 boolean is_standby);
450
451
469extern status_t
470 ycontrol_init_ex2 (int argc,
471 char *argv[],
472 const xmlChar *subsys_id,
473 boolean is_standby,
474 boolean quiet_mode);
475
476
487extern status_t
488 ycontrol_init2 (void);
489
490
504extern status_t
505 ycontrol_init2_ha (const char *server_id,
506 const char *server_addr,
507 uint16 server_port);
508
509#ifdef PTHREADS
517extern void
519#endif // PTHREADS
520
521
531extern void
532 ycontrol_cleanup (void);
533
534
546extern void
547 ycontrol_cleanup_ex (boolean do_ncx_cleanup);
548
549
560extern status_t
561 ycontrol_check_io (void);
562
563
572extern boolean
573 ycontrol_is_ready (void);
574
575
582extern void
584
585
591extern boolean
593
594
615extern status_t
616 ycontrol_register_service (const xmlChar *service_name,
617 ycontrol_service_start_t service_start,
618 ycontrol_service_stop_t service_stop,
619 ycontrol_service_msg_rcvr_t service_rcvr,
620 ycontrol_service_shutdown_t service_shut);
621
622
645extern status_t
646 ycontrol_register_service2 (const xmlChar *service_name,
647 ycontrol_service_start_t service_start,
648 ycontrol_service_stop_t service_stop,
649 ycontrol_service_msg_rcvr_t service_rcvr,
650 ycontrol_service_shutdown_t service_shut,
651 ycontrol_service_reconnect_t service_reconnect);
652
653
654
655
661extern void
662 ycontrol_unregister_service (const xmlChar *service_name);
663
664
670extern void
672
673
679extern void
681
682
692extern obj_template_t *
693 ycontrol_get_service_object (const xmlChar *service_name);
694
695
713extern status_t
714 ycontrol_send (const xmlChar *service_id,
715 uint32 *msgid,
716 ycontrol_msgtype_t msgtype,
717 val_value_t *service_payload,
718 status_t msg_status);
719
720
736extern status_t
737 ycontrol_send_ex (const xmlChar *service_id,
738 uint32 *msgid,
739 ycontrol_msgtype_t msgtype,
740 val_value_t *service_payload,
741 status_t msg_status,
742 const xmlChar *txid_str);
743
744
761extern status_t
762 ycontrol_send_ex2 (const xmlChar *service_id,
763 uint32 *msgid,
764 ycontrol_msgtype_t msgtype,
765 val_value_t *service_payload,
766 status_t msg_status,
767 boolean with_origin,
768 const xmlChar *txid_str);
769
770
784extern status_t
785 ycontrol_send_error (const xmlChar *service_id,
786 uint32 *msgid,
787 status_t msg_status,
788 uint32 error_index,
789 const xmlChar *error_message,
790 const xmlChar *txid_str);
791
792
802extern status_t
803 ycontrol_send_ok (const xmlChar *service_id,
804 uint32 *msgid,
805 const xmlChar *txid_str);
806
807
817extern boolean
819
820
827extern void
829
830
841extern boolean
842 ycontrol_shutdown_now (void);
843
844
852extern void
854
855
862extern void
863 ycontrol_set_retry_interval (int retry_int);
864
865
871extern const xmlChar *
873
874
875
881extern void
882 ycontrol_set_retry_limit (uint16 retry_limit);
883
884
894extern status_t
895 ycontrol_set_server_root (const char *server_root);
896
897
903extern void
905
906
911#ifdef __cplusplus
912} /* end extern 'C' */
913#endif
914
915#endif /* _H_ycontrol */
status_t
global error return code
Definition: status_enum.h:219
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_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_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
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
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
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:1138
One YANG data-def-stmt.
Definition: obj.h:1232
Session Control Block.
Definition: ses.h:573
Thread control block (TCB)
Definition: thd.h:175
one value to match one type
Definition: val.h:912
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.