#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 "smartcard-service-gdbus.h"
-#include "GDBusHelper.h"
-#else
-#include "Message.h"
-#include "ClientIPC.h"
-#endif
+#include "ClientGDBus.h"
#ifndef EXTERN_API
#define EXTERN_API __attribute__((visibility("default")))
namespace smartcard_service_api
{
ClientChannel::ClientChannel(void *context, Session *session,
- int channelNum, ByteArray selectResponse, void *handle)
+ int channelNum, const ByteArray &selectResponse, void *handle)
: Channel(session)
{
this->channelNum = -1;
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)
{
if (callback != NULL) {
callback(response.getBuffer(),
- response.getLength(),
+ response.size(),
result, param->user_param);
}
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;
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;
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
{
return result;
}
- int ClientChannel::transmitSync(ByteArray command, ByteArray &result)
+ int ClientChannel::transmitSync(const ByteArray &command, ByteArray &result)
throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
ErrorIllegalParameter &, ErrorSecurity &)
{
if (getSession()->getReader()->isSecureElementPresent() == true)
{
-#ifdef USE_GDBUS
GVariant *var_command = NULL, *var_response = NULL;
GError *error = NULL;
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
{
return rv;
}
- int ClientChannel::transmit(ByteArray command, transmitCallback callback, void *userParam)
+ int ClientChannel::transmit(const ByteArray &command, transmitCallback callback, void *userParam)
{
int result;
if (getSession()->getReader()->isSecureElementPresent() == true)
{
-#ifdef USE_GDBUS
GVariant *var_command;
CallbackParam *param = new CallbackParam();
GPOINTER_TO_UINT(context),
GPOINTER_TO_UINT(handle),
var_command, NULL,
- &ClientChannel::channel_close_cb, param);
+ &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.getLength(), 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());
- break;
- }
-
- delete msg;
-
- return result;
- }
-#endif /* USE_GDBUS */
} /* namespace smartcard_service_api */
/* export C API */
CHANNEL_EXTERN_BEGIN;
ByteArray temp;
- temp.setBuffer(command, length);
+ temp.assign(command, length);
result = channel->transmit(temp, (transmitCallback)callback, userParam);
CHANNEL_EXTERN_END;
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;
CHANNEL_EXTERN_BEGIN;
ByteArray temp, resp;
- temp.setBuffer(command, cmd_len);
+ temp.assign(command, cmd_len);
try
{
result = channel->transmitSync(temp, resp);
- if (resp.getLength() > 0)
+ if (resp.size() > 0)
{
- *resp_len = resp.getLength();
+ *resp_len = resp.size();
*response = (unsigned char *)calloc(1, *resp_len);
memcpy(*response, resp.getBuffer(), *resp_len);
}
result = -1;
}
CHANNEL_EXTERN_END;
-#endif
return result;
}
unsigned int result = 0;
CHANNEL_EXTERN_BEGIN;
- result = channel->getSelectResponse().getLength();
+ result = channel->getSelectResponse().size();
CHANNEL_EXTERN_END;
return result;
ByteArray response;
response = channel->getSelectResponse();
- if (response.getLength() > 0)
+ if (response.size() > 0)
{
- memcpy(buffer, response.getBuffer(), MIN(length, response.getLength()));
+ memcpy(buffer, response.getBuffer(), MIN(length, response.size()));
result = true;
}
CHANNEL_EXTERN_END;