1 /*
2 * Copyright 2008-2014 Arsen Chaloyan
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 * $Id: umcsession.h 2136 2014-07-04 06:33:36Z achaloyan@gmail.com $
17 */
18
19 #ifndef UMC_SESSION_H
20 #define UMC_SESSION_H
21
22 /**
23 * @file umcsession.h
24 * @brief UMC Session
25 */
26
27 #include "mrcp_application.h"
28
29 class UmcScenario;
30
31 class UmcSession
32 {
33 public:
34 /* ============================ CREATORS =================================== */
35 UmcSession(const UmcScenario* pScenario);
36 virtual ~UmcSession();
37
38 /* ============================ MANIPULATORS =============================== */
39 virtual bool Run();
40 virtual bool Stop();
41 virtual bool Terminate();
42
43 void SetMrcpProfile(const char* pMrcpProfile);
44 void SetMrcpApplication(mrcp_application_t* pMrcpApplication);
45
46 /* ============================ HANDLERS =================================== */
47 virtual bool OnSessionTerminate(mrcp_sig_status_code_e status);
48 virtual bool OnSessionUpdate(mrcp_sig_status_code_e status);
49 virtual bool OnChannelAdd(mrcp_channel_t *channel, mrcp_sig_status_code_e status);
50 virtual bool OnChannelRemove(mrcp_channel_t *channel, mrcp_sig_status_code_e status);
51 virtual bool OnMessageReceive(mrcp_channel_t *channel, mrcp_message_t *message);
52 virtual bool OnTerminateEvent(mrcp_channel_t *channel);
53 virtual bool OnResourceDiscover(mrcp_session_descriptor_t* descriptor, mrcp_sig_status_code_e status);
54
55 /* ============================ ACCESSORS ================================== */
56 const UmcScenario* GetScenario() const;
57
58 const char* GetId() const;
59
60 protected:
61 /* ============================ MANIPULATORS =============================== */
62 virtual bool Start() = 0;
63
64 bool CreateMrcpSession(const char* pProfileName);
65 bool DestroyMrcpSession();
66
67 bool AddMrcpChannel(mrcp_channel_t* pMrcpChannel);
68 bool RemoveMrcpChannel(mrcp_channel_t* pMrcpChannel);
69 bool SendMrcpRequest(mrcp_channel_t* pMrcpChannel, mrcp_message_t* pMrcpMessage);
70 bool ResourceDiscover();
71
72 mrcp_channel_t* CreateMrcpChannel(
73 mrcp_resource_id resource_id,
74 mpf_termination_t* pTermination,
75 mpf_rtp_termination_descriptor_t* pRtpDescriptor,
76 void* pObj);
77 mpf_termination_t* CreateAudioTermination(
78 const mpf_audio_stream_vtable_t* pStreamVtable,
79 mpf_stream_capabilities_t* pCapabilities,
80 void* pObj);
81 mrcp_message_t* CreateMrcpMessage(
82 mrcp_channel_t* pMrcpChannel,
83 mrcp_method_id method_id);
84
85 /* ============================ ACCESSORS ================================== */
86 apr_pool_t* GetSessionPool() const;
87 const char* GetMrcpSessionId() const;
88 mrcp_message_t* GetMrcpMessage() const;
89
90 /* ============================ DATA ======================================= */
91 const UmcScenario* m_pScenario;
92 const char* m_pMrcpProfile;
93 char m_Id[10];
94
95 private:
96 /* ============================ DATA ======================================= */
97 mrcp_application_t* m_pMrcpApplication;
98 mrcp_session_t* m_pMrcpSession;
99 mrcp_message_t* m_pMrcpMessage; /* last message sent */
100 bool m_Running;
101 bool m_Terminating;
102 };
103
104
105 /* ============================ INLINE METHODS ============================= */
GetScenario()106 inline const UmcScenario* UmcSession::GetScenario() const
107 {
108 return m_pScenario;
109 }
110
GetId()111 inline const char* UmcSession::GetId() const
112 {
113 return m_Id;
114 }
115
SetMrcpApplication(mrcp_application_t * pMrcpApplication)116 inline void UmcSession::SetMrcpApplication(mrcp_application_t* pMrcpApplication)
117 {
118 m_pMrcpApplication = pMrcpApplication;
119 }
120
SetMrcpProfile(const char * pMrcpProfile)121 inline void UmcSession::SetMrcpProfile(const char* pMrcpProfile)
122 {
123 m_pMrcpProfile = pMrcpProfile;
124 }
125
GetMrcpMessage()126 inline mrcp_message_t* UmcSession::GetMrcpMessage() const
127 {
128 return m_pMrcpMessage;
129 }
130
131 #endif /* UMC_SESSION_H */
132