Refactor slp-pkgmgr with tidl
[platform/core/appfw/slp-pkgmgr.git] / client / src / connection_event_listener.hh
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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 #ifndef CLIENT_SRC_CONNECTION_EVENT_LISTENER_H_
19 #define CLIENT_SRC_CONNECTION_EVENT_LISTENER_H_
20
21 #include <memory>
22 #include <string>
23
24 #include "PkgMgrProxy.h"
25
26 namespace pkgmgr {
27 namespace client {
28
29 enum class ConnectionState {
30   NotRequested,
31   Connected,
32   Disconnected,
33   Rejected,
34 };
35
36 template<class T>
37 class ConnectionEventListener : public T::IEventListener {
38  public:
39   void OnConnected() override {
40     state_ = ConnectionState::Connected;
41   }
42
43   void OnDisconnected() override {
44     state_ = ConnectionState::Disconnected;
45   }
46
47   void OnRejected() override {
48     state_ = ConnectionState::Rejected;
49   }
50
51   ConnectionState GetState() const {
52     return state_;
53   }
54
55  private:
56   ConnectionState state_ = ConnectionState::NotRequested;
57 };
58
59 }  // namespace client
60 }  // namespace pkgmgr
61
62 #endif  // CLIENT_SRC_CONNECTION_EVENT_LISTENER_H_