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.
22 * @author Pawel Misiak (p.misiak@samsung.com)
27 #ifndef MSGSERVICEHANDLEMGR_H
28 #define MSGSERVICEHANDLEMGR_H
30 #include <dpl/singleton.h>
31 #include <dpl/log/log.h>
32 #include <dpl/shared_ptr.h>
33 #include <dpl/thread.h>
34 #include <Commons/Exception.h>
45 * Class used for msg service handle manager
47 class MsgServiceHandleMgr
50 MsgServiceHandleMgr() : m_msgHandle(NULL)
53 // open one handle per all messaging
54 if (MSG_SUCCESS != msg_open_msg_handle(&m_msgHandle)) {
55 LogError("Unable to open handle");
56 Throw(WrtDeviceApis::Commons::PlatformException);
61 ~MsgServiceHandleMgr()
65 msg_close_msg_handle(&m_msgHandle);
69 msg_handle_t getHandle() const
72 LogError("Messaging handle not initialized");
73 Throw(WrtDeviceApis::Commons::PlatformException);
79 msg_handle_t m_msgHandle;
82 typedef DPL::SharedPtr<MsgServiceHandleMgr> MsgServiceHandleMgrPtr;
83 typedef DPL::ThreadLocalVariable<MsgServiceHandleMgrPtr> TlvMsgServiceHandleMgr;
85 class MsgServiceHandle
97 msg_handle_t getHandle()
99 if (m_tlvHandleMgr.IsNull()) {
100 m_tlvHandleMgr = MsgServiceHandleMgrPtr(new MsgServiceHandleMgr());
102 return (*m_tlvHandleMgr)->getHandle();
106 TlvMsgServiceHandleMgr m_tlvHandleMgr;
109 typedef DPL::Singleton<MsgServiceHandle> MsgServiceHandleSingleton;
111 #define MsgGetCommonHandle() MsgServiceHandleSingleton::Instance().getHandle()
115 #endif /* MSGSERVICEHANDLEMGR_H */