#include <stdlib.h>
#include <unistd.h>
#include <string.h>
-#ifdef USE_GDBUS
#include <glib.h>
-#endif
/* SLP library header */
#include "ClientChannel.h"
#include "ReaderHelper.h"
#include "APDUHelper.h"
-#ifdef USE_GDBUS
#include "ClientGDBus.h"
-#else
-#include "Message.h"
-#include "ClientIPC.h"
-#endif
#ifndef EXTERN_API
#define EXTERN_API __attribute__((visibility("default")))
this->handle = handle;
this->selectResponse = selectResponse;
this->context = context;
-#ifdef USE_GDBUS
- /* initialize client */
- if (!g_thread_supported())
- {
- g_thread_init(NULL);
- }
-
- g_type_init();
/* init default context */
GError *error = NULL;
g_error_free(error);
return;
}
-#endif
}
ClientChannel::~ClientChannel()
closeSync();
}
-#ifdef USE_GDBUS
void ClientChannel::channel_transmit_cb(GObject *source_object,
GAsyncResult *res, gpointer user_data)
{
delete param;
}
-#endif
+
void ClientChannel::closeSync()
throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
ErrorIllegalState &, ErrorIllegalParameter &)
{
if (getSession()->getReader()->isSecureElementPresent() == true)
{
-#ifdef USE_GDBUS
gint ret;
GError *error = NULL;
if (smartcard_service_channel_call_close_channel_sync(
(SmartcardServiceChannel *)proxy,
- ClientGDBus::getCookie(),
GPOINTER_TO_UINT(context),
GPOINTER_TO_UINT(handle),
&ret, NULL, &error) == true) {
throw ErrorIO(SCARD_ERROR_IPC_FAILED);
}
-#else
- Message msg;
- int rv;
-
-#ifdef CLIENT_IPC_THREAD
- /* send message to server */
- msg.message = Message::MSG_REQUEST_CLOSE_CHANNEL;
- msg.param1 = (unsigned long)handle;
- msg.error = (unsigned long)context; /* using error to context */
- msg.caller = (void *)this;
- msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
-
- syncLock();
- if (ClientIPC::getInstance().sendMessage(msg) == true)
- {
- rv = waitTimedCondition(0);
- if (rv < 0)
- {
- _ERR("timeout [%d]", rv);
- this->error = SCARD_ERROR_OPERATION_TIMEOUT;
- }
- }
- else
- {
- _ERR("sendMessage failed");
- this->error = SCARD_ERROR_IPC_FAILED;
- }
- syncUnlock();
-
- channelNum = -1;
-
- if (this->error != SCARD_ERROR_OK)
- {
- ThrowError::throwError(this->error);
- }
-#endif
-#endif
}
else
{
{
if (getSession()->getReader()->isSecureElementPresent() == true)
{
-#ifdef USE_GDBUS
CallbackParam *param = new CallbackParam();
param->instance = this;
smartcard_service_channel_call_close_channel(
(SmartcardServiceChannel *)proxy,
- ClientGDBus::getCookie(),
GPOINTER_TO_UINT(context),
GPOINTER_TO_UINT(handle), NULL,
&ClientChannel::channel_close_cb, param);
-#else
- Message msg;
- channelNum = -1;
-
- /* send message to server */
- msg.message = Message::MSG_REQUEST_CLOSE_CHANNEL;
- msg.param1 = (unsigned long)handle;
- msg.error = (unsigned long)context; /* using error to context */
- msg.caller = (void *)this;
- msg.callback = (void *)callback;
- msg.userParam = userParam;
-
- if (ClientIPC::getInstance().sendMessage(msg) == false)
- {
- _ERR("sendMessage failed");
- result = SCARD_ERROR_IPC_FAILED;
- }
-#endif
}
else
{
if (getSession()->getReader()->isSecureElementPresent() == true)
{
-#ifdef USE_GDBUS
GVariant *var_command = NULL, *var_response = NULL;
GError *error = NULL;
if (smartcard_service_channel_call_transmit_sync(
(SmartcardServiceChannel *)proxy,
- ClientGDBus::getCookie(),
GPOINTER_TO_UINT(context),
GPOINTER_TO_UINT(handle),
var_command, &rv, &var_response,
throw ErrorIO(SCARD_ERROR_IPC_FAILED);
}
-#else
- Message msg;
-#ifdef CLIENT_IPC_THREAD
- /* send message to server */
- msg.message = Message::MSG_REQUEST_TRANSMIT;
- msg.param1 = (unsigned long)handle;
- msg.param2 = 0;
- msg.data = command;
- msg.error = (unsigned long)context; /* using error to context */
- msg.caller = (void *)this;
- msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
-
- syncLock();
- if (ClientIPC::getInstance().sendMessage(msg) == true)
- {
- rv = waitTimedCondition(0);
- if (rv >= 0)
- {
- result = response;
- rv = SCARD_ERROR_OK;
- }
- else
- {
- _ERR("timeout [%d]", rv);
- this->error = SCARD_ERROR_OPERATION_TIMEOUT;
- }
- }
- else
- {
- _ERR("sendMessage failed");
- }
- syncUnlock();
-
- if (this->error != SCARD_ERROR_OK)
- {
- ThrowError::throwError(this->error);
- }
-#endif
-#endif
}
else
{
if (getSession()->getReader()->isSecureElementPresent() == true)
{
-#ifdef USE_GDBUS
GVariant *var_command;
CallbackParam *param = new CallbackParam();
smartcard_service_channel_call_transmit(
(SmartcardServiceChannel *)proxy,
- ClientGDBus::getCookie(),
GPOINTER_TO_UINT(context),
GPOINTER_TO_UINT(handle),
var_command, NULL,
&ClientChannel::channel_transmit_cb, param);
result = SCARD_ERROR_OK;
-#else
- Message msg;
-
- /* send message to server */
- msg.message = Message::MSG_REQUEST_TRANSMIT;
- msg.param1 = (unsigned long)handle;
- msg.param2 = 0;
- msg.data = command;
- msg.error = (unsigned long)context; /* using error to context */
- msg.caller = (void *)this;
- msg.callback = (void *)callback;
- msg.userParam = userParam;
-
- if (ClientIPC::getInstance().sendMessage(msg) == true)
- {
- result = SCARD_ERROR_OK;
- }
- else
- {
- _ERR("sendMessage failed");
- result = SCARD_ERROR_IPC_FAILED;
- }
-#endif
}
else
{
return result;
}
-
-#ifndef USE_GDBUS
- bool ClientChannel::dispatcherCallback(void *message)
- {
- Message *msg = (Message *)message;
- ClientChannel *channel = NULL;
- bool result = false;
-
- if (msg == NULL)
- {
- _ERR("message is null");
- return result;
- }
-
- channel = (ClientChannel *)msg->caller;
-
- switch (msg->message)
- {
- case Message::MSG_REQUEST_TRANSMIT :
- {
- /* transmit result */
- _INFO("MSG_REQUEST_TRANSMIT");
-
- if (msg->isSynchronousCall() == true) /* synchronized call */
- {
- /* sync call */
- channel->syncLock();
-
- /* copy result */
- channel->error = msg->error;
- channel->response = msg->data;
-
- channel->signalCondition();
- channel->syncUnlock();
- }
- else if (msg->callback != NULL)
- {
- transmitCallback cb = (transmitCallback)msg->callback;
-
- /* async call */
- cb(msg->data.getBuffer(),
- msg->data.size(),
- msg->error,
- msg->userParam);
- }
- }
- break;
-
- case Message::MSG_REQUEST_CLOSE_CHANNEL :
- {
- _INFO("MSG_REQUEST_CLOSE_CHANNEL");
-
- if (msg->isSynchronousCall() == true) /* synchronized call */
- {
- /* sync call */
- channel->syncLock();
-
- channel->error = msg->error;
-
- channel->signalCondition();
- channel->syncUnlock();
- }
- else if (msg->callback != NULL)
- {
- closeChannelCallback cb = (closeChannelCallback)msg->callback;
-
- /* async call */
- cb(msg->error, msg->userParam);
- }
- }
- break;
-
- default:
- _DBG("Unknown message : %s", msg->toString().c_str());
- break;
- }
-
- delete msg;
-
- return result;
- }
-#endif /* USE_GDBUS */
} /* namespace smartcard_service_api */
/* export C API */
EXTERN_API void channel_close_sync(channel_h handle)
{
-#ifdef CLIENT_IPC_THREAD
CHANNEL_EXTERN_BEGIN;
try
{
{
}
CHANNEL_EXTERN_END;
-#endif
}
EXTERN_API int channel_transmit_sync(channel_h handle, unsigned char *command,
{
int result = -1;
-#ifdef CLIENT_IPC_THREAD
if (command == NULL || cmd_len == 0 || response == NULL || resp_len == NULL)
return result;
result = -1;
}
CHANNEL_EXTERN_END;
-#endif
return result;
}