tizen 2.4 release
[framework/web/wrt-commons.git] / modules / rpc / include / dpl / rpc / abstract_rpc_connection.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  * @file        abstract_rpc_connection.h
18  * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version     1.0
20  * @brief       This file is the header file for abstract RPC connection
21  */
22 #ifndef DPL_ABSTRACT_RPC_CONNECTION_H
23 #define DPL_ABSTRACT_RPC_CONNECTION_H
24
25 #include <dpl/rpc/rpc_function.h>
26 #include <dpl/exception.h>
27 #include <dpl/generic_event.h>
28 #include <dpl/event/event_support.h>
29 #include <memory>
30 #include <string>
31
32 namespace DPL {
33 namespace RPC {
34 namespace AbstractRPCConnectionEvents {
35 /**
36  * Asynchronous call event
37  */
38 DECLARE_GENERIC_EVENT_1(AsyncCallEvent, RPCFunction)
39
40 /**
41  * Connection closed event
42  */
43 DECLARE_GENERIC_EVENT_0(ConnectionClosedEvent)
44
45 /**
46  * Connection broken event
47  */
48 DECLARE_GENERIC_EVENT_0(ConnectionBrokenEvent)
49 } // namespace AbstractRPCConnectionEvents
50
51 class AbstractRPCConnection :
52     public DPL::Event::EventSupport<AbstractRPCConnectionEvents::AsyncCallEvent>,
53     public DPL::Event::EventSupport<AbstractRPCConnectionEvents::
54                                         ConnectionClosedEvent>,
55     public DPL::Event::EventSupport<AbstractRPCConnectionEvents::
56                                         ConnectionBrokenEvent>
57 {
58   public:
59     class Exception
60     {
61       public:
62         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
63         DECLARE_EXCEPTION_TYPE(Base, AsyncCallFailed)
64         DECLARE_EXCEPTION_TYPE(Base, PingFailed)
65     };
66
67   public:
68     virtual ~AbstractRPCConnection() {}
69
70     /**
71      * Call asynchronously RPC function
72      *
73      * @param function COnstant reference to RPC function to call
74      * @return none
75      */
76     virtual void AsyncCall(const RPCFunction &function) = 0;
77
78     /**
79      * Ping RPC connection
80      * This will send a ping/pong packet over connection to ensure it is alive
81      * If any errors are to occur proper events will be emitted
82      *
83      * @return none
84      */
85     virtual void Ping() = 0;
86 };
87
88 /**
89  * Abstract connection ID used to represent connection being established
90  * or RPC server accepting connection
91  */
92 typedef void *AbstractRPCConnectionID;
93 }
94 } // namespace DPL
95
96 #endif // DPL_ABSTRACT_RPC_CONNECTION_H