Add card Inserted implementation and fix bug
[platform/core/connectivity/smartcard-service.git] / server / include / ServerGDBus.h
1 /*
2  * Copyright (c) 2012, 2013 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 #ifndef SERVERGDBUS_H_
18 #define SERVERGDBUS_H_
19
20 /* standard library header */
21 #include <glib.h>
22 #include <queue>
23 #include <vector>
24
25 /* SLP library header */
26
27 /* local header */
28 #include "Synchronous.h"
29 #include "GDBusHelper.h"
30 #include "smartcard-service-gdbus.h"
31
32 using namespace std;
33
34 namespace smartcard_service_api
35 {
36         typedef void (*dispatcher_cb_t)(vector<void *> &params);
37
38         class GDBusDispatcher : public Synchronous
39         {
40         public :
41                 static GDBusDispatcher &getInstance();
42
43                 /* push to queue */
44                 static void push(dispatcher_cb_t cb, const vector<void *> &params);
45
46         private :
47                 std::queue<pair<dispatcher_cb_t, vector<void *> > > q;
48
49                 GDBusDispatcher();
50                 ~GDBusDispatcher();
51
52                 void _push(dispatcher_cb_t cb, const vector<void *> &params);
53                 static gboolean dispatch(gpointer user_data);
54         };
55
56         class ServerGDBus
57         {
58         public :
59                 GDBusProxy *dbus_proxy;
60
61                 static ServerGDBus &getInstance();
62
63                 bool init();
64                 void deinit();
65
66                 /* connect to dbus daemon */
67                 bool _init();
68                 void _deinit();
69                 pid_t getPID(const char *name);
70
71                 void emitReaderInserted(unsigned int reader_id,
72                         const char *reader_name);
73                 void emitReaderRemoved(unsigned int reader_id,
74                         const char *reader_name);
75                 void emitCardInserted(unsigned int reader_id,
76                         const char *reader_name);
77                 void emitCardRemoved(unsigned int reader_id,
78                         const char *reader_name);
79
80         private :
81                 GDBusConnection *connection;
82
83                 SmartcardServiceSeService *seService;
84                 SmartcardServiceReader *reader;
85                 SmartcardServiceSession *session;
86                 SmartcardServiceChannel *channel;
87
88                 ServerGDBus();
89                 ~ServerGDBus();
90
91                 bool initSEService();
92                 void deinitSEService();
93
94                 bool initReader();
95                 void deinitReader();
96
97                 bool initSession();
98                 void deinitSession();
99
100                 bool initChannel();
101                 void deinitChannel();
102         };
103 } /* namespace smartcard_service_api */
104
105 #endif /* SERVERGDBUS_H_ */