1 /*******************************************************************************
2 
3     KHOMP generic endpoint/channel library.
4     Copyright (C) 2007-2010 Khomp Ind. & Com.
5 
6   The contents of this file are subject to the Mozilla Public License
7   Version 1.1 (the "License"); you may not use this file except in compliance
8   with the License. You may obtain a copy of the License at
9   http://www.mozilla.org/MPL/
10 
11   Software distributed under the License is distributed on an "AS IS" basis,
12   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
13   the specific language governing rights and limitations under the License.
14 
15   Alternatively, the contents of this file may be used under the terms of the
16   "GNU Lesser General Public License 2.1" license (the “LGPL" License), in which
17   case the provisions of "LGPL License" are applicable instead of those above.
18 
19   If you wish to allow use of your version of this file only under the terms of
20   the LGPL License and not to allow others to use your version of this file
21   under the MPL, indicate your decision by deleting the provisions above and
22   replace them with the notice and other provisions required by the LGPL
23   License. If you do not delete the provisions above, a recipient may use your
24   version of this file under either the MPL or the LGPL License.
25 
26   The LGPL header follows below:
27 
28     This library is free software; you can redistribute it and/or
29     modify it under the terms of the GNU Lesser General Public
30     License as published by the Free Software Foundation; either
31     version 2.1 of the License, or (at your option) any later version.
32 
33     This library is distributed in the hope that it will be useful,
34     but WITHOUT ANY WARRANTY; without even the implied warranty of
35     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
36     Lesser General Public License for more details.
37 
38     You should have received a copy of the GNU Lesser General Public License
39     along with this library; if not, write to the Free Software Foundation,
40     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
41 
42 *******************************************************************************/
43 
44 #ifndef _DEFS_H_
45 #define _DEFS_H_
46 
47 /* formatation macros */
48 #include "revision.h"
49 
50 #define KHOMP_LOG __FILE__, __SWITCH_FUNC__, __LINE__
51 #define KHOMP_EVENT_MAINT "khomp::maintenance"
52 
53 #define OBJ_FMT(dev,obj,msg) \
54     FMT("%s (d=%02d,c=%03d) " msg) % __SWITCH_FUNC__ % dev % obj
55 
56 #define OBJ_MSG(dev,obj,msg) \
57     "%s (d=%02d,c=%03d) " msg, __SWITCH_FUNC__, dev, obj
58 
59 #define PVT_FMT(tgt,msg) \
60     FMT("%s (d=%02d,c=%03d) " msg) % __SWITCH_FUNC__ % tgt.device % tgt.object
61 
62 #define PVT_MSG(tgt,msg) \
63     "%s (d=%02d,c=%03d) " msg, __SWITCH_FUNC__, tgt.device, tgt.object
64 
65 #define D(x) ( FMT( "%s: " x ) % __func__ )
66 
67 #define STR(fmt) \
68     STG(fmt).c_str()
69 
70 /* version controller macro */
71 #define SWITCH_LESS_THAN(x,y,z)                                                           \
72    (FS_VERSION_MICRO != -1) &&                                                            \
73    (((FS_VERSION_MAJOR == x)  && (FS_VERSION_MINOR == y)  &&  (FS_VERSION_MICRO <= z)) || \
74    ((FS_VERSION_MAJOR == x)  && (FS_VERSION_MINOR < y)) || (FS_VERSION_MAJOR < x))
75 
76 /* signalling groups macro */
77 #define CASE_R2_SIG         \
78     case ksigR2Digital:     \
79     case ksigContinuousEM:  \
80     case ksigPulsedEM:      \
81     case ksigUserR2Digital: \
82     case ksigOpenCAS:       \
83     case ksigOpenR2
84 /*
85     case ksigLineSide:      \
86     case ksigCAS_EL7:       \
87     case ksigE1LC
88 */
89 
90 #define CASE_RDSI_SIG       \
91     case ksigPRI_EndPoint:  \
92     case ksigPRI_Network:   \
93     case ksigPRI_Passive:   \
94     case ksigOpenCCS
95 
96 #define CASE_FLASH_GRP          \
97     case ksigLineSide:          \
98     case ksigCAS_EL7:           \
99     case ksigE1LC
100 
101 /******************************************************************************/
102 
103 /* Buffering size constants */
104 
105 #define SILENCE_PACKS               2
106 
107 #define KHOMP_READ_PACKET_TIME     16                            // board sample (ms)
108 
109 #define KHOMP_READ_PACKET_SIZE    (KHOMP_READ_PACKET_TIME *   8) // asterisk sample size (bytes)
110 
111 #define KHOMP_MIN_READ_PACKET_SIZE (10 * 8)                      // min size to return on khomp_read
112 #define KHOMP_MAX_READ_PACKET_SIZE (30 * 8)                      // max size to return on khomp_read
113 
114 #define KHOMP_AUDIO_BUFFER_SIZE   (KHOMP_READ_PACKET_SIZE  *  8) // buffer size (bytes)
115 
116 /* debug and log macros */
117 #define DBG(x,y) \
118     { \
119         if (K::Logger::Logg.classe( C_DBG_##x ).enabled()) \
120                 K::Logger::Logg( C_DBG_##x , y ); \
121     }
122 
123 #define LOG(x,y) \
124     { \
125         K::Logger::Logg( C_##x , y ); \
126     }
127 
128 #define LOGC(x,y) \
129     { \
130         if (K::Logger::Logg.classe( C_##x ).enabled()) \
131             LOG( x , y ); \
132     }
133 
134 /* useful to debug arguments */
135 #define DEBUG_CLI_CMD() \
136 { \
137     K::Logger::Logg2(C_CLI,stream,FMT("argc: %d ") % argc); \
138     for(int i = 0;i< argc;i++)                              \
139         K::Logger::Logg2(C_CLI,stream,FMT("argv[%d]:%s ") % i % argv[i]); \
140 }
141 
142 /* macros to cli commands */
143 #define ARG_CMP(a,b) (argv[a] && !strncasecmp(argv[a],b,sizeof(b)))
144 #define EXEC_CLI_CMD(command) Cli::command.execute(argc,argv)
145 
146 /* macro to string treats */
147 #define SAFE_sprintf(a, ...)    snprintf(a,sizeof(a), __VA_ARGS__)
148 #define SAFE_strcasecmp(a,b)    strncasecmp(a, b, sizeof(b))
149 
150 /* tags for timers */
151 #define TM_VAL_CALL    (unsigned int)0x01
152 #define TM_VAL_CHANNEL (unsigned int)0x02
153 
154 /* macro to creating contexts */
155 #define BEGIN_CONTEXT do
156 #define END_CONTEXT while(false);
157 
158 /* Define log type */
159 typedef enum
160 {
161     C_CLI,      /* cli msgs    */
162 
163     C_ERROR,    /* errors      */
164     C_WARNING,  /* warnings    */
165     C_MESSAGE,  /* normal msgs */
166 
167     C_EVENT,    /* k3l events   */
168     C_COMMAND,  /* k3l commands */
169 
170     C_AUDIO_EV, /* k3l audio events */
171     C_MODEM_EV, /* gsm modem events */
172     C_LINK_STT, /* link status msgs */
173     C_CAS_MSGS, /* cas events msgs  */
174 
175     C_DBG_FUNC,
176     C_DBG_LOCK,
177     C_DBG_THRD,
178     C_DBG_STRM,
179 
180     C_DBG_CONF,
181 }
182 class_type;
183 
184 typedef enum
185 {
186     O_CONSOLE,
187     O_GENERIC,
188     O_R2TRACE,
189 }
190 output_type;
191 
192 typedef enum
193 {
194     SCE_SHOW_WARNING,
195     SCE_SHOW_DEBUG,
196     SCE_SHOW_SAME,
197     SCE_HIDE
198 }
199 send_cmd_error_type;
200 
201 typedef enum
202 {
203     T_UNKNOWN = 2,
204     T_TRUE = 1,
205     T_FALSE = 0,
206 }
207 TriState;
208 
209 
210 #endif
211