Minor fix
authorWonkyu Kwon <wonkyu.kwon@samsung.com>
Mon, 22 Jul 2013 06:38:18 +0000 (15:38 +0900)
committerWonkyu Kwon <wonkyu.kwon@samsung.com>
Wed, 24 Jul 2013 08:56:39 +0000 (17:56 +0900)
 - adjust exit function
 - adjust inline function

Change-Id: I9a7627f5c5d5d1087b90ad1f39659147b95cb96b

common/AccessControlList.cpp
server/ClientInstance.cpp
server/ServerGDBus.cpp
server/ServerResource.cpp
server/include/ClientInstance.h
server/include/ServerResource.h
server/include/smartcard-daemon.h [new file with mode: 0644]
server/smartcard-daemon.cpp

index 00c9984..0233360 100644 (file)
@@ -227,7 +227,7 @@ END :
                ByteArray temp;
                map<ByteArray, AccessCondition>::const_iterator iterMap;
 
-               _DBG("================ Access Control Rules ==================");
+               _DBG("========================== Access Control Rules ============================");
                for (iterMap = mapConditions.begin(); iterMap != mapConditions.end(); iterMap++)
                {
                        temp = iterMap->first;
@@ -236,7 +236,7 @@ END :
 
                        iterMap->second.printAccessConditions();
                }
-               _DBG("========================================================");
+               _DBG("============================================================================");
        }
 
 } /* namespace smartcard_service_api */
index 04f668f..d2dfcb9 100644 (file)
 
 namespace smartcard_service_api
 {
-       void ClientInstance::setPID(int pid)
-       {
-               this->pid = pid;
-       }
-
        ServiceInstance *ClientInstance::createService()
        {
                ServiceInstance *result = NULL;
index d075cdc..b74ed8e 100644 (file)
@@ -143,9 +143,7 @@ namespace smartcard_service_api
                                _INFO("terminated client, pid [%d]", client->getPID());
                                resource.removeClient(old_owner);
 
-                               if (resource.getClientCount() == 0) {
-                                       g_main_loop_quit((GMainLoop *)resource.getMainLoopInstance());
-                               }
+                               resource.finish();
                        }
                }
        }
@@ -482,11 +480,7 @@ namespace smartcard_service_api
                        invocation, SCARD_ERROR_OK);
 
                /* terminate */
-               if (resource.getClientCount() == 0) {
-                       _INFO("no client connected. terminate server");
-
-                       g_main_loop_quit((GMainLoop *)resource.getMainLoopInstance());
-               }
+               resource.finish();
 
                return true;
        }
index 172e496..7905e26 100644 (file)
@@ -34,6 +34,7 @@
 #ifdef USE_GDBUS
 #include "ServerGDBus.h"
 #endif
+#include "smartcard-daemon.h"
 
 #ifndef EXTERN_API
 #define EXTERN_API __attribute__((visibility("default")))
@@ -84,8 +85,7 @@ namespace smartcard_service_api
 
 #define OMAPI_SE_PATH "/usr/lib/se"
 
-       ServerResource::ServerResource()
-               : mainLoop(NULL), seLoaded(false)
+       ServerResource::ServerResource() : seLoaded(false)
        {
                _BEGIN();
 #ifndef USE_GDBUS
@@ -1532,11 +1532,13 @@ namespace smartcard_service_api
 
                return result;
        }
-} /* namespace smartcard_service_api */
 
-using namespace smartcard_service_api;
+       void ServerResource::finish()
+       {
+               if (getClientCount() == 0) {
+                       _INFO("no client connected. terminate server");
 
-EXTERN_API void server_resource_set_main_loop_instance(void *instance)
-{
-       ServerResource::getInstance().setMainLoopInstance(instance);
-}
+                       smartcard_daemon_exit();
+               }
+       }
+} /* namespace smartcard_service_api */
index 7c22d4e..f3952ea 100644 (file)
@@ -27,7 +27,9 @@
 /* SLP library header */
 
 /* local header */
