Minor change
[platform/core/connectivity/smartcard-service.git] / client / include / SEService.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 SESERVICE_H_
18 #define SESERVICE_H_
19
20 /* standard library header */
21 #ifdef USE_GDBUS
22 #include <glib.h>
23 #include <gio/gio.h>
24 #endif
25
26 /* SLP library header */
27
28 /* local header */
29 #include "smartcard-types.h"
30 #ifdef __cplusplus
31 #include "SEServiceListener.h"
32 #include "SEServiceHelper.h"
33 #endif /* __cplusplus */
34
35 #ifdef __cplusplus
36 using namespace std;
37
38 namespace smartcard_service_api
39 {
40         typedef void (*serviceConnected)(SEServiceHelper *service, void *context);
41
42         class SEService : public SEServiceHelper
43         {
44         private:
45                 unsigned int handle;
46                 void *context;
47                 serviceConnected handler;
48                 SEServiceListener *listener;
49 #ifdef USE_GDBUS
50                 void *proxy;
51 #endif
52                 SEService();
53
54                 void addReader(unsigned int handle, const char *name);
55                 bool parseReaderInformation(unsigned int count, const ByteArray &data);
56 #ifdef USE_GDBUS
57                 bool parseReaderInformation(GVariant *variant);
58 #else
59                 static bool dispatcherCallback(void *message);
60 #endif
61
62                 bool _initialize()
63                         throw(ErrorIO &);
64                 bool initialize(void *context, serviceConnected handler)
65                         throw(ErrorIO &, ErrorIllegalParameter &);
66                 bool initialize(void *context, SEServiceListener *listener)
67                         throw(ErrorIO &, ErrorIllegalParameter &);
68                 SEService *initializeSync(void *context, serviceConnected handler)
69                         throw(ErrorIO &, ErrorIllegalParameter &);
70
71 #ifdef USE_GDBUS
72                 static void reader_inserted(GObject *source_object,
73                         guint reader_id, gchar *reader_name,
74                         gpointer user_data);
75                 static void reader_removed(GObject *source_object,
76                         guint reader_id, gchar *reader_name,
77                         gpointer user_data);
78                 static void se_service_shutdown_cb(GObject *source_object,
79                         GAsyncResult *res, gpointer user_data);
80                 static void se_service_cb(GObject *source_object,
81                         GAsyncResult *res, gpointer user_data);
82 #endif
83         public:
84                 SEService(void *user_data, serviceConnected handler)
85                         throw(ErrorIO &, ErrorIllegalParameter &);
86                 SEService(void *user_data, SEServiceListener *listener)
87                         throw(ErrorIO &, ErrorIllegalParameter &);
88                 ~SEService();
89
90                 static SEService *createInstance(void *user_data, SEServiceListener *listener)
91                         throw(ErrorIO &, ErrorIllegalParameter &);
92                 static SEService *createInstance(void *user_data, serviceConnected handler)
93                         throw(ErrorIO &, ErrorIllegalParameter &);
94
95                 void shutdown();
96                 void shutdownSync();
97
98 #ifndef USE_GDBUS
99                 friend class ClientDispatcher;
100 #endif
101         };
102 } /* namespace smartcard_service_api */
103 #endif /* __cplusplus */
104
105 /* export C API */
106 #ifdef __cplusplus
107 extern "C"
108 {
109 #endif /* __cplusplus */
110
111 se_service_h se_service_create_instance(void *user_data, se_service_connected_cb callback);
112 se_service_h se_service_create_instance_with_event_callback(void *user_data,
113         se_service_connected_cb connected, se_service_event_cb event, se_sesrvice_error_cb error);
114 int se_service_get_readers_count(se_service_h handle);
115 bool se_service_get_readers(se_service_h handle, reader_h *readers, int *count);
116 bool se_service_is_connected(se_service_h handle);
117 void se_service_shutdown(se_service_h handle);
118 void se_service_destroy_instance(se_service_h handle);
119
120 #ifdef __cplusplus
121 }
122 #endif /* __cplusplus */
123
124 #endif /* SESERVICE_H_ */