Tizen 2.1 base
[platform/framework/native/app-service.git] / inc / FApp_CommunicationDispatcher.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file         FApp_CommunicationDispatcher.h
20  * @brief       This is the header file of the _CommunicationDispatcher class.
21  *
22  * This header file contains the declarations of the _CommunicationDispatcher class.
23  */
24 #include <FApp.h>
25 #include <FBase.h>
26 #include <FIo.h>
27
28 #include <FApp_IAppManagerEventListener.h>
29 #include <FIo_IIpcServerEventListener.h>
30 #include "FApp_ICommunicationRequestListener.h"
31
32 #ifndef _FAPP_INTERNAL_COMMNUICATION_DISPATCHER_H_
33 #define _FAPP_INTERNAL_COMMNUICATION_DISPATCHER_H_
34
35 namespace Tizen { namespace App
36 {
37 class _AppManagerImpl;
38 }}
39
40 namespace Tizen { namespace Base
41 {
42 namespace Runtime
43 {
44 class Mutex;
45 }
46 }}
47
48 namespace Tizen { namespace Io
49 {
50 class _IpcServer;
51 }}
52
53 namespace Tizen { namespace App {
54
55 /**
56  * @class       _CommunicationDispatcher
57  * @brief       This class contains implementaion of communication feature for external application.
58  * @since 2.1
59  */
60 class _CommunicationDispatcher
61         : public Tizen::Io::_IIpcServerEventListener
62         , public _IAppManagerEventListener
63         , virtual public Tizen::Base::Runtime::IEventListener
64 {
65
66 public:
67         static _CommunicationDispatcher* GetInstance(void);
68
69         result AddCommunicationEventListener(Tizen::App::_ICommunicationRequestListener& listener);
70         result RemoveCommunicationEventListener(Tizen::App::_ICommunicationRequestListener& listener);
71
72         virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server) {}
73         virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server) {}
74         virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId) {}
75         virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer& server, int clientId) {}
76         virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
77
78         virtual void OnApplicationLaunched(const AppId& appId, _AppType type);
79         virtual void OnApplicationTerminated(const AppId& appId, _AppType type);
80
81         bool OnRequestOccured(const Tizen::Base::Collection::ArrayList& request, Tizen::Base::Collection::ArrayList* response);
82         result SendData(const Tizen::App::AppId appId, Tizen::Base::Collection::ArrayList& data);
83
84 private:
85         _CommunicationDispatcher(void);
86         virtual ~_CommunicationDispatcher(void);
87         Tizen::Base::Integer* GetClientId(const Tizen::App::AppId& appId, const Tizen::Base::String& componentId) const;
88         result AddClientId(Tizen::App::AppId appId, Tizen::Base::String componentId, Tizen::Base::Integer clientId);
89         result RemoveClientId(Tizen::App::AppId appId, Tizen::Base::String componentId, Tizen::Base::Integer clientId);
90         result RemoveClientId(Tizen::App::AppId appId, Tizen::Base::String componentId);
91         result RemoveClientId(Tizen::App::AppId appId);
92
93 private:
94         Tizen::Io::_IpcServer*                  __pIpcServer;
95         Tizen::Base::Collection::ArrayList*     __pRegisteredAppList;
96         Tizen::App::AppId                               __currentAppId;
97         Tizen::Base::Integer                    __currentClientId;
98         Tizen::Base::Runtime::Mutex             __Mutex;
99         _AppManagerImpl*                        __pAppManagerImpl;
100 };      //_CommunicationDispatcher
101
102 }} //Tizen::App
103 #endif /* _FAPP_INTERNAL_COMMNUICATION_DISPATCHER_H_ */