Apply user space smack, step 1
[platform/core/connectivity/smartcard-service.git] / server / include / ClientInstance.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 CLIENTINSTANCE_H_
18 #define CLIENTINSTANCE_H_
19
20 /* standard library header */
21 #include <map>
22 #include <vector>
23 #ifndef USE_GDBUS
24 #include <glib.h>
25 #endif
26
27 /* SLP library header */
28
29 /* local header */
30 #include "Message.h"
31 #include "ServiceInstance.h"
32
33 namespace smartcard_service_api
34 {
35         class ClientInstance
36         {
37         private :
38 #ifdef USE_GDBUS
39                 string name;
40 #else
41                 void *ioChannel;
42                 int socket;
43                 int watchID;
44                 int state;
45 #endif
46                 pid_t pid;
47                 vector<ByteArray> certHashes;
48                 map<unsigned int, ServiceInstance *> mapServices;
49
50         public :
51 #ifdef USE_GDBUS
52                 ClientInstance(const char *name, pid_t pid) : name(name), pid(pid)
53                 {
54                 }
55 #else
56                 ClientInstance(void *ioChannel, int socket, int watchID,
57                         int state, int pid) : ioChannel(ioChannel),
58                         socket(socket), watchID(watchID), state(state), pid(pid)
59                 {
60                 }
61
62                 ClientInstance(pid_t pid) : ioChannel(NULL),
63                         socket(pid), watchID(0), state(0), pid(pid)
64                 {
65                 }
66 #endif
67                 ~ClientInstance() { removeServices(); }
68 #ifdef USE_GDBUS
69                 inline bool operator ==(const char *name) const { return (this->name.compare(name) == 0); }
70 #else
71                 inline bool operator ==(const int &socket) const { return (this->socket == socket); }
72 #endif
73
74 #ifndef USE_GDBUS
75                 inline void *getIOChannel() { return ioChannel; }
76                 inline int getSocket() { return socket; }
77                 inline int getWatchID() { return watchID; }
78                 inline int getState() { return state; }
79 #endif
80                 void setPID(int pid);
81                 inline int getPID() { return pid; }
82
83                 ServiceInstance *createService();
84                 ServiceInstance *getService(unsigned int handle);
85                 void removeService(unsigned int handle);
86                 void removeServices();
87                 inline size_t getServiceCounts() const { return mapServices.size(); }
88 #ifndef USE_GDBUS
89                 bool sendMessageToAllServices(int socket, const Message &msg);
90 #endif
91                 void generateCertificationHashes();
92
93                 inline vector<ByteArray> &getCertificationHashes() { return certHashes; }
94         };
95 } /* namespace smartcard_service_api */
96 #endif /* CLIENTINSTANCE_H_ */