summaryrefslogtreecommitdiffstats
path: root/task_manager/server/include/tskm_debug.h
blob: ae963a8fa0ed954902b1466745f89f010b0ab914 (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
/*
 * @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.
 */

#ifndef TASK_MANAGER_SERVER_INCLUDE_TSKM_DEBUG_H_
#define TASK_MANAGER_SERVER_INCLUDE_TSKM_DEBUG_H_

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <native_service/ns_logger_if.h>
#include "system_service/tskm_svc.h"

#include "system_service/tskm_local_type.h"

#define TSKM_STATIC static

// for frameworkunifiedlog
#define ZONE_INIT         ZONEMASK(10)  // Reserved for lib
#define ZONE_FUNC         ZONEMASK(11)  // Reserved for lib
#define ZONE_MEM          ZONEMASK(12)  // Reserved for lib
#define ZONE_OUT          ZONEMASK(13)
#define ZONE_STATE        ZONEMASK(14)  // Basic state change
#define ZONE_15           ZONEMASK(15)
#define ZONE_16           ZONEMASK(16)
#define ZONE_17           ZONEMASK(17)
#define ZONE_18           ZONEMASK(18)
#define ZONE_19           ZONEMASK(19)
#define ZONE_20           ZONEMASK(20)
#define ZONE_21           ZONEMASK(21)
#define ZONE_22           ZONEMASK(22)
#define ZONE_23           ZONEMASK(23)
#define ZONE_24           ZONEMASK(24)
#define ZONE_25           ZONEMASK(25)
#define ZONE_26           ZONEMASK(26)
#define ZONE_27           ZONEMASK(27)
#define ZONE_28           ZONEMASK(28)
#define ZONE_INFO         ZONEMASK(29)  // Reserved for lib
#define ZONE_WARN         ZONEMASK(30)  // Reserved for lib
#define ZONE_ERR          ZONEMASK(31)  // Reserved for lib

#define ZONE_TEXT_10      "Init"
#define ZONE_TEXT_11      "Function"
#define ZONE_TEXT_12      "Memory"
#define ZONE_TEXT_13      ""
#define ZONE_TEXT_14      ""
#define ZONE_TEXT_15      ""
#define ZONE_TEXT_16      ""
#define ZONE_TEXT_17      ""
#define ZONE_TEXT_18      ""
#define ZONE_TEXT_19      ""
#define ZONE_TEXT_20      ""
#define ZONE_TEXT_21      ""
#define ZONE_TEXT_22      ""
#define ZONE_TEXT_23      ""
#define ZONE_TEXT_24      ""
#define ZONE_TEXT_25      ""
#define ZONE_TEXT_26      ""
#define ZONE_TEXT_27      ""
#define ZONE_TEXT_28      ""
#define ZONE_TEXT_29      "Info"
#define ZONE_TEXT_30      "Warning"
#define ZONE_TEXT_31      "Error"

#ifndef  FRAMEWORKUNIFIEDLOGOPTIONS
#define FRAMEWORKUNIFIEDLOGOPTIONS (LPRINT|LMSGQ)  // LPRINT , LMSGQ, LSLOGGER
#endif

#ifndef FRAMEWORKUNIFIEDLOGAPPZONES
#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_OUT, ZONE_WARN, ZONE_ERR, ZONE_STATE, ZONE_PERFORMANCE, ZONE_SYSTEMDATA
/*
 ZONE_NS_FUNC,\
  ZONE_NS_DIS,\
  ZONE_NS__CWORD77_,\
  ZONE_NS_IMP_INFO,\
  ZONE_NS_SM_DEV_INFO,\
  ZONE_NS_SM_USR_INFO,\
  ZONE_NS_INFO,\
  ZONE_NS_DEBUG_DUMP,\
  ZONE_NS_WAR       ,\
  ZONE_NS_ERR       ,\
  ZONE_DEBUG_DUMP
 */
#endif

#define TSKM_LOG_ERROR      0x00000001U
#define TSKM_LOG_STATE      0x00000002U
#define TSKM_LOG_DEBUG      0x00000004U
#define TSKM_LOG_API        0x00000008U
#define TSKM_LOG_PORTPF     0x00000010U
#define TSKM_LOG_FUNC       0x00000020U
#define TSKM_LOG_MSG        0x00000040U
#define TSKM_LOG_WARN       0x00000080U
#define TSKM_LOG_SVCSTATE   0x00000100U
#define TSKM_LOG_SYSTEMDATA 0x00000200U

// For debugging
#define TSKM_LOG_CUSTUM  (0 \
                        )
