Initialize smart traffic control iptables package
[platform/core/connectivity/stc-iptables.git] / test / stc_ipt_menu.h
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __STC_IPT_MENU_H__
18 #define __STC_IPT_MENU_H__
19
20 __BEGIN_DECLS
21
22 #define LOG_END                 "\e[0m"
23
24 #define LOG_BLACK                       "\e[0;30m"
25 #define LOG_RED                         "\e[0;31m"
26 #define LOG_GREEN                       "\e[0;32m"
27 #define LOG_BROWN                       "\e[0;33m"
28 #define LOG_BLUE                        "\e[0;34m"
29 #define LOG_MAGENTA                     "\e[0;35m"
30 #define LOG_CYAN                        "\e[0;36m"
31 #define LOG_LIGHTGRAY           "\e[0;37m"
32
33 #define LOG_DARKGRAY            "\e[1;30m"
34 #define LOG_LIGHTRED            "\e[1;31m"
35 #define LOG_LIGHTGREEN          "\e[1;32m"
36 #define LOG_YELLOW                      "\e[1;33m"
37 #define LOG_LIGHTBLUE           "\e[1;34m"
38 #define LOG_LIGHTMAGENTA        "\e[1;35m"
39 #define LOG_LIGHTCYAN           "\e[1;36m"
40 #define LOG_WHITE                       "\e[1;37m"
41
42
43 #define msg(fmt,args...)        do { fprintf(stdout, fmt "\n", ##args); \
44                 fflush(stdout); } while (0)
45 #define msgn(fmt,args...)       do { fprintf(stdout, fmt, ##args); \
46                 fflush(stdout); } while (0)
47
48 /* Bold (green) */
49 #define msgb(fmt,args...)  do { fprintf(stdout, LOG_LIGHTGREEN fmt \
50                 LOG_END "\n", ##args); fflush(stdout); } while (0)
51
52 /* Property message */
53 #define msgp(fmt,args...) do { fprintf(stdout, LOG_LIGHTMAGENTA fmt \
54                 LOG_END "\n", ##args); fflush(stdout); } while (0)
55
56 #define msgt(n,fmt,args...) do { fprintf(stdout, "\e[%dC" fmt "\n", \
57                 3 + ((n) * 2), ##args); fflush(stdout); } while (0)
58
59 #define pmsg(fmt,args...) do { \
60         if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \
61         fprintf(stdout, fmt "\n", ##args); fflush(stdout); } while (0)
62
63 #define pmsgb(fmt,args...) do { \
64         if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \
65         fprintf(stdout, LOG_LIGHTGREEN fmt \
66                         LOG_END "\n", ##args); fflush(stdout); } while (0)
67
68 #define pmsgt(n,fmt,args...) do { \
69         if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \
70         fprintf(stdout, "\e[%dC" fmt "\n", \
71                         3 + ((n) * 2), ##args); fflush(stdout); } while (0)
72
73 #define MENU_DATA_SIZE 255
74
75
76
77 /*
78  * Horizontal Line - width: 65
79  *                                      .12345678901234567890123456789012345678901234567890.
80  */
81 #define HR_SINGLE       "----------------------------------------" \
82                                         "-------------------------"
83 #define HR_DOUBLE       "========================================" \
84                                         "========================="
85 #define HR_SINGLE2      " ---------------------------------------" \
86                                         "------------------------ "
87
88 #define MAX_WIDTH       strlen (HR_SINGLE)
89 #define MAX_TITLE       ((MAX_WIDTH) - 10)
90 #define POS_MORE        ((MAX_WIDTH) - 3)
91 #define RET_SUCCESS 0
92 #define RET_FAILURE -1
93
94 typedef struct menu_manager MManager;
95
96 struct menu_data {
97         const char *key;
98         const char *title;
99         struct menu_data *sub_menu;
100         int (*callback)(MManager *mm, struct menu_data *menu);
101         char *data;
102 };
103
104 MManager* menu_manager_new(struct menu_data items[], GMainLoop *mainloop);
105 int       menu_manager_run(MManager *mm);
106 int       menu_manager_set_user_data(MManager *mm, void *user_data);
107 void*     menu_manager_ref_user_data(MManager *mm);
108
109 gboolean  on_menu_manager_keyboard(GIOChannel *src, GIOCondition con,
110                 gpointer data);
111
112 pid_t     get_tid ();
113 void      hide_pid ();
114 void      show_pid ();
115 int       is_pid_show ();
116 void      menu_print_dump(int data_len, void *data);
117
118 __END_DECLS
119
120 #endif /* __STC_IPT_MENU_H__ */