summaryrefslogtreecommitdiffstats
path: root/task_manager/server/include/system_service/tskm_svc.h
blob: 8b255818931ebb6c08b2b19abb15f8c5b0881444 (plain)
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
/*
 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * @file tskm_svc.h
 * @brief \~english define of tskm
 */
/** @addtogroup BaseSystem
 *  @{
 */
/** @addtogroup system_service
 *  @ingroup BaseSystem
 *  @{
 */
/** @addtogroup task_manager
 *  @ingroup system_service
 *  @{
 */
#ifndef TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_SVC_H_
#define TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_SVC_H_


#include <unistd.h>
#include <sys/types.h>
#include "system_service/tskm_local_type.h"


#define TSKM_SVC_WAIT_REQ_MAX  (8)      // Number of queued requests

// Service type
typedef enum {
  TSKM_SVC_TYPE_NATIVE,   //
  TSKM_SVC_TYPE_UNKNONW,  //
} TSKM_SVC_TYPE_t;

// Scheduling policy
typedef enum {
  TSKM_SVC_POLICY_TSS,   //
  TSKM_SVC_POLICY_RR,    //
  TSKM_SVC_POLICY_FIFO,  //
} TSKM_SVC_POLICY_t;

// Life cycle
typedef enum {
  TSKM_SVC_LC_ALWAYS,               // Resident
  TSKM_SVC_LC_ALWAYS_RECOVERABLE,   // Resident(Recoverable)
  TSKM_SVC_LC_DYNAMIC               // Non-resident
} TSKM_SVC_LC_t;

// CPU allocation: This defined value should match the specification of the second argument of CL_ProcessCreateAttrSetCpuAssign

typedef enum {
  TSKM_SVC_ASSIGN_CPU_AUTO = 0,  // Automatic allocation
  TSKM_SVC_ASSIGN_CPU_0 = 1,     // Fixed to CPU0
  TSKM_SVC_ASSIGN_CPU_1 = 2,     // Fixed to CPU1
} TSKM_SVC_ASSIGN_CPU_t;

// Service attributes (given by XML)
typedef struct {
  TSKM_SVCID_t svcId;        //
  const char* name;         //
  const char* path;         //
  char** args;         //
  TSKM_SVC_TYPE_t type;         //
  uint32_t prio;         //
  TSKM_SVC_POLICY_t policy;       //
  TSKM_SVC_LC_t lifeCycle;    //
  uint32_t retryCnt;     //
  TSKM_SVC_ASSIGN_CPU_t cpuAssign;    //
  const char* user;         //
  uint32_t runtimeLimit;  //
  uint32_t cpuLimit;     //
  uint32_t memLimit;     //
  TSKM_BOOL_t shotdownWait;  //
  uint32_t subgidNum;    //
  gid_t *subgidList;  //
} TSKM_SVC_ATTR_t;

// Service status
typedef enum {
  TSKM_SVC_DORMANT,      // During dormant (Not exec)
  TSKM_SVC_WAITCONNECT,  // Wait for connection
  TSKM_SVC_WAKEUP,       // Start in progress
  TSKM_SVC_RUNNING,      // Running (Startup completed)
  TSKM_SVC_DOWN,         // Termination in progress
  TSKM_SVC_FINDOWN,      // Termination completed
  TSKM_SVC_DISABLE,      // Prohibitting startup  (exec prohibited)
} TSKM_SVC_STATE_t;

// Service
typedef struct {                                                       // Life cycle
  TSKM_SVC_ATTR_t *attr;      // Service Attributes            ALL
  TSKM_SVC_STATE_t state;     // Service State                 ALL
  int iFd;                    // inotifyFd for touch           ALL
  pid_t pid;                  // PID of service                REQ_WAKEUP - FIN_DOWN
  int connFd;                 // service communication socket  DO_WAKEUP  - FIN_DOWN
  T_SS_SM_START_DataStructType bootInfo;        // Boot info                     REQ_WAKEUP - FIN_DOWN
  T_SS_SM_START_ExtDataStructType extBootInfo;  // Extended boot info            REQ_WAKEUP - FIN_DOWN

  TSKM_BOOL_t isShmDone;      // Shared memory initialization completed
  TSKM_BOOL_t isStepDone;     // Gradual startup completed
  TSKM_BOOL_t isAvailable;    // Availability reception completed

  uint32_t watchCnt;          // Service monitoring counter
  uint32_t waitResCnt;        // Wait for response to request       DO_WAKEUP  - WAIT_WAKEUP
  uint32_t waitReqCnt;        // Wait for request issuance          REQ_WAKEUP - DO_WAKEUP
  TSKM_GSTEP_REQ_INFO_t request[TSKM_SVC_WAIT_REQ_MAX];  //         REQ_WAKEUP - DO_WAKEUP

  uint32_t errTermCnt;        // Number of abnormal terminations    ALL
} TSKM_SVC_CTX_t;

