6198e79e3c7fc2ebd1c9d730b071e780cabb6ed3
[framework/web/wrt-plugins-common.git] / src / modules / tizen / Messaging / CallbackMgr.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 /**
17  *
18  *
19  * @file       CallbackMgr.h
20  * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
21  * @version    0.1
22  * @brief
23  */
24
25 #ifndef CALLBACKMGR_H_
26 #define CALLBACKMGR_H_
27
28 #include <map>
29 #include <dpl/singleton.h>
30 #include <dpl/mutex.h>
31
32 extern "C" {
33 #include <MsgTypes.h>
34 #include <MsgTransportTypes.h>
35 }
36
37 namespace WrtDeviceApis {
38 namespace Messaging {
39 class ISendingObserver;
40
41 /*
42  *
43  */
44 class CallbackMgr
45 {
46   protected:
47     CallbackMgr();
48
49     static void sendCallback(MSG_HANDLE_T handle,
50             MSG_SENT_STATUS_S *sent_status,
51             void *user_param);
52
53     void call(MSG_SENT_STATUS_S *sent_status);
54
55   public:
56     ~CallbackMgr();
57
58     typedef int (*SendingFunction)(MSG_HANDLE_T, MSG_REQUEST_S*);
59
60     // register for sending callback
61     MSG_ERROR_T registerAndSend(SendingFunction sendingFn,
62             const msg_message_t& message,
63             ISendingObserver* observer);
64
65     // unregister callback
66     void unregister(int reqId);
67
68   private:
69     DPL::Mutex m_mutex;
70
71     typedef std::map<MSG_REQUEST_ID_T, ISendingObserver*> SendReqMap;
72     SendReqMap m_sendRequests;
73 };
74
75 typedef DPL::Singleton<CallbackMgr> CallbackMgrSingleton;
76 }
77 }
78
79 #endif /* CALLBACKMGR_H_ */