-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathkatpriv.h
1319 lines (983 loc) · 38.8 KB
/
katpriv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef _KATPRIV_H_
#define _KATPRIV_H_
#include <signal.h>
#include <stdarg.h>
#include <sys/time.h>
#include <sys/types.h>
#include <avltree.h>
#ifdef __cplusplus
extern "C" {
#endif
#define KATCP_NAME_LENGTH 64
#define KATCL_IO_SIZE 4096 /* block we want to write out */
#define KATCL_BUFFER_INC 512 /* amount by which we resize read */
#define KATCL_ARGS_INC 8 /* grow the vector by this amount */
#define KATCL_PARSE_FRESH 0 /* newly allocated or cleared */
#define KATCL_PARSE_COMMAND 1 /* parsing first argument */
#define KATCL_PARSE_WHITESPACE 2 /* parsing between arguments */
#define KATCL_PARSE_ARG 3 /* parsing argument */
#define KATCL_PARSE_TAG 4 /* parsing optional tag */
#define KATCL_PARSE_ESCAPE 5 /* parsing escape sequence */
#define KATCL_PARSE_FAKE 6 /* generated manually, not parsed */
#define KATCL_PARSE_DONE 7 /* a complete message */
#define KATCL_ALIGN_NONE 0x0
#define KATCL_ALIGN_BYTE 0x1
#define KATCL_ALIGN_WORD 0x2 /* 32 bits */
/***************************************************************************/
struct katcl_byte_bit;
struct katcl_larg{
unsigned int a_begin;
unsigned int a_end;
unsigned int a_escape;
};
struct katcl_queue
{
struct katcl_parse **q_queue; /* parse array */
unsigned int q_size; /* size of queue */
unsigned int q_head; /* current position */
unsigned int q_count; /* No of entries */
};
struct katcl_parse{
unsigned int p_magic;
unsigned int p_state;
char *p_buffer;
unsigned int p_size;
unsigned int p_have;
unsigned int p_used;
unsigned int p_kept;
struct katcl_larg *p_args;
struct katcl_larg *p_current;
unsigned int p_count;
unsigned int p_got;
int p_refs;
int p_tag;
};
struct katcl_line{
int l_fd;
struct katcl_parse *l_ready;
struct katcl_parse *l_next;
struct katcl_parse *l_stage;
char l_buffer[KATCL_IO_SIZE];
unsigned int l_pending;
unsigned int l_arg; /* argument */
unsigned int l_offset; /* offset into argument */
struct katcl_queue *l_queue;
int l_error;
int l_sendable;
};
/******************************************************************************/
struct katcp_dispatch;
struct katcp_cmd{
char *c_name;
char *c_help;
int (*c_call)(struct katcp_dispatch *d, int argc);
struct katcp_cmd *c_next;
unsigned int c_mode;
unsigned int c_flags;
};
/**********************************************************************/
#define KATCP_SENSOR_INVALID (-1)
#define KATCP_SENSOR_INTEGER 0
#define KATCP_SENSOR_BOOLEAN 1
#define KATCP_SENSOR_DISCRETE 2
#define KATCP_SENSOR_LRU 3
#ifdef KATCP_USE_FLOATS
#define KATCP_SENSOR_FLOAT 4
#define KATCP_SENSORS_COUNT 5
#else
#define KATCP_SENSORS_COUNT 4
#endif
struct katcp_sensor;
struct katcp_nonsense;
struct katcp_acquire;
#ifdef KATCP_USE_FLOATS
struct katcp_double_acquire{
double da_current;
double (*da_get)(struct katcp_dispatch *d, struct katcp_acquire *a);
};
#endif
struct katcp_discrete_acquire{
unsigned int da_current;
int (*da_get)(struct katcp_dispatch *d, struct katcp_acquire *a);
};
struct katcp_integer_acquire{
int ia_current;
int (*ia_get)(struct katcp_dispatch *d, struct katcp_acquire *a);
};
struct katcp_acquire{
struct katcp_sensor **a_sensors;
unsigned int a_count;
int a_type;
int a_users;
int a_periodics; /* tracks if timer callback is running */
struct timeval a_poll; /* rate at which we poll this sensor */
struct timeval a_current; /* current rate */
struct timeval a_limit; /* fastest update rate */
struct timeval a_last; /* last time value was acquired */
#ifdef KATCP_EXPERIMENTAL
struct timeval a_real; /* time which sensor was actually read */
#endif
void *a_local;
void (*a_release)(struct katcp_dispatch *d, struct katcp_acquire *a);
void *a_more; /* could be a union */
};
struct katcp_sensor{
int s_magic;
int s_type;
char *s_name;
char *s_description;
char *s_units;
int s_preferred;
int s_status; /* WARNING, etc */
int s_mode; /* in what mode available */
struct timeval s_recent;
#if 0
int s_running; /* have it do stuff */
#endif
unsigned int s_refs;
struct katcp_nonsense **s_nonsense;
struct katcp_acquire *s_acquire;
int (*s_extract)(struct katcp_dispatch *d, struct katcp_sensor *sn);
int (*s_flush)(struct katcp_dispatch *d, struct katcp_sensor *sn);
void *s_more;
};
#ifdef KATCP_USE_FLOATS
struct katcp_double_sensor{
double ds_current;
int ds_checks;
double ds_nominal_min;
double ds_nominal_max;
double ds_warning_min;
double ds_warning_max;
};
#endif
struct katcp_integer_sensor{
int is_current;
int is_checks;
int is_nominal_min;
int is_nominal_max;
int is_warning_min;
int is_warning_max;
};
struct katcp_discrete_sensor{
int ds_current;
int ds_size;
char **ds_vector;
};
struct katcp_nonsense{
int n_magic;
struct katcp_dispatch *n_client;
struct katcp_sensor *n_sensor;
int n_strategy;
int n_status;
struct timeval n_period;
struct timeval n_next;
int n_manual;
void *n_more;
};
#ifdef KATCP_USE_FLOATS
struct katcp_double_nonsense{
double dn_previous;
double dn_delta;
};
#endif
struct katcp_integer_nonsense{
int in_previous;
int in_delta;
};
struct katcp_discrete_nonsense{
unsigned int dn_previous;
};
#if 0
struct katcp_sensor_integer{
int si_min;
int si_max;
int si_current;
int (*si_get)(struct katcp_sensor *s, void *local);
};
struct katcp_sensor_discrete{
int sd_current;
char **sd_vector;
unsigned int sd_size;
int (*sd_get)(struct katcp_sensor *s, void *local);
};
struct katcp_nonsense_discrete{
int nd_previous;
};
#ifdef KATCP_USE_FLOATS
struct katcp_sensor_float{
double sf_min;
double sf_max;
double sf_current;
double (*sf_get)(struct katcp_sensor *s, void *local);
};
struct katcp_nonsense_float{
double nf_previous;
double nf_delta;
};
#endif
#endif
/**********************************************************************/
struct katcp_entry{
char *e_name;
struct katcp_notice *(*e_prep)(struct katcp_dispatch *d, char *flags, unsigned int from, unsigned int to);
int (*e_enter)(struct katcp_dispatch *d, struct katcp_notice *n, char *flags, unsigned int to);
void (*e_leave)(struct katcp_dispatch *d, unsigned int from);
void *e_state;
void (*e_clear)(struct katcp_dispatch *d, unsigned int mode);
unsigned int e_status;
#if 0
char *e_version;
unsigned int e_minor;
unsigned int e_major;
#endif
};
struct katcp_version{
char *v_label;
char *v_value;
char *v_build;
unsigned int v_mode;
};
#if 0
#define KATCP_PS_UP 1
#define KATCP_PS_TERM 2
struct katcp_process{
void (*p_call)(struct katcp_dispatch *d, int status);
pid_t p_pid;
char *p_name;
int p_type;
int p_state;
};
#endif
struct katcp_notice;
struct katcp_trap{
char *t_name;
struct katcp_notice *t_notice;
};
struct katcp_map{
struct katcp_trap **m_traps;
unsigned int m_size;
};
#ifdef KATCP_SUBPROCESS
struct katcp_job{
unsigned int j_magic;
struct katcp_url *j_url;
pid_t j_pid;
int j_state; /* state machine */
int j_code; /* exit code */
int j_recvr; /* number of requests received */
int j_sendr; /* number of requests sent */
struct katcl_line *j_line;
struct katcp_notice *j_halt;
struct katcp_notice **j_queue;
unsigned int j_size;
unsigned int j_head; /* points at the current head */
unsigned int j_count; /* number of entries present */
struct katcp_map *j_map;
};
#endif
#if 0
#define KATCP_TIME_OTHER 0
#define KATCP_TIME_CURRENT 1
#define KATCP_TIME_REFRESH 2
#define KATCP_TIME_REAP 3
#endif
struct katcp_time{
int t_magic;
struct timeval t_when;
struct timeval t_interval;
int t_armed;
void *t_data;
int (*t_call)(struct katcp_dispatch *d, void *data);
};
struct katcp_invoke{
struct katcp_dispatch *v_client;
void *v_data;
int (*v_call)(struct katcp_dispatch *d, struct katcp_notice *n, void *data);
int v_trigger;
};
struct katcp_notice{
struct katcp_invoke *n_vector;
unsigned int n_count;
#if 0
int n_code;
#endif
char *n_name;
int n_trigger;
int n_tag;
int n_use;
#if 0
/* might get away with only one parse structure */
struct katcl_parse *n_parse;
#endif
struct katcl_queue *n_queue;
struct katcl_parse *n_parse;
#if 0
int n_position;
#endif
int n_changes;
#if 0
void *n_target;
int (*n_release)(struct katcp_dispatch *d, struct katcp_notice *n, void *target);
#endif
};
struct katcp_arb{
char *a_name;
int a_fd;
unsigned int a_type;
unsigned short a_reap;
unsigned short a_mode;
int (*a_run)(struct katcp_dispatch *d, struct katcp_arb *a, unsigned int mode);
void *a_data;
};
#ifdef KATCP_EXPERIMENTAL
/* duplex structures: was supposed to be called duplex, but flat is punnier */
/********************************************************************/
#define KATCP_VRT_GONE ((unsigned short)(-1))
#define KATCP_VRT_STRING 0
#define KATCP_VRT_TREE 1
#define KATCP_VRT_ARRAY 2
#define KATCP_MAX_VRT 3
/* flags need to be contigous, flag_from_string_vrbl_katcp needs that */
#define KATCP_VRF_NONE 0
#define KATCP_VRF_ENV 0x01 /* exported to environment */
#define KATCP_VRF_VER 0x02 /* a version variable */
#define KATCP_VRF_SEN 0x04 /* a variable visible as a sensor */
#define KATCP_VRF_FLX 0x08 /* type can change */
#define KATCP_VRF_HID 0x10 /* hidden */
#define KATCP_VRF_ROM 0x20 /* no overwrite */
#define KATCP_MASK_VRF 0x1f /* mask of all flags */
/* other possible options */
#if 0
#define KATCP_VRF_COW /* copy on write */
#define KATCP_VRF_RO /* readonly */
#endif
#define KATCP_VRC_VERSION_VERSION ":version"
#define KATCP_VRC_VERSION_BUILD ":build"
#define KATCP_VRC_SENSOR_VALUE ":value"
#define KATCP_VRC_SENSOR_STATUS ":status"
#define KATCP_VRC_SENSOR_HELP ":help"
#define KATCP_VRC_SENSOR_UNITS ":units"
#define KATCP_VRC_SENSOR_TYPE ":type"
#define KATCP_VRC_SENSOR_RANGE ":range"
#define KATCP_VRC_SENSOR_TIME ":time"
#if 0 /* unused - causes unexpected namespace collisions */
#define KATCP_VRC_SENSOR_PREFIX ":prefix"
#endif
struct katcp_vrbl_payload;
struct katcp_vrbl_map_item{
char *m_key;
struct katcp_vrbl_payload *m_value;
};
struct katcp_vrbl_array{
struct katcp_vrbl_payload **a_elements;
unsigned int a_size;
};
struct katcp_vrbl_payload{
unsigned short p_type;
union{
char *u_string;
unsigned int u_integer;
struct avl_tree *u_tree;
struct katcp_vrbl_array u_array;
} p_union;
};
struct katcp_vrbl{
char *v_name; /* not always set, never owned */
unsigned short v_status;
unsigned short v_flags;
#if 1
/* unsure where this is going to be used */
int (*v_refresh)(struct katcp_dispatch *d, void *state, char *name, struct katcp_vrbl *vx);
#endif
int (*v_change)(struct katcp_dispatch *d, void *state, char *name, struct katcp_vrbl *vx);
void (*v_release)(struct katcp_dispatch *d, void *state, char *name, struct katcp_vrbl *vx);
struct katcp_vrbl_payload *v_payload;
void *v_extra;
};
struct katcp_region{
struct avl_tree *r_tree;
};
struct katcp_subscribe{
struct katcp_vrbl *s_variable;
struct katcp_endpoint *s_endpoint;
unsigned int s_strategy;
/* for time, last time updated, next time when ... */
};
struct katcp_wit{
unsigned int w_magic;
struct katcp_endpoint *w_endpoint;
struct katcp_subscribe **w_vector;
unsigned int w_size;
/* todo - timeval counter ... runs at rate */
};
struct katcp_listener{
unsigned int l_magic;
unsigned int l_port;
char *l_address;
struct katcp_group *l_group;
};
struct katcp_cmd_item{
/* a single command */
char *i_name;
char *i_help;
int (*i_call)(struct katcp_dispatch *d, int argc);
unsigned int i_flags;
void *i_data;
void (*i_clear)(void *data);
int i_refs;
};
struct katcp_cmd_map{
/* "table" of commands */
char *m_name;
unsigned int m_refs;
struct avl_tree *m_tree;
struct katcp_cmd_item *m_fallback;
};
#define KATCP_SCOPE_INVALID (-1)
/* dpx-misc has a lookuptable based on this order */
#define KATCP_SCOPE_SINGLE 0
#define KATCP_SCOPE_GROUP 1
#define KATCP_SCOPE_GLOBAL 2
#define KATCP_MAX_SCOPE 3
#define KATCP_MAP_UNSET (-1)
#define KATCP_MAP_INNER_REQUEST 0
#define KATCP_MAP_REMOTE_REQUEST 1
#define KATCP_MAP_INNER_INFORM 2
#define KATCP_MAP_REMOTE_INFORM 3
#define KATCP_SIZE_MAP 4
#define KATCP_DIRECTION_INVALID (-1)
#define KATCP_DIRECTION_INNER 0
#define KATCP_DIRECTION_REMOTE 1
/* discard entire pending set after this many queued elements */
#define KATCP_FLUSH_DEFER 8
struct katcp_group{
/* a set of flats which belong together, probably spawned off the same listener, probably same set of commands, probably same "mode" */
char *g_name;
unsigned int g_flags;
struct katcp_cmd_map *g_maps[KATCP_SIZE_MAP];
struct katcp_flat **g_flats;
unsigned int g_count;
int g_log_level;
int g_scope;
int g_use; /* are we ref'ed by the listener */
int g_autoremove; /* do we disappear if use and count are zero ? */
int g_flushdefer; /* number of queued items after we cancel the lot */
struct katcp_region *g_region;
};
#define KATCP_REPLY_HANDLE_REPLIES 0x1
#define KATCP_REPLY_HANDLE_INFORMS 0x2
struct katcp_response_handler{
unsigned int r_flags;
char *r_message;
int (*r_reply)(struct katcp_dispatch *d, int argc);
struct katcp_endpoint *r_issuer;
struct katcp_endpoint *r_recipient;
struct katcl_parse *r_initial;
};
#define KATCP_SIZE_REPLY 2
#define KATCP_DPX_SEND_INVALID 0x00
#define KATCP_DPX_SEND_DESTINATION 0x0f
#define KATCP_DPX_SEND_NULL 0x01 /* throw IO away */
#define KATCP_DPX_SEND_STREAM 0x02 /* goes to f_line */
#define KATCP_DPX_SEND_PEER 0x03 /* goes to top of endpoint */
#define KATCP_DPX_SEND_PERSISTENCE 0xf0
#define KATCP_DPX_SEND_CURRENTLY 0x10 /* set until callback finishes */
#define KATCP_DPX_SEND_LOCKED 0x20 /* user set indefinitely */
#define KATCP_DPX_SEND_RESET 0x100 /* clear lock flag */
#define KATCP_DEFER_OUTSIDE_REQUEST 0x1 /* stop handling outside requests, already have one */
#define KATCP_DEFER_OWN_REQUEST 0x2 /* don't send further requests, other side already busy */
#define KATCP_STALE_SENSOR_NAIVE 0x1 /* haven't issued a sensor-list, can't be out of date */
#define KATCP_STALE_SENSOR_CURRENT 0x2 /* have done sensor-list recently */
#define KATCP_STALE_SENSOR_STALE 0x3 /* things have changed since last sensor-list */
#define KATCP_STALE_MASK_SENSOR 0x3 /* mask out sensor related data */
struct katcp_flat{
/* a client instance, intended to replace what was job and dispatch previously */
unsigned int f_magic;
char *f_name; /* locate the thing by name */
unsigned int f_flags; /* which directions can we do */
int f_state; /* up, shutting down, etc */
int f_exit_code; /* reported exit status */
int f_log_level; /* log level currently set */
int f_scope; /* how much we see */
unsigned int f_stale; /* what is out of date */
unsigned int f_deferring; /* status flags for requests outstanding */
struct katcl_gueue *f_defer; /* deferred requests */
int f_max_defer; /* worst case queue size */
struct katcp_endpoint *f_peer; /* queue for all messages, can be from different senders */
struct katcp_endpoint *f_remote; /* queue for remote messages, used to make remote messages "fit" into peer queue */
struct katcl_line *f_line;
struct katcp_shared *f_shared;
struct katcl_parse *f_orx; /* originating received message (needed for replies) */
struct katcl_parse *f_rx; /* received message */
struct katcl_parse *f_tx; /* message about to send */
struct katcp_cmd_item *f_cmd; /* command currently matched */
#if 0
unsigned int f_send; /* message sending flags */
#endif
struct katcp_response_handler f_replies[KATCP_SIZE_REPLY]; /* this should probably be a dynamic number */
struct katcp_endpoint *f_current_endpoint;
struct katcp_cmd_map *f_maps[KATCP_SIZE_MAP];
int f_current_map;
struct katcp_group *f_group;
/* TODO: */
/* notices, sensors */
/* a sensor could probably be a special type of notice */
struct katcp_region *f_region;
time_t f_start;
};
#endif
#define KATCP_FLAT_STACK 4
struct katcp_shared{
unsigned int s_magic;
struct katcp_entry *s_vector;
unsigned int s_default; /* default log level */
unsigned int s_size;
#if 0
unsigned int s_modal;
#endif
int (*s_prehook)(struct katcp_dispatch *d, int argc);
int (*s_posthook)(struct katcp_dispatch *d, int argc);
struct katcp_cmd *s_commands;
struct katcp_sensor *s_mode_sensor;
unsigned int s_mode;
unsigned int s_flaky; /* mode transition failed, breaking the old one */
unsigned int s_new;
char *s_options;
struct katcp_notice *s_transition;
struct katcp_dispatch *s_template;
struct katcp_dispatch **s_clients;
unsigned int s_count;
unsigned int s_used;
int s_lfd;
struct katcp_job **s_tasks;
unsigned int s_number;
#if 0
struct katcp_process *s_table;
int s_entries;
#endif
struct katcp_time **s_queue;
unsigned int s_length;
struct katcp_arb **s_extras;
unsigned int s_total;
struct katcp_notice **s_notices;
unsigned int s_pending;
unsigned int s_busy; /* more things to do, keep select short */
struct katcp_group **s_groups;
struct katcp_group *s_fallback;
unsigned int s_members;
unsigned int s_lock; /* can't call functions which mess with group pointers */
struct katcp_flat **s_this;
int s_level;
int s_stories;
unsigned int s_changes;
struct katcp_endpoint *s_endpoints;
struct katcp_region *s_region;
#if 0
int s_version_major;
int s_version_minor;
char *s_version_subsystem; /* not ideally named */
#endif
char **s_build_state;
int s_build_items;
struct katcp_sensor **s_sensors;
unsigned int s_tally;
struct katcp_version **s_versions;
unsigned int s_amount;
sigset_t s_signal_mask;
struct sigaction s_child_current, s_child_previous;
struct sigaction s_term_current, s_term_previous;
int s_restore_signals;
fd_set s_read, s_write;
int s_max;
struct katcp_type **s_type;
unsigned int s_type_count;
time_t s_start;
};
struct katcp_dispatch{
int d_level; /* log level */
int d_ready;
int d_run; /* 1 if up, -1 if shutting down, 0 if shut down */
int d_exit; /* exit code, reason for shutting down */
int d_pause; /* waiting for a notice */
struct katcl_line *d_line;
int (*d_current)(struct katcp_dispatch *d, int argc);
struct katcp_shared *d_shared;
struct katcp_nonsense **d_nonsense;
unsigned int d_size;
struct katcp_notice **d_notices;
unsigned int d_count;
struct katcp_notice *d_end;
int d_clone;
char d_name[KATCP_NAME_LENGTH];
};
struct katcp_url {
int u_use;
char *u_str;
char *u_scheme;
char *u_host;
int u_port;
char **u_path;
int u_pcount;
char *u_cmd;
};
struct katcp_type {
char *t_name;
int t_dep;
struct avl_tree *t_tree;
void (*t_print)(struct katcp_dispatch *, char *key, void *);
void (*t_free)(void *);
int (*t_copy)(void *src, void *dest, int);
int (*t_compare)(const void *, const void *);
void *(*t_parse)(struct katcp_dispatch *d, char **);
char *(*t_getkey)(void *data);
};
struct katcp_tobject {
void *o_data;
struct katcp_type *o_type;
int o_man;
};
struct katcp_stack {
struct katcp_tobject **s_objs;
int s_count;
};
#ifdef KATCP_SUBPROCESS
struct katcp_dynamic_mode{
int d_magic;
char *d_cmd;
};
#endif
/**********************************************************************************/
struct katcp_message{
unsigned int m_flags;
struct katcl_parse *m_parse;
struct katcp_endpoint *m_from;
struct katcp_endpoint *m_to;
};
struct katcp_endpoint{
unsigned int e_magic;
unsigned short e_freeable;
unsigned int e_state;
unsigned int e_refcount;
#if 0
char *e_name;
struct katcp_endpoint *e_peer;
#endif
struct katcl_gueue *e_queue;
unsigned int e_precedence;
int (*e_wake)(struct katcp_dispatch *d, struct katcp_endpoint *ep, struct katcp_message *msg, void *data);
void (*e_release)(struct katcp_dispatch *d, void *data);
void *e_data;
struct katcp_endpoint *e_next;
};
#if 0
#define KATCP_ENDPOINT_OWN 0x00
#define KATCP_ENDPOINT_FAIL 0x01
#define KATCP_ENDPOINT_OK 0x02
#define KATCP_ENDPOINT_QUICK 0x03
#define KATCP_ENDPOINT_STALL 0x04
#define KATCP_MASK_ENDPOINT 0x0f
#define KATCP_ENDPOINT_DEAD 0xf0
#endif
/**********************************************************************************/
void exchange_katcl(struct katcl_line *l, int fd);
int dispatch_cmd_katcp(struct katcp_dispatch *d, int argc);
void component_time_katcp(struct timeval *result, unsigned int ms);
int string_to_tv_katcp(struct timeval *tv, char *string);
int sub_time_katcp(struct timeval *delta, struct timeval *alpha, struct timeval *beta);
int add_time_katcp(struct timeval *sigma, struct timeval *alpha, struct timeval *beta);
int cmp_time_katcp(struct timeval *alpha, struct timeval *beta);
int startup_shared_katcp(struct katcp_dispatch *d);
void shutdown_shared_katcp(struct katcp_dispatch *d);
int listen_shared_katcp(struct katcp_dispatch *d, char *host, int port);
int allocate_clients_shared_katcp(struct katcp_dispatch *d, unsigned int count);
int link_shared_katcp(struct katcp_dispatch *d, struct katcp_dispatch *cd);
int load_shared_katcp(struct katcp_dispatch *d);
int run_shared_katcp(struct katcp_dispatch *d);
int ended_shared_katcp(struct katcp_dispatch *d);
void shutdown_cmd_katcp(struct katcp_cmd *c);
int define_cmd_katcp(struct katcp_dispatch *d, int argc);
/* sensor stuff */
int sensor_limit_cmd_katcp(struct katcp_dispatch *d, int argc);
int sensor_value_cmd_katcp(struct katcp_dispatch *d, int argc);
int sensor_list_cmd_katcp(struct katcp_dispatch *d, int argc);
int sensor_sampling_cmd_katcp(struct katcp_dispatch *d, int argc);
int sensor_dump_cmd_katcp(struct katcp_dispatch *d, int argc);
int sensor_cmd_katcp(struct katcp_dispatch *d, int argc);
int match_sensor_status_katcp(struct katcp_dispatch *d, struct katcp_notice *n, void *data);
int match_sensor_list_katcp(struct katcp_dispatch *d, struct katcp_notice *n, void *data);
/* misc */
char *code_to_name_katcm(int code);
char **copy_vector_katcm(char **vector, unsigned int size);
void delete_vector_katcm(char **vector, unsigned int size);
char *default_message_type_katcm(char *string, int type);
int print_time_delta_katcm(char *buffer, unsigned int len, time_t delta);
/* timing support */
int empty_timers_katcp(struct katcp_dispatch *d);
int run_timers_katcp(struct katcp_dispatch *d, struct timespec *interval);
void dump_timers_katcp(struct katcp_dispatch *d);
/* nonsense support */
void forget_nonsense_katcp(struct katcp_dispatch *d, unsigned int index);
/* how many times to try waitpid for child to exit */
#define KATCP_WAITPID_CHECKS 5
/* how long to sleep between checks in nanoseconds */
#define KATCP_WAITPID_POLL 250000000UL
int term_signal_shared_katcp(struct katcp_shared *s);
int child_signal_shared_katcp(struct katcp_shared *s);
int reap_children_shared_katcp(struct katcp_dispatch *d, pid_t pid, int force);
int init_signals_shared_katcp(struct katcp_shared *s);
int undo_signals_shared_katcp(struct katcp_shared *s);
/* notice logic */
void disown_notices_katcp(struct katcp_dispatch *d);
void destroy_notices_katcp(struct katcp_dispatch *d);
int run_notices_katcp(struct katcp_dispatch *d);
int notice_cmd_katcp(struct katcp_dispatch *d, int argc);
int cancel_notice_katcp(struct katcp_dispatch *d, struct katcp_notice *n);
/* jobs */
int load_jobs_katcp(struct katcp_dispatch *d);
int wait_jobs_katcp(struct katcp_dispatch *d);
int run_jobs_katcp(struct katcp_dispatch *d);
int job_cmd_katcp(struct katcp_dispatch *d, int argc);
int register_subprocess_cmd_katcp(struct katcp_dispatch *d, int argc);
int submit_to_job_katcp(struct katcp_dispatch *d, struct katcp_job *j, struct katcl_parse *p, char *name, int (*call)(struct katcp_dispatch *d, struct katcp_notice *n, void *data), void *data);
int notice_to_job_katcp(struct katcp_dispatch *d, struct katcp_job *j, struct katcp_notice *n);
int ended_jobs_katcp(struct katcp_dispatch *d);
/* cmd stuff */
struct katcp_cmd_map *create_cmd_map_katcp(char *name);
void destroy_cmd_map_katcp(struct katcp_cmd_map *m);
void hold_cmd_map_katcp(struct katcp_cmd_map *m);
struct katcp_cmd_map *duplicate_cmd_map_katcp(struct katcp_cmd_map *mo, char *name);
struct katcp_cmd_item *find_cmd_map_katcp(struct katcp_cmd_map *m, char *name);
int remove_cmd_map_katcp(struct katcp_cmd_map *m, char *name);
void set_flag_cmd_item_katcp(struct katcp_cmd_item *ix, unsigned int flags);
int set_help_cmd_item_katcp(struct katcp_cmd_item *ix, char *help);