// Service list
typedef struct {
  uint32_t svcNum;
  TSKM_SVC_CTX_t *svcList;
} TSKM_SVCS_CTX_t;

// State of waiting for service termination
typedef enum {
  TSKM_SVC_WAIT_NONE,       // No wait
  TSKM_SVC_WAIT_TRANSIENT,  // Waiting for termination of nonresident service
  TSKM_SVC_WAIT_BOTH,       // Waiting for termination of resident/nonresident service
} TSKM_SVC_WAIT_STATE_t;

// Service list
  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcsEventHandle
  /// \~english @par Summary
  ///
  /// \~english @param
  /// \~english @param  [in] p_svcs
  ///            p_svcs   - pointer of services
  /// \~english @par
  ///           p_svcs   TSKM_SVCS_CTX_t*
  /// \~english @code
  ///           typedef struct {
  ///             uint32_t svcNum;           // service num
  ///             TSKM_SVC_CTX_t *svcList;   // services list pointer
  ///           } TSKM_SVCS_CTX_t;
  ///           @endcode
  /// \~english @param  [in] p_inEv
  ///            p_inEv   - pointer of input event info
  /// \~english @par
  ///           p_inEv   TSKM_EVENT_INFO_t*
  /// \~english @code
  /// typedef struct _TSKM_EVENT_INFO_t {
  ///   TSKM_EVENT_t event;
  ///   TSKM_ERR_t errCode;
  ///   pid_t fromPid;
  ///   TSKM_BOOL_t hasExtend;
  ///   uint32_t extendSize;
  ///   void *extendPrm;
  ///   union {
  ///     // TSKM->PRI
  ///     TSKM_EV_PRI_REQ_WAKEUP_PRM_t reqWakeup;
  ///     TSKM_EV_PRI_REQ_DOWN_PRM_t reqDown;
  ///     // PRI->TSKM
  ///     TSKM_EV_PRI_REP_WAKEUP_COMP_PRM_t repWakeupComp;
  ///     TSKM_EV_PRI_REP_DOWN_COMP_PRM_t repDownComp;
  ///     TSKM_EV_PRI_REP_CONNECT_PRM_t repConnect;
  ///     TSKM_EV_PRI_RES_WAKEUP_PRM_t resWakeup;
  ///     TSKM_EV_PRI_RES_DOWN_PRM_t resDown;
  ///     TSKM_EV_LCL_CHG_SVC_STATE_PRM_t chgSvc;
  ///   } prm;
  /// } TSKM_EVENT_INFO_t;
  ///           @endcode
  /// \~english @param  [out] p_outEv
  ///           p_outEv   - pointer of output event info
  /// \~english @par
  ///           p_outEv   TSKM_EVENT_INFO_t*
  /// \~english @retval
  /// \~english @par Preconditions
  ///       -
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///       -
  /// \~english @par Classification
  ///       - public
  /// \~english @par Type
  ///       - method
  /// \~english @par Detail
  ///
  /// \~english @see  None
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_ERR_t tskm_svcsEventHandle(TSKM_SVCS_CTX_t* p_svcs,
                                const TSKM_EVENT_INFO_t* p_inEv,
                                TSKM_EVENT_INFO_t* p_outEv);

  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcsGetSvcBySvcId
  /// \~english @par Summary
  ///           find service in inputed service list by service id.
  /// \~english @param  [in] p_svcs
  ///            p_svcs   - pointer of services object
  /// \~english @par
  ///           p_svcs   TSKM_SVCS_CTX_t*
  /// \~english @code
  ///           typedef struct {
  ///             uint32_t svcNum;           // service num
  ///             TSKM_SVC_CTX_t *svcList;   // services list pointer
  ///           } TSKM_SVCS_CTX_t;
  ///           @endcode
  /// \~english @param  [in] svcId
  ///            svcId  - service Id
  /// \~english @par
  ///            svcId   uint32_t
  /// \~english @retval TSKM_SVC_CTX_t*  service pointer
  /// \~english @retval TSKM_SVC_CTX_t*  NULL
  /// \~english @par Preconditions
  ///       -  none
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///       -  If not find svcId in services list. [NULL]
  /// \~english @par Classification
  ///       -  public
  /// \~english @par Type
  ///       -  method only
  /// \~english @par Detail
  ///           find service in inputed service list by service id.. If do not find then return NULL pointer.
  /// \~english @see getSvcCtxBySvcId
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_SVC_CTX_t* tskm_svcsGetSvcBySvcId(TSKM_SVCS_CTX_t* p_svcs,
                                       TSKM_SVCID_t svcId);

  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcsGetSvcByPid
  /// \~english @par Summary
  ///            find service in inputed service list by process id.
  /// \~english @param  [in] p_svcs
  ///            p_svcs   - pointer of services
  /// \~english @par
  ///           p_svcs   TSKM_SVCS_CTX_t*
  /// \~english @code
  ///           typedef struct {
  ///             uint32_t svcNum;           // service num
  ///             TSKM_SVC_CTX_t *svcList;   // services list pointer
  ///           } TSKM_SVCS_CTX_t;
  ///           @endcode
  /// \~english @param  [in] pid
  ///            pid    - process id
  /// \~english @par
  ///            pid   pid_t
  /// \~english @retval TSKM_SVC_CTX_t*  service pointer
  /// \~english @retval TSKM_SVC_CTX_t*  NULL
  /// \~english @par Preconditions
  ///       -
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///       -  If not find process id in services list. [NULL]
  /// \~english @par Classification
  ///       - public
  /// \~english @par Type
  ///       - method only
  /// \~english @par Detail
  ///           find service in inputed service list by process id. If do not find then return NULL pointer.
  /// \~english @see  getSvcCtxByPid
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_SVC_CTX_t* tskm_svcsGetSvcByPid(TSKM_SVCS_CTX_t* p_svcs, pid_t pid);


  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcsIsWaiting
  /// \~english @par Summary
  ///           Is the service state waiting.
  /// \~english @param  [in] p_svcs
  ///            p_svcs   - pointer of services
  /// \~english @par
  ///           p_svcs   TSKM_SVCS_CTX_t*
  /// \~english @code
  ///           typedef struct {
  ///             uint32_t svcNum;           // service num
  ///             TSKM_SVC_CTX_t *svcList;   // services list pointer
  ///           } TSKM_SVCS_CTX_t;
  ///           @endcode
  /// \~english @retval TSKM_BOOL_t
  /// \~english @par Preconditions
  ///       -
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///       -  If service state is TSKM_SVC_WAITCONNECT and wait response num is 0. [TSKM_FALSE]
  /// \~english @par Classification
  ///       -  public
  /// \~english @par Type
  ///       -  method only
  /// \~english @par Detail
  ///          Is the service state waiting. \n
  ///          There are not service's state equal TSKM_SVC_WAITCONNECT or wait respose number > 0 return TSKM_TRUE.
  /// \~english @see  None
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_BOOL_t tskm_svcsIsWaiting(TSKM_SVCS_CTX_t* p_svcs);

  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcsGetSvcTermWaitState
  /// \~english @par Summary
  ///           Get the service which state equanl not equal terminal.
  /// \~english @code
  ///           typedef struct {
  ///             uint32_t svcNum;           // service num
  ///             TSKM_SVC_CTX_t *svcList;   // services list pointer
  ///           } TSKM_SVCS_CTX_t;
  ///           @endcode
  /// \~english @retval TSKM_SVC_WAIT_STATE_t
  /// \~english @par
  ///            TSKM_SVC_WAIT_STATE_t  enum
  /// \~english @code
  /// typedef enum {
  ///   TSKM_SVC_WAIT_NONE,       // not waiting state
  ///   TSKM_SVC_WAIT_TRANSIENT,  // dynamic service terminal waiting state
  ///   TSKM_SVC_WAIT_BOTH,       // no dynamic/ dyanmic service terminal  waiting state
  /// } TSKM_SVC_WAIT_STATE_t;
  ///            @endcode
  /// \~english @par Preconditions
  ///       -  none
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///           If all services state equal TSKM_SVC_DORMANT. [TSKM_SVC_WAIT_NONE]
  ///           If dynamic service.  [TSKM_SVC_WAIT_TRANSIENT]
  ///           If not dynamic service and state not TSKM_SVC_FINDOWN. [TSKM_SVC_WAIT_BOTH]
  /// \~english @par Classification
  ///       -  public
  /// \~english @par Type
  ///       -  method only
  /// \~english @par Detail
  ///           Get the service which state equanl not equal terminal. \n
  /// \~english @see  None
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_SVC_WAIT_STATE_t tskm_svcsGetSvcTermWaitState(TSKM_SVCS_CTX_t* p_svcs);

  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcsSetBootInfo
  /// \~english @par Summary
  ///             initialize all services boot info.
  /// \~english @param  [in] p_svcs
  ///            p_svcs   - pointer of services
  /// \~english @par
  ///           p_svcs   TSKM_SVCS_CTX_t*
  /// \~english @code
  ///           typedef struct {
  ///             uint32_t svcNum;           // service num
  ///             TSKM_SVC_CTX_t *svcList;   // services list pointer
  ///           } TSKM_SVCS_CTX_t;
  ///           @endcode
  /// \~english @param  [in] p_info
  ///           p_info   - SS_SM_START 'FrameworkunifiedOnStart'/'evStart' message pointer
  /// \~english @par
  ///           p_info   T_SS_SM_START_DataStructType*
  /// \~english @code
  /// Data passed as part of SS_SM_START 'FrameworkunifiedOnStart'/'evStart' message
  /// typedef struct T_SS_SM_START_DataStruct {
  ///     EPWR_WAKEUP_FACTOR_TYPE   startupReason;
  ///     BOOL                      isUserModeOn;
  ///     ESMDataResetModeInfo      dataResetMode;
  ///     EPWR_SC_SECURITY_STATUS   securityStatus;
  ///     EPWR_SC_WAKEUP_TYPE       wakeupType;
  ///     ESMDramBackupStatus       dramBackupStatus;
  ///     ESMResetStatus            resetStatus;
  ///     UI_32                     errResetCount;
  ///     T_SS_SM_START_DataStruct
  /// } T_SS_SM_START_DataStructType;
  ///           @endcode
  /// \~english @param  [in] p_exInfo
  ///           p_exInfo   - FrameworkunifiedOnStart extend info pointer
  /// \~english @par
  ///           p_exInfo   T_SS_SM_START_ExtDataStructType*
  /// \~english @code
  /// /// Extended Parameter for FrameworkunifiedOnStart
  /// typedef struct {
  ///         BOOL             isProgUpdated;
  ///         EMRelaunchStatus relaunchStatus;
  ///         BOOL             isMapUpdated;
  ///         BOOL             isMapDiffUpdated;
  ///         uint8_t          reserved[SS_SM_START_EXT_RSV_SIZE];
  /// } T_SS_SM_START_ExtDataStructType;
  ///          @endcode
  /// \~english @retval TSKM_E_OK
  /// \~english @par
  ///            TSKM_SVC_WAIT_STATE_t  enum
  /// \~english @par Preconditions
  ///       -  call tskm_dataInitAll() to get boot info
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///       -  none
  /// \~english @par Classification
  ///       -  pulbic
  /// \~english @par Type
  ///       -  method only
  /// \~english @par Detail
  ///      - initialize all services boot info.
  /// \~english @see  None
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_ERR_t tskm_svcsSetBootInfo(TSKM_SVCS_CTX_t* p_svcs,
                                T_SS_SM_START_DataStructType* p_info,
                                T_SS_SM_START_ExtDataStructType *p_exInfo);

  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcsAvtiveSvcTerm
  /// \~english @par Summary
  ///           Terminal the dynamic services.
  /// \~english @param  [in] p_svcs
  ///            p_svcs   - pointer of services
  /// \~english @par
  ///           p_svcs   TSKM_SVCS_CTX_t*
  /// \~english @code
  ///           typedef struct {
  ///             uint32_t svcNum;           // service num
  ///             TSKM_SVC_CTX_t *svcList;   // services list pointer
  ///           } TSKM_SVCS_CTX_t;
  ///           @endcode
  /// \~english @retval TSKM_ERR_t
  /// \~english @par
  ///            TSKM_E_OK
  ///            TSKM_E_NG
  /// \~english @par Preconditions
  ///       -  none
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///       -  tskm_svcDownRequest return failed [TSKM_E_NG]
  /// \~english @par Classification
  ///       -  pulbic
  /// \~english @par Type
  ///       - method only
  /// \~english @par Detail
  ///       Terminal all the dynamic services which state equal TSKM_SVC_RUNNING and response num equal 0. \n
  /// \~english @see  tskm_svcDownRequest
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_ERR_t tskm_svcsAvtiveSvcTerm(TSKM_SVCS_CTX_t* p_svcs);

  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcsCallDebugDump
  /// \~english @par Summary
  ///           Send DebugDump message to services.
  /// \~english @param  [in] p_svcs
  ///            p_svcs   - pointer of services
  /// \~english @par
  ///           p_svcs   TSKM_SVCS_CTX_t*
  /// \~english @code
  ///           typedef struct {
  ///             uint32_t svcNum;           // service num
  ///             TSKM_SVC_CTX_t *svcList;   // services list pointer
  ///           } TSKM_SVCS_CTX_t;
  ///           @endcode
  /// \~english @retval TSKM_ERR_t
  /// \~english @par
  ///            TSKM_E_OK
  ///            TSKM_E_NG
  /// \~english @par Preconditions
  ///       -  none
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///       -  tskm_sockSend send DebugDump message failed [TSKM_E_NG]
  /// \~english @par Classification
  ///       - public
  /// \~english @par Type
  ///       - method only
  /// \~english @par Detail
  ///            Send DebugDump message to services which state equal TSKM_SVC_RUNNING. \n
  /// \~english @see  tskm_sockSend
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_ERR_t tskm_svcsCallDebugDump(TSKM_SVCS_CTX_t* p_svcs);

  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcsCallLowMem
  /// \~english @par Summary
  ///           Send checking low memory message to services.
  /// \~english @param  [in] p_svcs
  ///            p_svcs   - pointer of services
  /// \~english @par
  ///           p_svcs   TSKM_SVCS_CTX_t*
  /// \~english @code
  ///           typedef struct {
  ///             uint32_t svcNum;           // service num
  ///             TSKM_SVC_CTX_t *svcList;   // services list pointer
  ///           } TSKM_SVCS_CTX_t;
  ///           @endcode
  /// \~english @retval TSKM_ERR_t
  /// \~english @par
  ///            TSKM_E_OK
  ///            TSKM_E_NG
  /// \~english @par Preconditions
  ///       -  none
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///       - tskm_sockSend send LowMemory message failed [TSKM_E_NG]
  /// \~english @par Classification
  ///       - public
  /// \~english @par Type
  ///       - method only
  /// \~english @par Detail
  ///       Send checking LowMemory message to services which state equal TSKM_SVC_RUNNING. \n
  /// \~english @see  tskm_sockSend
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_ERR_t tskm_svcsCallLowMem(TSKM_SVCS_CTX_t* p_svcs);

