//
-// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
#include <typeinfo>
#include <unique_ptr.h>
-#include <package_manager.h>
-
#include <message-port.h>
#include <FBaseSysLog.h>
+#include <FBaseByteBuffer.h>
+
#include <FBase_StringConverter.h>
#include <FApp_AppInfo.h>
namespace Tizen { namespace Io
{
+//static const int MAX_MESSAGE_SIZE = 16 * 1024;
+
static void
ConvertBundleToMap(const char *pKey, const int type, const bundle_keyval_t *pVal, void *pData)
{
- SysLog(NID_IO, "CB key = %s", pKey);
+ //SysLog(NID_IO, "CB key = %s", pKey);
HashMap* pMap = static_cast<HashMap*>(pData);
case BUNDLE_TYPE_BYTE:
bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
- SysLog(NID_IO, "Bundle byte value = %s, size = %d", pStr, size);
+ //SysLog(NID_IO, "Bundle byte value = %s, size = %d", pStr, size);
if (pStr)
{
ByteBuffer* pBuffer = new (std::nothrow) ByteBuffer();
- SysTryReturn(NID_IO, pMap != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+ SysTryReturnVoidResult(NID_IO, pMap != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
result r = pBuffer->Construct(size);
- SysTryReturn(NID_IO, r == E_SUCCESS, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+ SysTryCatch(NID_IO, r == E_SUCCESS, delete pBuffer, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+ r = pBuffer->SetArray((const byte*)pStr, 0, size);
+ SysTryCatch(NID_IO, r == E_SUCCESS, delete pBuffer, E_INVALID_ARG, "[E_INVALID_ARG] The buffer argument is invalid.");
- pBuffer->SetArray((const byte*)pStr, 0, size);
pBuffer->Flip();
pMap->Add(new (std::nothrow) String(pKey), pBuffer);
break;
}
}
+
+CATCH:
+ return;
}
static void
ret = messageport_get_local_port_name(id, &pLocalPort);
if (pLocalPort == null)
{
- SysLog(NID_IO, "No local port for id: %d", id);
+ SysSecureLog(NID_IO, "No local port for id: %d", id);
bundle_free(data);
return;
}
- SysLog(NID_IO, "local port name: %s", pLocalPort);
+ //SysLog(NID_IO, "local port name: %s", pLocalPort);
_IMessagePortListener* pListener = null;
p->__listeners.GetValue(pLocalPort, pListener);
result r = pMap->Construct();
SysTryCatch(NID_IO, r == E_SUCCESS, delete pMap, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
- SysLog(NID_IO, "bundle to map");
-
bundle_foreach(data, ConvertBundleToMap, pMap);
if (remote_app_id == null) // Uni-directional
}
else // Bi-directional
{
- SysLog(NID_IO, "Message received from [%s:%s], trusted: %d", remote_app_id, remote_port, trusted_port);
+ SysSecureLog(NID_IO, "Message received from [%s:%s], trusted: %d", remote_app_id, remote_port, trusted_port);
pListener->OnMessageReceivedN(remote_app_id, remote_port, trusted_port, pMap);
}
ret = messageport_get_local_port_name(id, &pLocalPort);
if (pLocalPort == null)
{
- SysLog(NID_IO, "No local port for id: %d", id);
+ SysSecureLog(NID_IO, "No local port for id: %d", id);
bundle_free(data);
return;
}
else // Bi-directional
{
- SysLog(NID_IO, "Trusted message received from [%s:%s], trusted: %d", remote_app_id, remote_port, trusted_port);
+ SysSecureLog(NID_IO, "Trusted message received from [%s:%s], trusted: %d", remote_app_id, remote_port, trusted_port);
+
pListener->OnMessageReceivedN(remote_app_id, remote_port, trusted_port, pMap);
}
}
_MessagePortProxy::RegisterMessagePort(const String& localPort, bool isTrusted,
const _IMessagePortListener& listener)
{
- SysLog(NID_IO, "Register a message port : [%ls:%ls]", __appId.GetPointer(), localPort.GetPointer());
+ SysSecureLog(NID_IO, "Register a message port : [%ls:%ls]", __appId.GetPointer(), localPort.GetPointer());
- result r = E_SUCCESS;
int ret = 0;
bool contain = false;
const String& remotePort,
bool isTrusted)
{
- SysLog(NID_IO, "Request a remote message port [%ls:%ls]", remoteAppId.GetPointer(), remotePort.GetPointer());
+ SysSecureLog(NID_IO, "Request a remote message port [%ls:%ls]", remoteAppId.GetPointer(), remotePort.GetPointer());
result r = E_SUCCESS;
int ret = 0;
result
_MessagePortProxy::SendMessage(const AppId& remoteAppId, const String& remotePort, bool isTrusted, const HashMap* pMap)
{
- SysLog(NID_IO, "Send a unidirectional message to remote port [%ls:%ls]", remoteAppId.GetPointer(), remotePort.GetPointer());
+ SysSecureLog(NID_IO, "Send a unidirectional message to remote port [%ls:%ls]", remoteAppId.GetPointer(), remotePort.GetPointer());
int ret = 0;
+ int size = 0;
// Convert Map to bundle
- bundle* b = ConvertMapToBundleN(pMap);
- SysTryReturnResult(NID_IO, b != null, E_SYSTEM, "Internal system errors.");
+ bundle* b = ConvertMapToBundleN(pMap, &size);
+ SysTryReturnResult(NID_IO, b != null, E_INVALID_ARG, "The argument is invalid.");
+ //SysTryReturnResult(NID_IO, size <= MAX_MESSAGE_SIZE, E_MAX_EXCEEDED, "The size of the message has exceeded the maximum limit.");
unique_ptr<char[]> pRemoteAppId(_StringConverter::CopyToCharArrayN(remoteAppId));
unique_ptr<char[]> pRemotePort(_StringConverter::CopyToCharArrayN(remotePort));
if (ret < 0)
{
+ if (ret == MESSAGEPORT_ERROR_RESOURCE_UNAVAILABLE)
+ {
+ SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] The socket receiver queue of remote port is temporarily full.");
+ }
+
result r = ConvertToResult(ret);
SysTryReturnResult(NID_IO, r != E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "The remote message port is not found.");
result
_MessagePortProxy::SendMessage(const String& localPort, bool isTrustedLocal, const AppId& remoteAppId, const String& remotePort, bool isTrustedRemote, const HashMap* pMap)
{
- SysLog(NID_IO, "Send a bidirectional message from [%ls:%ls] to [%ls:%ls]", __appId.GetPointer(), localPort.GetPointer(), remoteAppId.GetPointer(), remotePort.GetPointer());
+ SysSecureLog(NID_IO, "Send a bidirectional message from [%ls:%ls] to [%ls:%ls]", __appId.GetPointer(), localPort.GetPointer(), remoteAppId.GetPointer(), remotePort.GetPointer());
result r = E_SUCCESS;
int id = 0;
SysTryReturnResult(NID_IO, r == E_SUCCESS, E_SYSTEM, "Internal system errors.");
+ int size = 0;
+
// Convert Map to bundle
- bundle* b = ConvertMapToBundleN(pMap);
- SysTryReturnResult(NID_IO, b != null, E_SYSTEM, "Internal system errors.");
+ bundle* b = ConvertMapToBundleN(pMap, &size);
+ SysTryReturnResult(NID_IO, b != null, E_INVALID_ARG, "The argument is invalid.");
+ //SysTryReturnResult(NID_IO, size <= MAX_MESSAGE_SIZE, E_MAX_EXCEEDED, "The size of the message has exceeded the maximum limit.");
unique_ptr<char[]> pRemoteAppId(_StringConverter::CopyToCharArrayN(remoteAppId));
unique_ptr<char[]> pRemotePort(_StringConverter::CopyToCharArrayN(remotePort));
if (ret < 0)
{
+ if (ret == MESSAGEPORT_ERROR_RESOURCE_UNAVAILABLE)
+ {
+ SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] The socket receiver queue of remote port is temporarily full.");
+ }
+
result r = ConvertToResult(ret);
SysTryReturnResult(NID_IO, r != E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "The remote message port is not found.");
case MESSAGEPORT_ERROR_MAX_EXCEEDED:
return E_MAX_EXCEEDED;
+ case MESSAGEPORT_ERROR_RESOURCE_UNAVAILABLE:
+ // fall through
+
default:
return E_SYSTEM;
}
}
bundle*
-_MessagePortProxy::ConvertMapToBundleN(const HashMap* pMap)
+_MessagePortProxy::ConvertMapToBundleN(const HashMap* pMap, int* pSize)
{
bundle *b = bundle_create();
+ int size = 0;
std::unique_ptr<IMapEnumerator> pEnum (pMap->GetMapEnumeratorN());
while(pEnum->MoveNext() == E_SUCCESS)
if (typeid(*pValue) == typeid(const String)) // String
{
- unique_ptr<char[]> pValueData(_StringConverter::CopyToCharArrayN(*(static_cast<const String*>(pValue))));
+ const String* pStr = static_cast<const String*>(pValue);
+ size += pStr->GetLength() * sizeof(wchar_t);
+
+ unique_ptr<char[]> pValueData(_StringConverter::CopyToCharArrayN(*pStr));
//SysLog(NID_IO, "key: %s, value: %s", pKeyData.get(), pValueData.get());
if (typeid(*pValue) == typeid(const ByteBuffer)) // ByteBuffer
{
const ByteBuffer* pBuffer = static_cast<const ByteBuffer*>(pValue);
+ size += pBuffer->GetLimit();
- // Add a byte data to bundle
- SysLog(NID_IO, "Add a string key: %s, byte value: %s", pKeyData.get(), pBuffer->GetPointer());
+ //SysLog(NID_IO, "Add a string key: %s, byte value: %s", pKeyData.get(), pBuffer->GetPointer());
bundle_add_byte(b, pKeyData.get(), pBuffer->GetPointer(), pBuffer->GetLimit());
}
else
{
- SysLog(NID_IO, "Not supported");
+ SysLog(NID_IO, "The value type is not supported.");
bundle_free(b);
return null;
}
else
{
- SysLog(NID_IO, "Not supported");
+ SysLog(NID_IO, "The key type is not supported.");
bundle_free(b);
return null;
}
}
+ *pSize = size;
return b;
}