2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef SERVERRESOURCE_H_
19 #define SERVERRESOURCE_H_
21 /* standard library header */
26 /* SLP library header */
31 #include "ServerIPC.h"
32 #include "ServerDispatcher.h"
33 #include "ServerReader.h"
34 #include "ServerSession.h"
35 #include "ClientInstance.h"
36 #include "ServiceInstance.h"
40 namespace smartcard_service_api
45 static unsigned int newHandle;
46 static set<unsigned int> setHandles;
47 static PMutex mutexLock;
50 static const unsigned int INVALID_HANDLE = (unsigned int)-1;
52 static unsigned int assignHandle();
53 static void releaseHandle(unsigned int);
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 */
66 ServerDispatcher *serverDispatcher;
71 Terminal *createInstance(void *library);
72 bool appendSELibrary(char *library);
73 void clearSELibraries();
75 static void terminalCallback(void *terminal, int event, int error, void *user_param);
79 static ServerResource &getInstance();
81 /* non-static member */
82 int loadSecureElements();
83 void unloadSecureElements();
85 Terminal *getTerminal(unsigned int terminalID);
86 Terminal *getTerminal(const char *name);
87 int getReadersInformation(ByteArray &info);
88 bool isValidReaderHandle(unsigned int reader);
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);
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);
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);
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);
111 AccessControlList *getAccessControlList(Terminal *terminal);
113 bool sendMessageToAllClients(Message &msg);
115 friend void terminalCallback(void *terminal, int event, int error, void *user_param);
118 } /* namespace smartcard_service_api */
119 #endif /* SERVERRESOURCE_H_ */