// Service
  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcEventHandle
  /// \~english @par Summary
  ///           process event.
  /// \~english @param  [in] p_svcs
  ///            p_svcs   - pointer of services
  /// \~english @par
  ///           p_svcs   TSKM_SVCS_CTX_t*
  /// \~english @code
  ///           typedef struct {
  ///             uint32_t svcNum;           // service num
  ///             TSKM_SVC_CTX_t *svcList;   // services list pointer
  ///           } TSKM_SVCS_CTX_t;
  ///           @endcode
  /// \~english @param  [in][out] p_ev
  ///            p_ev   - event info pointer
  /// \~english @par
  ///           p_ev   TSKM_EVENT_INFO_t*
  /// \~english @code
  /// typedef struct _TSKM_EVENT_INFO_t {
  ///   TSKM_EVENT_t event;
  ///   TSKM_ERR_t errCode;
  ///   pid_t fromPid;
  ///   TSKM_BOOL_t hasExtend;
  ///   uint32_t extendSize;
  ///   void *extendPrm;
  ///   union {
  ///     // TSKM->PRI
  ///     TSKM_EV_PRI_REQ_WAKEUP_PRM_t reqWakeup;
  ///     TSKM_EV_PRI_REQ_DOWN_PRM_t reqDown;
  ///
  ///     // PRI->TSKM
  ///     TSKM_EV_PRI_REP_WAKEUP_COMP_PRM_t repWakeupComp;
  ///     TSKM_EV_PRI_REP_DOWN_COMP_PRM_t repDownComp;
  ///     TSKM_EV_PRI_REP_CONNECT_PRM_t repConnect;
  ///     TSKM_EV_PRI_RES_WAKEUP_PRM_t resWakeup;
  ///     TSKM_EV_PRI_RES_DOWN_PRM_t resDown;
  ///     TSKM_EV_LCL_CHG_SVC_STATE_PRM_t chgSvc;
  ///   } prm;
  /// } TSKM_EVENT_INFO_t;
  ///           @endcode
  /// \~english @retval TSKM_ERR_t
  /// \~english @par
  ///            TSKM_E_OK
  /// \~english @par Preconditions
  ///       -  none
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///       -  none
  /// \~english @par Classification
  ///       - public
  /// \~english @par Type
  ///       - method
  /// \~english @par Detail
  ///         process event.\n
  ///         process connect response.\n
  ///         process disconnect response. \n
  ///         process service wakeup request. \n
  ///         process service down request. \n
  ///         process service debugdump request. \n
  ///         process service exit request. \n
  ///         process service terminal response. \n
  /// \~english @see  isSvcEvent,connectHandle,disConnectHandle,resWakeupHandle, \n
  ///                  resDownHandle,resDebugDumpHandle,reqExit,repTermHandle \n
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_ERR_t tskm_svcEventHandle(TSKM_SVC_CTX_t* p_svc, TSKM_EVENT_INFO_t* p_ev);  // p_ev: [IN/OUT]

  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcExec
  /// \~english @par Summary
  ///           start service.
  /// \~english @param  [in][out] p_svc
  ///            p_svc   - pointer of services
  /// \~english @par
  ///           p_svc   TSKM_SVC_CTX_t*
  /// \~english @code
  /// typedef struct {
  ///   TSKM_SVC_ATTR_t *attr;      // attribute of service
  ///   TSKM_SVC_STATE_t state;     // state of service
  ///   int iFd;                    // inotifyFd used by touch
  ///   pid_t pid;                  // PID of service
  ///   int connFd;                 // service communicate fd
  ///   T_SS_SM_START_DataStructType bootInfo;        // BOOT info
  ///   T_SS_SM_START_ExtDataStructType extBootInfo;  // extend BOOT info
  ///   TSKM_BOOL_t isShmDone;      // shared memory init done
  ///   TSKM_BOOL_t isStepDone;     // step done
  ///   TSKM_BOOL_t isAvailable;    // Availability flag
  ///   uint32_t watchCnt;          // service monitor count
  ///   uint32_t waitResCnt;        // wait response num
  ///   uint32_t waitReqCnt;        // wait request num
  ///   TSKM_GSTEP_REQ_INFO_t request[TSKM_SVC_WAIT_REQ_MAX];
  ///   uint32_t errTermCnt;        // exception terminal count
  /// } TSKM_SVC_CTX_t;
  ///           @endcode
  /// \~english @retval TSKM_ERR_t
  /// \~english @par
  ///            TSKM_E_OK
  ///            TSKM_E_NG
  ///            TSKM_E_STATE
  /// \~english @par Preconditions
  ///       -
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///            - input parameter p_svc is NULL. [TSKM_E_NG]
  ///            - service state is TSKM_SVC_DISABLE [TSKM_E_STATE]
  ///            - reqTouch return failed [TSKM_E_NG]
  ///            - tskm_pf_createProc return failed [TSKM_E_NG]
  /// \~english @par Classification
  ///       - public
  /// \~english @par Type
  ///       - method
  /// \~english @par Detail
  ///       start service which state is TSKM_SVC_DORMANT.\n
  /// \~english @see  svcExec, reqTouch, tskm_pf_createProc
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_ERR_t tskm_svcExec(TSKM_SVC_CTX_t* p_svc);

  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcWakeupRequest
  /// \~english @par Summary
  ///           Send started request to service.
  /// \~english @param  [in][out] p_svc
  ///            p_svc   - pointer of service
  /// \~english @par
  ///           p_svc   TSKM_SVC_CTX_t*
  /// \~english @code
  /// typedef struct {
  ///   TSKM_SVC_ATTR_t *attr;      // attribute of service
  ///   TSKM_SVC_STATE_t state;     // state of service
  ///   int iFd;                    // inotifyFd used by touch
  ///   pid_t pid;                  // PID of service
  ///   int connFd;                 // service communicate fd
  ///   T_SS_SM_START_DataStructType bootInfo;        // BOOT info
  ///   T_SS_SM_START_ExtDataStructType extBootInfo;  // extend BOOT info
  ///   TSKM_BOOL_t isShmDone;      // shared memory init done
  ///   TSKM_BOOL_t isStepDone;     // step done
  ///   TSKM_BOOL_t isAvailable;    // Availability flag
  ///   uint32_t watchCnt;          // service monitor count
  ///   uint32_t waitResCnt;        // wait response num
  ///   uint32_t waitReqCnt;        // wait request num
  ///   TSKM_GSTEP_REQ_INFO_t request[TSKM_SVC_WAIT_REQ_MAX];
  ///   uint32_t errTermCnt;        // exception terminal count
  /// } TSKM_SVC_CTX_t;
  ///           @endcode
  /// \~english @param  [in] p_req
  ///            p_req   - pointer of request
  /// \~english @par
  ///           p_req   TSKM_GSTEP_REQ_INFO_t*
  /// \~english @code
  /// typedef struct {
  ///   TSKM_SVCID_t svcId;           // service ID
  ///   TSKM_LOCAL_STEP_t localStep;  // local step id
  /// } TSKM_GSTEP_REQ_INFO_t;
  ///            @endcode
  /// \~english @retval TSKM_ERR_t
  /// \~english @par
  ///            TSKM_E_OK
  ///            TSKM_E_NG
  ///            TSKM_E_STATE
  /// \~english @par Preconditions
  ///       -  none
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///            - Input parameter p_svc is NULL. [TSKM_E_STATE]
  ///            - Service state is TSKM_SVC_DISABLE [TSKM_E_STATE]
  ///            - wakeupRequest return failed [TSKM_E_NG]
  /// \~english @par Classification
  ///       - public
  /// \~english @par Type
  ///       - method
  /// \~english @par Detail
  ///       Send started request to service. If service do not connect, save the request.\n
  ///       Send request again when service connect. \n
  /// \~english @see  svcWakeupRequest
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_ERR_t tskm_svcWakeupRequest(TSKM_SVC_CTX_t* p_svc,
                                 TSKM_GSTEP_REQ_INFO_t* p_req);


  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcDownRequest
  /// \~english @par Summary
  ///           Send service down request to service.
  /// \~english @param  [in][out] p_svc
  ///            p_svc   - pointer service
  /// \~english @par
  ///           p_svc   TSKM_SVC_CTX_t*
  /// \~english @code
  /// typedef struct {
  ///   TSKM_SVC_ATTR_t *attr;      // attribute of service
  ///   TSKM_SVC_STATE_t state;     // state of service
  ///   int iFd;                    // inotifyFd used by touch
  ///   pid_t pid;                  // PID of service
  ///   int connFd;                 // service communicate fd
  ///   T_SS_SM_START_DataStructType bootInfo;        // BOOT info
  ///   T_SS_SM_START_ExtDataStructType extBootInfo;  // extend BOOT info
  ///   TSKM_BOOL_t isShmDone;      // shared memory init done
  ///   TSKM_BOOL_t isStepDone;     // step done
  ///   TSKM_BOOL_t isAvailable;    // Availability flag
  ///   uint32_t watchCnt;          // service monitor count
  ///   uint32_t waitResCnt;        // wait response num
  ///   uint32_t waitReqCnt;        // wait request num
  ///   TSKM_GSTEP_REQ_INFO_t request[TSKM_SVC_WAIT_REQ_MAX];
  ///   uint32_t errTermCnt;        // exception terminal count
  /// } TSKM_SVC_CTX_t;
  ///           @endcode
  /// \~english @param  [in] p_req
  ///            p_req   - request pointer
  /// \~english @par
  ///           p_req   TSKM_GSTEP_REQ_INFO_t*
  /// \~english @code
  /// typedef struct {
  ///   TSKM_SVCID_t svcId;           // service ID
  ///   TSKM_LOCAL_STEP_t localStep;  // local step id
  /// } TSKM_GSTEP_REQ_INFO_t;
  ///            @endcode
  /// \~english @retval TSKM_ERR_t
  /// \~english @par
  ///            TSKM_E_OK
  ///            TSKM_E_NG
  /// \~english @par Preconditions
  ///       -
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///       -  Send service down request failed [TSKM_E_NG]
  /// \~english @par Classification
  ///       - public
  /// \~english @par Type
  ///       - method
  /// \~english @par Detail
  ///       If service state is commounicated(TSKM_SVC_WAKEUP, TSKM_SVC_RUNNING), \n
  ///            send service down request and set state as TSKM_SVC_DOWN.\n
  /// \~english @see  tskm_svcIsCommunicatable,tskm_sockSend
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_ERR_t tskm_svcDownRequest(TSKM_SVC_CTX_t* p_svc,
                               TSKM_GSTEP_REQ_INFO_t* p_req);

  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcDisableRequest
  /// \~english @par Summary
  ///
  /// \~english @param  [in][out] p_svc
  ///            p_svc   - pointer of service
  /// \~english @par
  ///           p_svc   TSKM_SVC_CTX_t*
  /// \~english @code
  /// typedef struct {
  ///   TSKM_SVC_ATTR_t *attr;      // attribute of service
  ///   TSKM_SVC_STATE_t state;     // state of service
  ///   int iFd;                    // inotifyFd used by touch
  ///   pid_t pid;                  // PID of service
  ///   int connFd;                 // service communicate fd
  ///   T_SS_SM_START_DataStructType bootInfo;        // BOOT info
  ///   T_SS_SM_START_ExtDataStructType extBootInfo;  // extend BOOT info
  ///   TSKM_BOOL_t isShmDone;      // shared memory init done
  ///   TSKM_BOOL_t isStepDone;     // step done
  ///   TSKM_BOOL_t isAvailable;    // Availability flag
  ///   uint32_t watchCnt;          // service monitor count
  ///   uint32_t waitResCnt;        // wait response num
  ///   uint32_t waitReqCnt;        // wait request num
  ///   TSKM_GSTEP_REQ_INFO_t request[TSKM_SVC_WAIT_REQ_MAX];
  ///   uint32_t errTermCnt;        // exception terminal count
  /// } TSKM_SVC_CTX_t;
  ///           @endcode
  /// \~english @retval TSKM_ERR_t
  /// \~english @par
  ///            TSKM_E_OK
  ///            TSKM_E_STATE
  /// \~english @par Preconditions
  ///       -
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///       -  If service state is not TSKM_SVC_DORMANT and TSKM_SVC_DISABLE. [TSKM_E_STATE]
  /// \~english @par Classification
  ///       -  public
  /// \~english @par Type
  ///       - method
  /// \~english @par Detail
  ///       Set service state as TSKM_SVC_DISABLE if state is TSKM_SVC_DORMANT.
  /// \~english @see  None
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_ERR_t tskm_svcDisableRequest(TSKM_SVC_CTX_t* p_svc);

  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcDisableRequest
  /// \~english @par Summary
  ///           Set service state as start available.
  /// \~english @param  [in][out] p_svc
  ///            p_svc   - Pointer to service
  /// \~english @par
  ///           p_svc   TSKM_SVC_CTX_t*
  /// \~english @code
  /// typedef struct {
  ///   TSKM_SVC_ATTR_t *attr;      // attribute of service
  ///   TSKM_SVC_STATE_t state;     // state of service
  ///   int iFd;                    // inotifyFd used by touch
  ///   pid_t pid;                  // PID of service
  ///   int connFd;                 // service communicate fd
  ///   T_SS_SM_START_DataStructType bootInfo;        // BOOT info
  ///   T_SS_SM_START_ExtDataStructType extBootInfo;  // extend BOOT info
  ///   TSKM_BOOL_t isShmDone;      // shared memory init done
  ///   TSKM_BOOL_t isStepDone;     // step done
  ///   TSKM_BOOL_t isAvailable;    // Availability flag
  ///   uint32_t watchCnt;          // service monitor count
  ///   uint32_t waitResCnt;        // wait response num
  ///   uint32_t waitReqCnt;        // wait request num
  ///   TSKM_GSTEP_REQ_INFO_t request[TSKM_SVC_WAIT_REQ_MAX];
  ///   uint32_t errTermCnt;        // exception terminal count
  /// } TSKM_SVC_CTX_t;
  ///           @endcode
  /// \~english @retval TSKM_ERR_t
  /// \~english @par
  ///            TSKM_E_OK
  /// \~english @par Preconditions
  ///       -
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///       -  none
  /// \~english @par Classification
  ///       - public
  /// \~english @par Type
  ///       - method
  /// \~english @par Detail
  ///           Set service state as start available which state is disable(TSKM_SVC_DISABLE).
  /// \~english @see  None
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_ERR_t tskm_svcEnableRequest(TSKM_SVC_CTX_t* p_svc);

  /////////////////////////////////////////////////////////////////////////////////////
  /// \ingroup tskm_svcIsCommunicatable
  /// \~english @par Summary
  ///           Whether service is Communicatable.
  /// \~english @param  [in] p_svc
  ///            p_svc   - pointer of service
  /// \~english @par
  ///           p_svc   TSKM_SVC_CTX_t*
  /// \~english @code
  /// typedef struct {
  ///   TSKM_SVC_ATTR_t *attr;      // attribute of service
  ///   TSKM_SVC_STATE_t state;     // state of service
  ///   int iFd;                    // inotifyFd used by touch
  ///   pid_t pid;                  // PID of service
  ///   int connFd;                 // service communicate fd
  ///   T_SS_SM_START_DataStructType bootInfo;        // BOOT info
  ///   T_SS_SM_START_ExtDataStructType extBootInfo;  // extend BOOT info
  ///   TSKM_BOOL_t isShmDone;      // shared memory init done
  ///   TSKM_BOOL_t isStepDone;     // step done
  ///   TSKM_BOOL_t isAvailable;    // Availability flag
  ///   uint32_t watchCnt;          // service monitor count
  ///   uint32_t waitResCnt;        // wait response num
  ///   uint32_t waitReqCnt;        // wait request num
  ///   TSKM_GSTEP_REQ_INFO_t request[TSKM_SVC_WAIT_REQ_MAX];
  ///   uint32_t errTermCnt;        // exception terminal count
  /// } TSKM_SVC_CTX_t;
  ///           @endcode
  /// \~english @retval TSKM_BOOL_t
  /// \~english @par
  ///            TSKM_FALSE
  ///            TSKM_TRUE
  /// \~english @par Preconditions
  ///       -
  /// \~english @par Change of the internal state
  ///       -  The internal state is not changed.
  /// \~english @par Causes of failures
  ///            - If input parameter p_svc is NULL.  [TSKM_FALSE]
  ///            - If input parameter p_svc->attr->type is TSKM_SVC_TYPE_UNKNONW. [TSKM_FALSE]
  ///            - If service state is TSKM_SVC_DORMANT or TSKM_SVC_WAITCONNECT or
  ///              TSKM_SVC_FINDOWN orTSKM_SVC_DISABLE. [TSKM_FALSE]
  /// \~english @par Classification
  ///       - public
  /// \~english @par Type
  ///       - method
  /// \~english @par Detail
  ///       Whether service is Communicatable. \n
  ///       If service state is TSKM_SVC_WAKEUP or TSKM_SVC_RUNNING or TSKM_SVC_DOWN, return TSKM_TRUE. \n
  /// \~english @see  None
  ////////////////////////////////////////////////////////////////////////////////////
TSKM_BOOL_t tskm_svcIsCommunicatable(TSKM_SVC_CTX_t* p_svc);

#endif  // TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_SVC_H_
/** @}*/
/** @}*/
/** @}*/