00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 #ifndef __OPAL_H323NEG_H
00172 #define __OPAL_H323NEG_H
00173
00174 #ifdef P_USE_PRAGMA
00175 #pragma interface
00176 #endif
00177
00178
00179 #include <h323/h323pdu.h>
00180 #include <h323/channels.h>
00181
00182
00183 class H323EndPoint;
00184 class H323Connection;
00185
00186
00188
00191 class H245Negotiator : public PObject
00192 {
00193 PCLASSINFO(H245Negotiator, PObject);
00194
00195 public:
00196 H245Negotiator(H323EndPoint & endpoint, H323Connection & connection);
00197
00198 protected:
00199 PDECLARE_NOTIFIER(PTimer, H245Negotiator, HandleTimeout);
00200
00201 H323EndPoint & endpoint;
00202 H323Connection & connection;
00203 PTimer replyTimer;
00204 PMutex mutex;
00205 };
00206
00207
00210 class H245NegMasterSlaveDetermination : public H245Negotiator
00211 {
00212 PCLASSINFO(H245NegMasterSlaveDetermination, H245Negotiator);
00213
00214 public:
00215 H245NegMasterSlaveDetermination(H323EndPoint & endpoint, H323Connection & connection);
00216
00217 BOOL Start(BOOL renegotiate);
00218 void Stop();
00219 BOOL HandleIncoming(const H245_MasterSlaveDetermination & pdu);
00220 BOOL HandleAck(const H245_MasterSlaveDeterminationAck & pdu);
00221 BOOL HandleReject(const H245_MasterSlaveDeterminationReject & pdu);
00222 BOOL HandleRelease(const H245_MasterSlaveDeterminationRelease & pdu);
00223 void HandleTimeout(PTimer &, INT);
00224
00225 BOOL IsMaster() const { return status == e_DeterminedMaster; }
00226 BOOL IsDetermined() const { return state == e_Idle && status != e_Indeterminate; }
00227
00228 protected:
00229 BOOL Restart();
00230
00231 enum States {
00232 e_Idle, e_Outgoing, e_Incoming,
00233 e_NumStates
00234 } state;
00235 #if PTRACING
00236 static const char * GetStateName(States s);
00237 friend ostream & operator<<(ostream & o, States s) { return o << GetStateName(s); }
00238 #endif
00239
00240 DWORD determinationNumber;
00241 unsigned retryCount;
00242
00243 enum MasterSlaveStatus {
00244 e_Indeterminate, e_DeterminedMaster, e_DeterminedSlave,
00245 e_NumStatuses
00246 } status;
00247 #if PTRACING
00248 static const char * GetStatusName(MasterSlaveStatus s);
00249 friend ostream & operator<<(ostream & o , MasterSlaveStatus s) { return o << GetStatusName(s); }
00250 #endif
00251 };
00252
00253
00256 class H245NegTerminalCapabilitySet : public H245Negotiator
00257 {
00258 PCLASSINFO(H245NegTerminalCapabilitySet, H245Negotiator);
00259
00260 public:
00261 H245NegTerminalCapabilitySet(H323EndPoint & endpoint, H323Connection & connection);
00262
00263 BOOL Start(BOOL renegotiate, BOOL empty = FALSE);
00264 void Stop(BOOL dec = FALSE);
00265 BOOL HandleIncoming(const H245_TerminalCapabilitySet & pdu);
00266 BOOL HandleAck(const H245_TerminalCapabilitySetAck & pdu);
00267 BOOL HandleReject(const H245_TerminalCapabilitySetReject & pdu);
00268 BOOL HandleRelease(const H245_TerminalCapabilitySetRelease & pdu);
00269 void HandleTimeout(PTimer &, INT);
00270
00271 BOOL HasSentCapabilities() const { return state == e_Sent; }
00272 BOOL HasReceivedCapabilities() const { return receivedCapabilites; }
00273
00274 protected:
00275 enum States {
00276 e_Idle, e_InProgress, e_Sent,
00277 e_NumStates
00278 } state;
00279 #if PTRACING
00280 static const char * GetStateName(States s);
00281 friend ostream & operator<<(ostream & o, States s) { return o << GetStateName(s); }
00282 #endif
00283
00284 unsigned inSequenceNumber;
00285 unsigned outSequenceNumber;
00286
00287 BOOL receivedCapabilites;
00288 };
00289
00290
00293 class H245NegLogicalChannel : public H245Negotiator
00294 {
00295 PCLASSINFO(H245NegLogicalChannel, H245Negotiator);
00296
00297 public:
00298 H245NegLogicalChannel(H323EndPoint & endpoint,
00299 H323Connection & connection,
00300 const H323ChannelNumber & channelNumber);
00301 H245NegLogicalChannel(H323EndPoint & endpoint,
00302 H323Connection & connection,
00303 H323Channel & channel);
00304 ~H245NegLogicalChannel();
00305
00306 virtual BOOL Open(
00307 const H323Capability & capability,
00308 unsigned sessionID,
00309 unsigned replacementFor = 0
00310 );
00311 virtual BOOL Close();
00312 virtual BOOL HandleOpen(const H245_OpenLogicalChannel & pdu);
00313 virtual BOOL HandleOpenAck(const H245_OpenLogicalChannelAck & pdu);
00314 virtual BOOL HandleOpenConfirm(const H245_OpenLogicalChannelConfirm & pdu);
00315 virtual BOOL HandleReject(const H245_OpenLogicalChannelReject & pdu);
00316 virtual BOOL HandleClose(const H245_CloseLogicalChannel & pdu);
00317 virtual BOOL HandleCloseAck(const H245_CloseLogicalChannelAck & pdu);
00318 virtual BOOL HandleRequestClose(const H245_RequestChannelClose & pdu);
00319 virtual BOOL HandleRequestCloseAck(const H245_RequestChannelCloseAck & pdu);
00320 virtual BOOL HandleRequestCloseReject(const H245_RequestChannelCloseReject & pdu);
00321 virtual BOOL HandleRequestCloseRelease(const H245_RequestChannelCloseRelease & pdu);
00322 virtual void HandleTimeout(PTimer &, INT);
00323
00324 H323Channel * GetChannel();
00325
00326
00327 protected:
00328 virtual BOOL OpenWhileLocked(
00329 const H323Capability & capability,
00330 unsigned sessionID,
00331 unsigned replacementFor = 0
00332 );
00333 virtual BOOL CloseWhileLocked();
00334 virtual void Release();
00335
00336
00337 H323Channel * channel;
00338
00339 H323ChannelNumber channelNumber;
00340
00341 enum States {
00342 e_Released,
00343 e_AwaitingEstablishment,
00344 e_Established,
00345 e_AwaitingRelease,
00346 e_AwaitingConfirmation,
00347 e_AwaitingResponse,
00348 e_NumStates
00349 } state;
00350 #if PTRACING
00351 static const char * GetStateName(States s);
00352 friend ostream & operator<<(ostream & o, States s) { return o << GetStateName(s); }
00353 #endif
00354
00355
00356 friend class H245NegLogicalChannels;
00357 };
00358
00359
00360 PDICTIONARY(H245LogicalChannelDict, H323ChannelNumber, H245NegLogicalChannel);
00361
00364 class H245NegLogicalChannels : public H245Negotiator
00365 {
00366 PCLASSINFO(H245NegLogicalChannels, H245Negotiator);
00367
00368 public:
00369 H245NegLogicalChannels(H323EndPoint & endpoint, H323Connection & connection);
00370
00371 virtual void Add(H323Channel & channel);
00372
00373 virtual BOOL Open(
00374 const H323Capability & capability,
00375 unsigned sessionID,
00376 unsigned replacementFor = 0
00377 );
00378 virtual BOOL Close(unsigned channelNumber, BOOL fromRemote);
00379 virtual BOOL HandleOpen(const H245_OpenLogicalChannel & pdu);
00380 virtual BOOL HandleOpenAck(const H245_OpenLogicalChannelAck & pdu);
00381 virtual BOOL HandleOpenConfirm(const H245_OpenLogicalChannelConfirm & pdu);
00382 virtual BOOL HandleReject(const H245_OpenLogicalChannelReject & pdu);
00383 virtual BOOL HandleClose(const H245_CloseLogicalChannel & pdu);
00384 virtual BOOL HandleCloseAck(const H245_CloseLogicalChannelAck & pdu);
00385 virtual BOOL HandleRequestClose(const H245_RequestChannelClose & pdu);
00386 virtual BOOL HandleRequestCloseAck(const H245_RequestChannelCloseAck & pdu);
00387 virtual BOOL HandleRequestCloseReject(const H245_RequestChannelCloseReject & pdu);
00388 virtual BOOL HandleRequestCloseRelease(const H245_RequestChannelCloseRelease & pdu);
00389
00390 H323ChannelNumber GetNextChannelNumber();
00391 PINDEX GetSize() const { return channels.GetSize(); }
00392 H323Channel * GetChannelAt(PINDEX i);
00393 H323Channel * FindChannel(unsigned channelNumber, BOOL fromRemote);
00394 H245NegLogicalChannel & GetNegLogicalChannelAt(PINDEX i);
00395 H245NegLogicalChannel * FindNegLogicalChannel(unsigned channelNumber, BOOL fromRemote);
00396 H323Channel * FindChannelBySession(unsigned rtpSessionId, BOOL fromRemote);
00397 void RemoveAll();
00398
00399 protected:
00400 H323ChannelNumber lastChannelNumber;
00401 H245LogicalChannelDict channels;
00402 };
00403
00404
00407 class H245NegRequestMode : public H245Negotiator
00408 {
00409 PCLASSINFO(H245NegRequestMode, H245Negotiator);
00410
00411 public:
00412 H245NegRequestMode(H323EndPoint & endpoint, H323Connection & connection);
00413
00414 virtual BOOL StartRequest(const PString & newModes);
00415 virtual BOOL StartRequest(const H245_ArrayOf_ModeDescription & newModes);
00416 virtual BOOL HandleRequest(const H245_RequestMode & pdu);
00417 virtual BOOL HandleAck(const H245_RequestModeAck & pdu);
00418 virtual BOOL HandleReject(const H245_RequestModeReject & pdu);
00419 virtual BOOL HandleRelease(const H245_RequestModeRelease & pdu);
00420 virtual void HandleTimeout(PTimer &, INT);
00421
00422 protected:
00423 BOOL awaitingResponse;
00424 unsigned inSequenceNumber;
00425 unsigned outSequenceNumber;
00426 };
00427
00428
00431 class H245NegRoundTripDelay : public H245Negotiator
00432 {
00433 PCLASSINFO(H245NegRoundTripDelay, H245Negotiator);
00434
00435 public:
00436 H245NegRoundTripDelay(H323EndPoint & endpoint, H323Connection & connection);
00437
00438 BOOL StartRequest();
00439 BOOL HandleRequest(const H245_RoundTripDelayRequest & pdu);
00440 BOOL HandleResponse(const H245_RoundTripDelayResponse & pdu);
00441 void HandleTimeout(PTimer &, INT);
00442
00443 PTimeInterval GetRoundTripDelay() const { return roundTripTime; }
00444 BOOL IsRemoteOffline() const { return retryCount == 0; }
00445
00446 protected:
00447 BOOL awaitingResponse;
00448 unsigned sequenceNumber;
00449 PTimeInterval tripStartTime;
00450 PTimeInterval roundTripTime;
00451 unsigned retryCount;
00452 };
00453
00454
00455 #endif // __OPAL_H323NEG_H
00456
00457