update the latest source
[framework/system/smartcard-service.git] / server / include / ServerResource.h
1 /*
2 * Copyright (c) 2012 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
18 #ifndef SERVERRESOURCE_H_
19 #define SERVERRESOURCE_H_
20
21 /* standard library header */
22 #include <map>
23 #include <vector>
24 #include <set>
25
26 /* SLP library header */
27
28 /* local header */
29 #include "Terminal.h"
30 #include "Lock.h"
31 #include "ServerIPC.h"
32 #include "ServerDispatcher.h"
33 #include "ServerReader.h"
34 #include "ServerSession.h"
35 #include "ClientInstance.h"
36 #include "ServiceInstance.h"
37
38 using namespace std;
39
40 namespace smartcard_service_api
41 {
42         class IntegerHandle
43         {
44         private:
45                 static unsigned int newHandle;
46                 static set<unsigned int> setHandles;
47                 static PMutex mutexLock;
48
49         public:
50                 static const unsigned int INVALID_HANDLE = (unsigned int)-1;
51
52                 static unsigned int assignHandle();
53                 static void releaseHandle(unsigned int);
54         };
55
56         class ServerResource
57         {
58         private:
59                 /* non-static member */
60                 vector<void *> libraries;
61                 map<unsigned int, Terminal *> mapTerminals; /* unique id <-> terminal instance map */
62                 map<int, ClientInstance *> mapClients; /* client pid <-> client instance map */
63                 map<Terminal *, AccessControlList *> mapACL; /* terminal instance <-> access control instance map */
64
65                 ServerIPC *serverIPC;
66                 ServerDispatcher *serverDispatcher;
67
68                 ServerResource();
69                 ~ServerResource();
70
71                 Terminal *createInstance(void *library);
72                 bool appendSELibrary(char *library);
73                 void clearSELibraries();
74
75                 static void terminalCallback(void *terminal, int event, int error, void *user_param);
76
77         public:
78                 /* static member */
79                 static ServerResource &getInstance();
80
81                 /* non-static member */
82                 int loadSecureElements();
83                 void unloadSecureElements();
84
85                 Terminal *getTerminal(unsigned int terminalID);
86                 Terminal *getTerminal(const char *name);
87                 int getReadersInformation(ByteArray &info);
88                 bool isValidReaderHandle(unsigned int reader);
89
90                 bool createClient(void *ioChannel, int socket, int watchID, int state, int pid);
91                 ClientInstance *getClient(int socket);
92                 void setPID(int socket, int pid);
93                 void removeClient(int socket);
94                 void removeClients();
95
96                 bool createService(int socket, unsigned int context);
97                 ServiceInstance *getService(int socket, unsigned int context);
98                 void removeService(int socket, unsigned int context);
99                 void removeServices(int socket);
100
101                 unsigned int createSession(int socket, unsigned int context, unsigned int terminalID, ByteArray packageCert, void *caller);
102                 ServerSession *getSession(int socket, unsigned int context, unsigned int sessionID);
103                 unsigned int getChannelCount(int socket, unsigned int context, unsigned int sessionID);
104                 void removeSession(int socket, unsigned int context, unsigned int session);
105                 bool isValidSessionHandle(int socket, unsigned int context, unsigned int sessionID);
106
107                 unsigned int createChannel(int socket, unsigned int context, unsigned int sessionID, int channelType, ByteArray aid);
108                 Channel *getChannel(int socket, unsigned int context, unsigned int channelID);
109                 void removeChannel(int socket, unsigned int context, unsigned int channelID);
110
111                 AccessControlList *getAccessControlList(Terminal *terminal);
112
113                 bool sendMessageToAllClients(Message &msg);
114
115                 friend void terminalCallback(void *terminal, int event, int error, void *user_param);
116         };
117
118 } /* namespace smartcard_service_api */
119 #endif /* SERVERRESOURCE_H_ */