2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * @author Pawel Misiak (p.misiak@samsung.com)
25 #ifndef MSGSERVICEHANDLEMGR_H
26 #define MSGSERVICEHANDLEMGR_H
28 #include <dpl/singleton.h>
29 #include <dpl/log/log.h>
30 #include <dpl/shared_ptr.h>
31 #include <dpl/thread.h>
32 #include <Commons/Exception.h>
35 #include <MapiControl.h>
38 namespace WrtDeviceApis {
41 * Class used for msg service handle manager
43 class MsgServiceHandleMgr
46 MsgServiceHandleMgr() : m_msgHandle(NULL)
49 // open one handle per all messaging
50 if (MSG_SUCCESS != msg_open_msg_handle(&m_msgHandle)) {
51 LogError("Unable to open handle");
52 Throw(Commons::PlatformException);
57 ~MsgServiceHandleMgr()
61 msg_close_msg_handle(&m_msgHandle);
65 MSG_HANDLE_T getHandle() const
68 LogError("Messaging handle not initialized");
69 Throw(Commons::PlatformException);
75 MSG_HANDLE_T m_msgHandle;
78 typedef DPL::SharedPtr<MsgServiceHandleMgr> MsgServiceHandleMgrPtr;
79 typedef DPL::ThreadLocalVariable<MsgServiceHandleMgrPtr> TlvMsgServiceHandleMgr;
81 class MsgServiceHandle
93 MSG_HANDLE_T getHandle()
95 if (m_tlvHandleMgr.IsNull()) {
96 m_tlvHandleMgr = MsgServiceHandleMgrPtr(new MsgServiceHandleMgr());
98 return (*m_tlvHandleMgr)->getHandle();
102 TlvMsgServiceHandleMgr m_tlvHandleMgr;
105 typedef DPL::Singleton<MsgServiceHandle> MsgServiceHandleSingleton;
107 #define MsgGetCommonHandle() MsgServiceHandleSingleton::Instance().getHandle()
111 #endif /* MSGSERVICEHANDLEMGR_H */