Add new feature and 2 enum values for USB secure element
[platform/core/api/smartcard.git] / src / Session.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 5089a4b..266ee61
 /* SLP library header */
 
 /* local header */
-#include "Debug.h"
+#include "smartcard_debug.h"
 #include "Session.h"
 #include "Reader.h"
 #include "ClientChannel.h"
 #include "ClientGDBus.h"
 
+/* LCOV_EXCL_START */
+
 #ifndef EXTERN_API
 #define EXTERN_API __attribute__((visibility("default")))
 #endif
@@ -60,8 +62,10 @@ namespace smartcard_service_api
                        NULL, &error);
                if (proxy == NULL)
                {
-                       _ERR("Can not create proxy : %s", error->message);
-                       g_error_free(error);
+                       if (error != NULL) {
+                               _ERR("Can not create proxy : %s", error->message);
+                               g_error_free(error);
+                       }
                        return;
                }
 
@@ -82,7 +86,7 @@ namespace smartcard_service_api
                channels.clear();
        }
 
-       void Session::closeChannels() throw(ErrorIO &, ErrorIllegalState &)
+       void Session::closeChannels()
        {
                size_t i;
 
@@ -124,8 +128,10 @@ namespace smartcard_service_api
                                _ERR("smartcard_service_session_call_get_atr failed, [%d]", result);
                        }
                } else {
-                       _ERR("smartcard_service_session_call_get_atr failed, [%s]", error->message);
-                       g_error_free(error);
+                       if (error != NULL) {
+                               _ERR("smartcard_service_session_call_get_atr failed, [%s]", error->message);
+                               g_error_free(error);
+                       }
 
                        result = SCARD_ERROR_IPC_FAILED;
                }
@@ -172,7 +178,7 @@ namespace smartcard_service_api
                                        var_response, response);
 
                                /* create new instance of channel */
-                               channel = new ClientChannel(session->context,
+                               channel = new (std::nothrow)ClientChannel(session->context,
                                        session, channel_id,
                                        response, GUINT_TO_POINTER(channel_id));
                                if (channel != NULL) {
@@ -186,8 +192,10 @@ namespace smartcard_service_api
                                _ERR("smartcard_service_session_call_open_channel failed, [%d]", result);
                        }
                } else {
-                       _ERR("smartcard_service_session_call_open_channel failed, [%s]", error->message);
-                       g_error_free(error);
+                       if (error != NULL) {
+                               _ERR("smartcard_service_session_call_open_channel failed, [%s]", error->message);
+                               g_error_free(error);
+                       }
 
                        result = SCARD_ERROR_IPC_FAILED;
                }
@@ -227,8 +235,10 @@ namespace smartcard_service_api
                                _ERR("smartcard_service_session_call_close_session failed, [%d]", result);
                        }
                } else {
-                       _ERR("smartcard_service_session_call_close_session failed, [%s]", error->message);
-                       g_error_free(error);
+                       if (error != NULL) {
+                               _ERR("smartcard_service_session_call_close_session failed, [%s]", error->message);
+                               g_error_free(error);
+                       }
 
                        result = SCARD_ERROR_IPC_FAILED;
                }
@@ -241,8 +251,6 @@ namespace smartcard_service_api
        }
 
        const ByteArray Session::getATRSync()
-               throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
-                       ErrorIllegalState &, ErrorIllegalParameter &)
        {
                ByteArray result;
 
@@ -268,8 +276,10 @@ namespace smartcard_service_api
                                                THROW_ERROR(ret);
                                        }
                                } else {
-                                       _ERR("smartcard_service_session_call_get_atr_sync failed, [%s]", error->message);
-                                       g_error_free(error);
+                                       if (error != NULL) {
+                                               _ERR("smartcard_service_session_call_get_atr_sync failed, [%s]", error->message);
+                                               g_error_free(error);
+                                       }
 
                                        THROW_ERROR(SCARD_ERROR_IPC_FAILED);
                                }
@@ -290,7 +300,7 @@ namespace smartcard_service_api
 
                if (getReader()->isSecureElementPresent() == true) {
                        if (atr.isEmpty() == true) {
-                               CallbackParam *param = new CallbackParam();
+                               CallbackParam *param = new (std::nothrow)CallbackParam();
 
                                param->instance = this;
                                param->callback = (void *)callback;
@@ -319,8 +329,6 @@ namespace smartcard_service_api
        }
 
        void Session::closeSync()
-               throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
-                       ErrorIllegalState &, ErrorIllegalParameter &)
        {
                if (isClosed() == false)
                {
@@ -343,8 +351,10 @@ namespace smartcard_service_api
                                        THROW_ERROR(ret);
                                }
                        } else {
-                               _ERR("smartcard_service_session_call_get_atr_sync failed, [%s]", error->message);
-                               g_error_free(error);
+                               if (error != NULL) {
+                                       _ERR("smartcard_service_session_call_get_atr_sync failed, [%s]", error->message);
+                                       g_error_free(error);
+                               }
 
                                THROW_ERROR(SCARD_ERROR_IPC_FAILED);
                        }