+#ifndef USE_GDBUS
 #include "Message.h"
+#endif
 #include "ServiceInstance.h"
 
 namespace smartcard_service_api
@@ -49,7 +51,8 @@ namespace smartcard_service_api
 
        public :
 #ifdef USE_GDBUS
-               ClientInstance(const char *name, pid_t pid) : name(name), pid(pid)
+               ClientInstance(const char *name, pid_t pid) :
+                       name(name), pid(pid)
                {
                }
 #else
@@ -64,7 +67,7 @@ namespace smartcard_service_api
                {
                }
 #endif
-               ~ClientInstance() { removeServices(); }
+               inline ~ClientInstance() { removeServices(); }
 #ifdef USE_GDBUS
                inline bool operator ==(const char *name) const { return (this->name.compare(name) == 0); }
 #else
@@ -77,8 +80,8 @@ namespace smartcard_service_api
                inline int getWatchID() { return watchID; }
                inline int getState() { return state; }
 #endif
-               void setPID(int pid);
-               inline int getPID() { return pid; }
+               inline void setPID(int pid) { this->pid = pid; }
+               inline int getPID() const { return pid; }
 
                ServiceInstance *createService();
                ServiceInstance *getService(unsigned int handle);
index add3ccf..20f377c 100644 (file)
@@ -69,7 +69,6 @@ namespace smartcard_service_api
                map<int, ClientInstance *> mapClients; /* client pid <-> client instance map */
 #endif
                map<Terminal *, AccessControlList *> mapACL; /* terminal instance <-> access control instance map */
-               void *mainLoop;
 #ifndef USE_GDBUS
                ServerIPC *serverIPC;
                ServerDispatcher *serverDispatcher;
@@ -95,16 +94,6 @@ namespace smartcard_service_api
                /* static member */
                static ServerResource &getInstance();
 
-               /* non-static member */
-               inline void setMainLoopInstance(void *mainLoop)
-               {
-                       this->mainLoop = mainLoop;
-               }
-               inline void *getMainLoopInstance()
-               {
-                       return this->mainLoop;
-               }
-
                int loadSecureElements();
                void unloadSecureElements();
 
@@ -182,6 +171,8 @@ namespace smartcard_service_api
                bool isAuthorizedNFCAccess(Terminal *terminal, const ByteArray &aid,
                        const vector<ByteArray> &hashes);
 
+               void finish();
+
                friend void terminalCallback(void *terminal, int event, int error, void *user_param);
        };
 
diff --git a/server/include/smartcard-daemon.h b/server/include/smartcard-daemon.h
new file mode 100644 (file)
index 0000000..17cc583
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SMARTCARD_DAEMON_H_
+#define SMARTCARD_DAEMON_H_
+
+void smartcard_daemon_exit();
+
+#endif /* SMARTCARD_DAEMON_H_ */
index fcddf44..a8ddbd3 100644 (file)
@@ -107,7 +107,7 @@ static void _bus_acquired_cb(GDBusConnection *connection,
 {
        _DBG("bus path : %s", path);
 
-       ServerResource::getInstance().setMainLoopInstance(main_loop);
+       ServerResource::getInstance();
 
        ServerGDBus::getInstance().init();
 }
@@ -233,7 +233,7 @@ static void __sighandler(int sig)
 #endif
 }
 
-int main()
+int main(int argc, char *argv[])
 {
 #ifdef USE_GDBUS
        guint id = 0;
@@ -262,7 +262,6 @@ int main()
                        NULL,
                        NULL);
 #else
-       ServerResource::getInstance().setMainLoopInstance(main_loop);
        ServerIPC::getInstance()->createListenSocket();
 #ifdef USE_AUTOSTART
        _initialize_dbus();
@@ -283,3 +282,8 @@ int main()
 
        return 0;
 }
+
+void smartcard_daemon_exit()
+{
+       g_main_loop_quit(main_loop);
+}