1 /*
2  * main.h
3  *
4  * OPAL call generator
5  *
6  * Copyright (c) 2007 Equivalence Pty. Ltd.
7  *
8  * The contents of this file are subject to the Mozilla Public License
9  * Version 1.0 (the "License"); you may not use this file except in
10  * compliance with the License. You may obtain a copy of the License at
11  * http://www.mozilla.org/MPL/
12  *
13  * Software distributed under the License is distributed on an "AS IS"
14  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
15  * the License for the specific language governing rights and limitations
16  * under the License.
17  *
18  * The Original Code is CallGen.
19  *
20  * Contributor(s): Equivalence Pty. Ltd.
21  *
22  * $Revision: 23928 $
23  * $Author: rjongbloed $
24  * $Date: 2010-01-13 00:12:37 -0600 (Wed, 13 Jan 2010) $
25  */
26 
27 
28 ///////////////////////////////////////////////////////////////////////////////
29 
30 class MyManager;
31 class CallThread;
32 
33 class MyCall : public OpalCall
34 {
35     PCLASSINFO(MyCall, OpalCall);
36   public:
37     MyCall(MyManager & manager, CallThread * caller);
38 
39     virtual void OnEstablishedCall();
40     virtual void OnReleased(OpalConnection & connection);
41     virtual PBoolean OnOpenMediaStream(OpalConnection & connection, OpalMediaStream & stream);
42     virtual void OnRTPStatistics(const OpalConnection & connection, const RTP_Session & session);
43 
44     MyManager          & manager;
45     unsigned             index;
46     PTime                openedTransmitMedia;
47     PTime                openedReceiveMedia;
48     PTime                receivedMedia;
49     OpalTransportAddress mediaGateway;
50 };
51 
52 
53 ///////////////////////////////////////////////////////////////////////////////
54 
55 class MyManager : public OpalManager
56 {
57     PCLASSINFO(MyManager, OpalManager);
58   public:
MyManager()59     MyManager()
60       { }
61 
62     virtual OpalCall * CreateCall(void * userData);
63 
64     virtual PBoolean OnOpenMediaStream(OpalConnection & connection, OpalMediaStream & stream);
65 
GetActiveCalls()66     PINDEX GetActiveCalls() const { return activeCalls.GetSize(); }
67 };
68 
69 
70 ///////////////////////////////////////////////////////////////////////////////
71 
72 class CallGen;
73 
74 struct CallParams
75 {
CallParamsCallParams76   CallParams(CallGen & app)
77     : callgen(app) { }
78 
79   CallGen & callgen;
80 
81   unsigned repeat;
82   PTimeInterval tmax_est;
83   PTimeInterval tmin_call;
84   PTimeInterval tmax_call;
85   PTimeInterval tmin_wait;
86   PTimeInterval tmax_wait;
87 };
88 
89 
90 ///////////////////////////////////////////////////////////////////////////////
91 
92 class CallThread : public PThread
93 {
94   PCLASSINFO(CallThread, PThread);
95   public:
96     CallThread(
97       unsigned index,
98       const PStringArray & destinations,
99       const CallParams & params
100     );
101     void Main();
102     void Stop();
103 
104     PStringArray destinations;
105     unsigned     index;
106     CallParams   params;
107     PSyncPoint   exit;
108 };
109 
110 PLIST(CallThreadList, CallThread);
111 
112 
113 ///////////////////////////////////////////////////////////////////////////////
114 
115 class CallGen : public PProcess
116 {
117   PCLASSINFO(CallGen, PProcess)
118 
119   public:
120     CallGen();
121     void Main();
Current()122     static CallGen & Current() { return (CallGen&)PProcess::Current(); }
123 
124     MyManager  manager;
125     PURL       m_outgoingMessageFile;
126     PString    incomingAudioDirectory;
127     PTextFile  cdrFile;
128 
129     PSyncPoint threadEnded;
130     unsigned   totalAttempts;
131     unsigned   totalEstablished;
132     bool       quietMode;
133     PMutex     coutMutex;
134 
135     PDECLARE_NOTIFIER(PThread, CallGen, Cancel);
136     PConsoleChannel console;
137     CallThreadList threadList;
138 };
139 
140 
141 ///////////////////////////////////////////////////////////////////////////////
142