@@ -360,7 +370,7 @@ namespace smartcard_service_api
                        closed = true;
                        closeChannels();
 
-                       CallbackParam *param = new CallbackParam();
+                       CallbackParam *param = new (std::nothrow)CallbackParam();
 
                        param->instance = this;
                        param->callback = (void *)callback;
@@ -390,15 +400,11 @@ namespace smartcard_service_api
                return count;
        }
        Channel *Session::openChannelSync(int id, const ByteArray &aid)
-               throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
-                       ErrorIllegalParameter &, ErrorSecurity &)
        {
                return openChannelSync(id, aid, 0x00);
        }
 
        Channel *Session::openChannelSync(int id, const ByteArray &aid, unsigned char P2)
-               throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
-                       ErrorIllegalParameter &, ErrorSecurity &)
        {
                Channel *channel = NULL;
 
@@ -424,7 +430,7 @@ namespace smartcard_service_api
                                                var_response, response);
 
                                        /* create new instance of channel */
-                                       channel = new ClientChannel(context,
+                                       channel = new (std::nothrow)ClientChannel(context,
                                                this, channel_number,
                                                response, GUINT_TO_POINTER(channel_id));
                                        if (channel != NULL) {
@@ -440,8 +446,10 @@ namespace smartcard_service_api
                                        THROW_ERROR(ret);
                                }
                        } else {
-                               _ERR("smartcard_service_session_call_open_channel_sync failed, [%s]", error->message);
-                               g_error_free(error);
+                               if (error != NULL) {
+                                       _ERR("smartcard_service_session_call_open_channel_sync failed, [%s]", error->message);
+                                       g_error_free(error);
+                               }
 
                                THROW_ERROR(SCARD_ERROR_IPC_FAILED);
                        }
@@ -461,7 +469,7 @@ namespace smartcard_service_api
                if (getReader()->isSecureElementPresent() == true) {
                        GVariant *var_aid;
 
-                       CallbackParam *param = new CallbackParam();
+                       CallbackParam *param = new (std::nothrow)CallbackParam();
 
                        param->instance = this;
                        param->callback = (void *)callback;
@@ -486,22 +494,16 @@ namespace smartcard_service_api
        }
 
        Channel *Session::openBasicChannelSync(const ByteArray &aid)
-               throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
-                       ErrorIllegalParameter &, ErrorSecurity &)
        {
                return openChannelSync(0, aid, 0x00);
        }
 
        Channel *Session::openBasicChannelSync(const ByteArray &aid, unsigned char P2)
-               throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
-                       ErrorIllegalParameter &, ErrorSecurity &)
        {
                return openChannelSync(0, aid, P2);
        }
 
        Channel *Session::openBasicChannelSync(const unsigned char *aid, unsigned int length)
-               throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
-                       ErrorIllegalParameter &, ErrorSecurity &)
        {
                ByteArray temp(aid, length);
 
@@ -509,8 +511,6 @@ namespace smartcard_service_api
        }
 
        Channel *Session::openBasicChannelSync(const unsigned char *aid, unsigned int length, unsigned char P2)
-               throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
-                       ErrorIllegalParameter &, ErrorSecurity &)
        {
                ByteArray temp(aid, length);
 
@@ -531,22 +531,16 @@ namespace smartcard_service_api
        }
 
        Channel *Session::openLogicalChannelSync(const ByteArray &aid)
-               throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
-                       ErrorIllegalParameter &, ErrorSecurity &)
        {
                return openChannelSync(1, aid, 0x00);
        }
 
        Channel *Session::openLogicalChannelSync(const ByteArray &aid, unsigned char P2)
-               throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
-                       ErrorIllegalParameter &, ErrorSecurity &)
        {
                return openChannelSync(1, aid, P2);
        }
 
        Channel *Session::openLogicalChannelSync(const unsigned char *aid, unsigned int length)
-               throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
-                       ErrorIllegalParameter &, ErrorSecurity &)
        {
                ByteArray temp(aid, length);
 
@@ -554,8 +548,6 @@ namespace smartcard_service_api
        }
 
        Channel *Session::openLogicalChannelSync(const unsigned char *aid, unsigned int length, unsigned char P2)
-               throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
-                       ErrorIllegalParameter &, ErrorSecurity &)
        {
                ByteArray temp(aid, length);
 
@@ -866,3 +858,5 @@ EXTERN_API void session_destroy_instance(session_h handle)
 {
 }
 
+/* LCOV_EXCL_STOP */
+