tizen beta 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 {
34 namespace RPC
35 {
36 namespace AbstractRPCConnectionEvents
37 {
38 /**
39  * Asynchronous call event
40  */
41 DECLARE_GENERIC_EVENT_1(AsyncCallEvent, RPCFunction)
42
43 /**
44  * Connection closed event
45  */
46 DECLARE_GENERIC_EVENT_0(ConnectionClosedEvent)
47
48 /**
49  * Connection broken event
50  */
51 DECLARE_GENERIC_EVENT_0(ConnectionBrokenEvent)
52 } // namespace AbstractRPCConnectionEvents
53
54 class AbstractRPCConnection
55     : public DPL::Event::EventSupport<AbstractRPCConnectionEvents::AsyncCallEvent>,
56       public DPL::Event::EventSupport<AbstractRPCConnectionEvents::ConnectionClosedEvent>,
57       public DPL::Event::EventSupport<AbstractRPCConnectionEvents::ConnectionBrokenEvent>
58 {
59 public:
60     class Exception
61     {
62     public:
63         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
64         DECLARE_EXCEPTION_TYPE(Base, AsyncCallFailed)
65         DECLARE_EXCEPTION_TYPE(Base, PingFailed)
66     };
67
68 public:
69     virtual ~AbstractRPCConnection() {}
70
71     /**
72      * Call asynchronously RPC function
73      *
74      * @param function COnstant reference to RPC function to call
75      * @return none
76      */
77     virtual void AsyncCall(const RPCFunction &function) = 0;
78
79     /**
80      * Ping RPC connection
81      * This will send a ping/pong packet over connection to ensure it is alive
82      * If any errors are to occur proper events will be emitted
83      *
84      * @return none
85      */
86     virtual void Ping() = 0;
87 };
88
89 /**
90  * Abstract connection ID used to represent connection being established
91  * or RPC server accepting connection
92  */
93 typedef void *AbstractRPCConnectionID;
94
95 }
96 } // namespace DPL
97
98 #endif // DPL_ABSTRACT_RPC_CONNECTION_H