/*
 |TSKM_LOG_MSG    \
                         |TSKM_LOG_DEBUG  \
                         |TSKM_LOG_FUNC   \
                         |TSKM_LOG_PORTPF \
 */

typedef enum {
  TSKM_LOG_TYPE_TEXT,
  TSKM_LOG_TYPE_PLACE,
} TSKM_LOG_TYPE_t;

#define TSKM_DEFAULT_PRINTF(flag, fmt, ...) { \
    switch (flag) { \
        case TSKM_LOG_SYSTEMDATA: \
            FRAMEWORKUNIFIEDLOG(ZONE_SYSTEMDATA, __FUNCTION__, fmt, ##__VA_ARGS__); \
            break; \
        case TSKM_LOG_API: \
        case TSKM_LOG_STATE: \
            FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, fmt, ##__VA_ARGS__); \
            break; \
        case TSKM_LOG_ERROR: \
            FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, fmt, ##__VA_ARGS__); \
            break; \
        case TSKM_LOG_WARN: \
            FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, fmt, ##__VA_ARGS__); \
            break; \
        case TSKM_LOG_DEBUG: \
            FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, fmt, ##__VA_ARGS__); \
            break; \
        case TSKM_LOG_MSG: \
        case TSKM_LOG_FUNC: \
        case TSKM_LOG_PORTPF: \
        default: \
            FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, fmt, ##__VA_ARGS__); \
            break; \
    } \
  }

#define TSKM_PRINTF(flag, fmt, ...) { \
    if (TSKM_LOG_SVCSTATE == flag) { \
      /* Logs at startup and termination */ \
      FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, fmt, ## __VA_ARGS__); \
    } else if (TSKM_LOG_CUSTUM & flag) { \
      /* Logging by STATE when CUSTUM is specified */ \
      FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, fmt, ## __VA_ARGS__); \
    } else { \
      TSKM_DEFAULT_PRINTF(flag, fmt, ## __VA_ARGS__); \
    } \
  }

#define TSKM_ASSERT(x)  \
          if (!(x)) { \
            FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "TSKM_ASSERT"); \
          }

#define TSKM_ASSERT_ERRNO(x)  \
          if (!(x)) { \
             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "TSKM_ASSERT %d:%s", errno, strerror(errno)); \
          }

#define TSKM_ASSERT_PRINT(x, fmt, ...) \
          if (!(x)) { \
            FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "TSKM_ASSERT:" fmt, ## __VA_ARGS__); \
          }

#define TSKM_STATIC_ASSERT(expr) \
  { \
    char STATIC_ASSERTION_FAILED[(expr) ? 1 : -1]; \
    (void)STATIC_ASSERTION_FAILED; \
  }

#define TSKM_DUMP(addr, size) { \
    char* buf = (char*)addr;  /* NOLINT (readability/casting) */  \
    int ii; \
    printf("[DUMP] %s:%d addr:%p size:%d", __FUNCTION__, __LINE__, addr, size); \
    for (ii=0 ; ii < size ; ii++) { \
      if (ii%16 == 0) printf(" "); \
      if (ii%32 == 0) printf("\n");  \
      printf("%02x", buf[ii]);  \
    } \
    printf("\n"); \
  }

#define TSKM_FUNC_IN() TSKM_PRINTF(TSKM_LOG_FUNC, "%s:IN", __FUNCTION__)

#define TSKM_FUNC_OUT() TSKM_PRINTF(TSKM_LOG_FUNC, "%s:OUT", __FUNCTION__)

const char* tskm_convState2Str(TSKM_STATE_t state);
const char* tskm_convLocalStep2Str(TSKM_LOCAL_STEP_t localStep);
const char* tskm_convEvent2Str(TSKM_EVENT_t event);
const char* tskm_convInitCompId2Str(uint64_t compId);
const char* tskm_convTermCompId2Str(uint64_t compId);
const char* tskm_convSvcState2Str(TSKM_SVC_STATE_t state);
void tskm_svcsDump(TSKM_SVCS_CTX_t* p_svcs);

#endif  // TASK_MANAGER_SERVER_INCLUDE_TSKM_DEBUG_H_