File: main_process.cxx

package info (click to toggle)
t38modem 2.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,032 kB
  • sloc: cpp: 12,647; ansic: 155; makefile: 62
file content (267 lines) | stat: -rw-r--r-- 6,623 bytes parent folder | download | duplicates (2)
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
/*
 * main_process.cxx
 *
 * T38FAX Pseudo Modem
 *
 * Copyright (c) 2007-2010 Vyacheslav Frolov
 *
 * Open H323 Project
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.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.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 *
 * The Original Code is Open H323 Library.
 *
 * The Initial Developer of the Original Code is Vyacheslav Frolov
 *
 * Contributor(s):
 *
 * $Log: main_process.cxx,v $
 * Revision 1.9  2010/02/12 08:33:44  vfrolov
 * Moved PTrace::Initialise() to beginning
 *
 * Revision 1.8  2009/07/29 10:39:04  vfrolov
 * Moved h323lib specific code to h323lib directory
 *
 * Revision 1.7  2009/07/15 13:23:19  vfrolov
 * Added Descriptions(args)
 *
 * Revision 1.6  2009/07/03 09:18:11  vfrolov
 * Included opal/buildopts.h
 * Added workarounds for race condition on exit
 * Suppressed version tracing on help output
 *
 * Revision 1.5  2009/04/03 12:04:36  vfrolov
 * Added versions of used libs to output
 *
 * Revision 1.4  2009/01/21 12:25:12  vfrolov
 * Added tracing of options
 *
 * Revision 1.3  2008/09/11 16:04:47  frolov
 * Added list of libs to output
 *
 * Revision 1.2  2008/09/10 11:15:00  frolov
 * Ported to OPAL SVN trunk
 *
 * Revision 1.1  2007/05/17 08:32:44  vfrolov
 * Moved class T38Modem from main.h and main.cxx to main_process.cxx
 *
 */

#include <ptlib.h>

#ifdef USE_OPAL
  #include <opal/buildopts.h>
#endif

#include "version.h"

#ifdef USE_OPAL
  #include "opal/manager.h"
#else
  #include "h323lib/h323ep.h"
#endif

#define new PNEW

/////////////////////////////////////////////////////////////////////////////
static PString GetListOfLibs()
{
  return
#ifdef USE_OPAL
    PString("OPAL-")
    + PString(OPAL_VERSION)
    + PString("/")
    + OpalGetVersion()
#else
  #if OPENH323_MAJOR < 1 || (OPENH323_MAJOR == 1 && OPENH323_MINOR <= 19)
    PString("OpenH323-") + PString(OPENH323_VERSION)
  #else
    PString("H323plus-") + PString(OPENH323_VERSION)
  #endif
#endif
#ifdef PTLIB_VERSION
    + PString(", PTLIB-")
    + PString(PTLIB_VERSION)
  #if PTLIB_MAJOR > 2 || (PTLIB_MAJOR == 2 && PTLIB_MINOR >= 6)
    + PString("/")
    + PProcess::GetLibVersion()
  #endif
#endif
#ifdef PWLIB_VERSION
    + PString(", PWLIB-") + PString(PWLIB_VERSION)
#endif
  ;
}
/////////////////////////////////////////////////////////////////////////////
class T38Modem : public PProcess
{
  PCLASSINFO(T38Modem, PProcess)

  public:
    T38Modem();

    void Main();

  protected:
    PBoolean Initialise();
};

PCREATE_PROCESS(T38Modem);
///////////////////////////////////////////////////////////////
T38Modem::T38Modem()
  : PProcess("Vyacheslav Frolov", "T38Modem",
             MAJOR_VERSION, MINOR_VERSION, BUILD_TYPE, BUILD_NUMBER)
{
}

void T38Modem::Main()
{
  cout << GetName()
       << " Version " << GetVersion(TRUE) << "\n"
       << " (" << GetListOfLibs() << ")"
       << " by " << GetManufacturer()
       << " on " << GetOSClass() << ' ' << GetOSName()
       << " (" << GetOSVersion() << '-' << GetOSHardware() << ")\n"
       << endl;

  if (!Initialise()) {
    PThread::Sleep(100);  // workaround for race condition
    return;
  }

  for (;;)
    PThread::Sleep(5000);
}

PBoolean T38Modem::Initialise()
{
  PConfigArgs args(GetArguments());

  args.Parse(
#ifdef USE_OPAL
             MyManager::ArgSpec() +
#else
             MyH323EndPoint::ArgSpec() +
#endif
             "h-help."
             "v-version."
#if PMEMORY_CHECK
             "-setallocationbreakpoint:"
#endif
#if PTRACING
             "t-trace."
             "o-output:"
#endif
             "-save."
          , FALSE);

#if PMEMORY_CHECK
  if (args.HasOption("setallocationbreakpoint"))
    PMemoryHeap::SetAllocationBreakpoint(args.GetOptionString("setallocationbreakpoint").AsInteger());
#endif

#if PTRACING
  PTrace::Initialise(args.GetOptionCount('t'),
                     args.HasOption('o') ? (const char *)args.GetOptionString('o') : NULL,
                     PTrace::DateAndTime | PTrace::Thread | PTrace::Blocks);
#endif

  if (args.HasOption('h')) {
    cout <<
        "Usage:\n"
        "  " << GetName() << " [options]\n"
        "\n"
        "Options:\n"
#if PTRACING
        "  -t --trace                : Enable trace, use multiple times for more detail.\n"
        "  -o --output file          : File for trace output, default is stderr.\n"
#endif
        "     --save                 : Save arguments in configuration file and exit.\n"
        "  -v --version              : Display version.\n"
        "  -h --help                 : Display this help message.\n"
        "\n";

    PStringArray descriptions =
#ifdef USE_OPAL
        MyManager::Descriptions();
#else
        MyH323EndPoint::Descriptions();
#endif

    for (PINDEX i = 0 ; i < descriptions.GetSize() ; i++)
      cout << descriptions[i] << endl;

    return FALSE;
  }

  PStringArray info =
#ifdef USE_OPAL
      MyManager::Descriptions(args);
#else
      MyH323EndPoint::Descriptions(args);
#endif

  if (info.GetSize() > 0) {
    for (PINDEX i = 0 ; i < info.GetSize() ; i++)
      cout << info[i] << endl;

    return FALSE;
  }

  if (args.HasOption('v'))
    return FALSE;

  if (args.HasOption("save")) {
    args.Save("save");
    cout << "Arguments were saved in configuration file" << endl;
    return FALSE;
  }

  PTRACE(1, GetName()
      << " Version " << GetVersion(TRUE)
      << " (" << GetListOfLibs() << ")"
      << " on " << GetOSClass() << " " << GetOSName()
      << " (" << GetOSVersion() << '-' << GetOSHardware() << ")");

#if PTRACING
  if (PTrace::CanTrace(3)) {
    PTRACE(3, "Options: " << args);

    const PConfig config;
    const PStringArray keys = config.GetKeys();

    if (!keys.IsEmpty()) {
      PTRACE(3, "Config:");
      for (PINDEX iK = 0 ; iK < keys.GetSize() ; iK++) {
        const PStringArray values = config.GetString(keys[iK]).Lines();

        for (PINDEX iV = 0 ; iV < values.GetSize() ; iV++) {
          PTRACE(3, "  --" << keys[iK] << "=" << values[iV]);
        }
      }
    }
  }
#endif

#ifdef USE_OPAL
  MyManager *manager = new MyManager();

  if (!manager->Initialise(args))
    return FALSE;
#else
  if (!MyH323EndPoint::Create(args))
    return FALSE;
#endif

  return TRUE;
}
/////////////////////////////////////////////////////////////////////////////