本文整理汇总了C++中CDataAccessor::setData方法的典型用法代码示例。如果您正苦于以下问题:C++ CDataAccessor::setData方法的具体用法?C++ CDataAccessor::setData怎么用?C++ CDataAccessor::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDataAccessor
的用法示例。
在下文中一共展示了CDataAccessor::setData方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: address
bool L1InterfaceStub::processClientGetConnectionAddrRequest(CDataAccessor & accessor,
const iviLink::Ipc::DirectionID dirId)
{
LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__);
ConnectionInformation fake;
UInt8 * serializedData = fake.serialize();
accessor.setData(serializedData, fake.getSerializedSize());
accessor.setErrorCode(ConnectivityAgentError::ERROR_NOT_FOUND);
delete[] serializedData;
if (mpAgent)
{
iviLink::ConnectivityAgent::HAL::CCarrierAdapter* pca =
mpAgent->getCurrentCarrierAdapter();
if (pca)
{
LOG4CPLUS_INFO(logger, "Retrieving actual connection information");
ConnectionInformation address(pca->getLocalAddress(), pca->getRemoteAddress(),
pca->getTypeName());
UInt8 * serializedData = address.serialize();
accessor.setData(serializedData, address.getSerializedSize());
accessor.setErrorCode(BaseError::IVILINK_NO_ERROR);
delete[] serializedData;
}
}
// we try to send response always
return true;
}
示例2: testRawArray
void testRawArray()
{
//setup
UInt8 data[] = "012";
CDataAccessor a;
a.setChannelID(123);
a.setErrorCode(234);
a.setOpCode(345);
a.setData(data, sizeof(data));
UInt8 array[100];
a.printContent();
// test
UInt32 size = a.getObjectSize();
a.copyToRawArray(array);
CPPUNIT_ASSERT_EQUAL(sizeof(data) + 4*4, size);
CDataAccessor b(array, size);
b.printContent();
CPPUNIT_ASSERT_EQUAL(123u, b.getChannelID());
CPPUNIT_ASSERT_EQUAL(234u, b.getErrorCode());
CPPUNIT_ASSERT_EQUAL(345u, b.getOpCode());
CPPUNIT_ASSERT_EQUAL(sizeof(data), b.getDataSize());
CPPUNIT_ASSERT(0 == memcmp(data, b.getData(), sizeof(data)));
}
示例3: convertIntegerToString
void L1InterfaceStub::processServiceDeallocateRequest(CDataAccessor & accessor)
{
UInt32 channel_id = accessor.getChannelID();
LOG4CPLUS_INFO(logger, "L1InterfaceStub::processServiceDeallocateRequest() => "
"Channel deallocate request id = " + convertIntegerToString(channel_id));
ConnectivityAgentError ret = deallocateChannel(channel_id );
accessor.setOpCode(E_DEALLOCATE_CHANNEL_RESP);
UInt32 data = ret.getCode();
accessor.setData(reinterpret_cast<UInt8 *>(&data), sizeof(UInt32));
sendRequest(accessor);
if (ret.isNoError())
{
LOG4CPLUS_INFO(logger, "L1InterfaceStub::processServiceDeallocateRequest() => "
"channel successfully deallocated. "
"Notifying client");
iviLink::Ipc::DirectionID dirId;
bool found = false;
mRegistryMutex.lock();
tChannelsRegistryMap::iterator iter = mL1ChannelRegistry.find(accessor.getChannelID());
if (mL1ChannelRegistry.end() != iter)
{
dirId = iter->second.mClientDir;
found = true;
LOG4CPLUS_INFO(logger, "L1InterfaceStub::processServiceDeallocateRequest() => "
"channel found in registry - removing");
mL1ChannelRegistry.erase(accessor.getChannelID());
}
mRegistryMutex.unlock();
if (found)
{
accessor.setOpCode(E_DEALLOCATE_CHANNEL_NTF);
UInt8* buf = new UInt8[accessor.getObjectSize()];
accessor.copyToRawArray(buf);
BaseError err = mpIpc->asyncRequest(mMsgIdGen.next(),
buf, accessor.getObjectSize(), &dirId);
if (!err.isNoError())
{
LOG4CPLUS_WARN(logger, static_cast<std::string>(err));
}
delete[] buf;
}
} // ret == OK
}
示例4: sendData
ERROR_CODE CConnectivityAgentProxy::sendData(const UInt32 channel_id, UInt8 const* data,
const UInt32 size)
{
LOG4CPLUS_INFO(logger,
"CConnectivityAgentProxy::sendData() => channel " + convertIntegerToString(channel_id)
+ ", size " + convertIntegerToString(size));
ERROR_CODE ret = ERR_FAIL;
const int MAX_BUF_SIZE = 0xFFFF;
if ((data != NULL) && ((Int32) size > 0) && (size < MAX_BUF_SIZE))
{
mRegistryMutex.lockRead();
bool found = (mChannelRegistry.find(channel_id) != mChannelRegistry.end());
mRegistryMutex.unlockRead();
if (found)
{
CDataAccessor requestDA;
requestDA.setChannelID(channel_id);
requestDA.setOpCode(E_SEND_DATA);
requestDA.setData(data, size);
UInt8 buf[MAX_BUF_SIZE];
requestDA.copyToRawArray(buf);
assert(requestDA.getObjectSize() <= MAX_BUF_SIZE);
if (requestDA.getObjectSize() > MAX_BUF_SIZE)
{
LOG4CPLUS_ERROR(logger,
"CConnectivityAgentProxy::sendData() => ERROR: \
requestDA.getObjectSize() > max buf size");
}
UInt32 respSize = 0;
CError err = mpIpc->request(mMsgIdGen.next(), buf, requestDA.getObjectSize(), NULL,
respSize);
if (err.isNoError())
{
ret = ERR_OK;
} else
{
LOG4CPLUS_WARN(logger, static_cast<std::string>(err));
}
} else
示例5: if
bool L1InterfaceStub::processClientGetDeviceList(CDataAccessor & accessor, const iviLink::Ipc::DirectionID dirId)
{
LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__);
UInt32 number = 0;
if(accessor.getDataSize()<sizeof(UInt32))
{
accessor.resetData();
accessor.setErrorCode(ConnectivityAgentError::ERROR_REQUEST_FAILED);
return true;
}
number=*(reinterpret_cast<UInt32*>(accessor.getData()));
if(number!=0)
{
accessor.resetData();
accessor.setErrorCode(ConnectivityAgentError::ERROR_NOT_FOUND);
return true;
}
else
{
LOG4CPLUS_INFO(logger, "Device Number know, transmitting");
FoundDevice device;
UInt8* serializedData = NULL;
device.mName="N/a";
device.mAddress="";
device.mConnection=CON_UNKNOWN;
if (mpAgent)
{
iviLink::ConnectivityAgent::HAL::CCarrierAdapter* pca = mpAgent->getCurrentCarrierAdapter();
if (pca)
{
const char *remoteAddress = pca->getRemoteAddress();
const char *connTypeName = pca->getTypeName();
if(connTypeName == NULL)
{
connTypeName = "";
}
if(remoteAddress == NULL)
{
remoteAddress = "N/a";
}
std::string typeName = connTypeName;
device.mName = remoteAddress;
device.mAddress = remoteAddress;
if (typeName == "Bluetooth")
{
device.mConnection = CON_BLUETOOTH;
}
else if (typeName == "TCP/IP")
{
device.mConnection = CON_IP;
}
}
}
serializedData = device.serialize();
accessor.resetData();
accessor.setData(serializedData,device.getSerializedSize());
delete[] serializedData;
accessor.setErrorCode(BaseError::IVILINK_NO_ERROR);
return true;
}
}
示例6: switch
void L1InterfaceStub::RequestTimeout::onTimeout()
{
CDataAccessor resp;
UInt32 data = ERR_TIMEOUT;
if (mEnabled)
{
switch (mRequest)
{
case E_ALLOCATE_CHANNEL:
{
mpOwner->mRegistryMutex.lock();
bool found = (mpOwner->mL1ChannelRegistry.find(mChannelID) !=
mpOwner->mL1ChannelRegistry.end());
mpOwner->mRegistryMutex.unlock();
if (found)
{
LOG4CPLUS_INFO(logger, "L1InterfaceStub::RequestTimeout::onTimeout()=> channel "
+ convertIntegerToString(mChannelID) + " allocated!");
}
else
{
LOG4CPLUS_WARN(logger, "L1InterfaceStub::RequestTimeout::onTimeout()=> Channel "
+ convertIntegerToString(mChannelID) + " allocation timeout!");
resp.setChannelID(mChannelID);
resp.setOpCode(E_ALLOCATE_CHANNEL_RESP);
resp.setData(reinterpret_cast<UInt8 *>(&data), sizeof(UInt32));
resp.setErrorCode(ConnectivityAgentError::ERROR_TIMEOUT);
mpOwner->mRequestedMapMutex.lock();
mpOwner->mRequestedMap.erase(mChannelID);
mpOwner->mRequestedMapMutex.unlock();
mpOwner->sendRequest(resp);
}
break;
}
case E_DEALLOCATE_CHANNEL:
{
iviLink::Ipc::DirectionID client_dir;
bool found = false;
mpOwner->mRegistryMutex.lock();
{
tChannelsRegistryMap::iterator iter = mpOwner->mL1ChannelRegistry.find(mChannelID);
found = (iter != mpOwner->mL1ChannelRegistry.end());
if (found)
{
client_dir = iter->second.mClientDir;
}
}
mpOwner->mRegistryMutex.unlock();
if (found)
{
LOG4CPLUS_INFO(logger, "L1InterfaceStub::RequestTimeout::onTimeout() => "
"Channel deallocation timeout!");
resp.setChannelID(mChannelID);
resp.setOpCode(E_DEALLOCATE_CHANNEL_RESP);
resp.setData(reinterpret_cast<UInt8 *>(&data), sizeof(UInt32));
resp.setErrorCode(ConnectivityAgentError::ERROR_TIMEOUT);
UInt8* buf = new UInt8[resp.getObjectSize()];
resp.copyToRawArray(buf);
BaseError err = mpOwner->mpIpc->asyncRequest(mpOwner->mMsgIdGen.next(),
buf, resp.getObjectSize(), &client_dir);
if (!err.isNoError())
{
LOG4CPLUS_WARN(logger, static_cast<std::string>(err));
}
delete [] buf;
}
else
{
LOG4CPLUS_INFO(logger, "L1InterfaceStub::RequestTimeout::onTimeout() => "
"channel Deallocated!");
}
break;
}
default:
break;
}
}
}
示例7: allocateChannel
ERROR_CODE CConnectivityAgentProxy::allocateChannel(TChannelPriority prio, UInt32 channel_id,
IChannelObserver* observer)
{
LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__);
LOG4CPLUS_INFO(logger,
"CConnectivityAgentProxy::allocateChannel(type = " + convertIntegerToString((int) prio)
+ ", id = " + convertIntegerToString(channel_id) + " ), this = "
+ convertIntegerToString((intptr_t) this));
ERROR_CODE ret = ERR_FAIL;
if ((channel_id > 0) && (channel_id <= 0xFFFF) && (NULL != observer))
{
mRegistryMutex.lockWrite();
bool channel_unknown = mChannelRegistry.find(channel_id) == mChannelRegistry.end();
mRegistryMutex.unlockWrite();
if (channel_unknown)
{
mAllocateRequestCond.lock();
bool channel_requested = mAllocateRequestMap.find(channel_id)
!= mAllocateRequestMap.end();
if (channel_requested)
{
ret = ERR_IN_PROGRESS;
channel_unknown = false;
LOG4CPLUS_WARN(logger,
"CConnectivityAgentProxy::allocateChannel() => ERROR: channel allocation in progress!");
} else
{
LOG4CPLUS_INFO(logger,
"CConnectivityAgentProxy::allocateChannel() => insert request");
mAllocateRequestMap.insert(
std::make_pair(channel_id,
AllocateRequestInfo(prio, observer, false, ERR_UNKNOWN)));
}
mAllocateRequestCond.unlock();
}
if (channel_unknown)
{
CDataAccessor requestDA;
requestDA.setChannelID(channel_id);
requestDA.setOpCode(E_ALLOCATE_CHANNEL);
UInt32 data = prio;
requestDA.setData(reinterpret_cast<UInt8 *>(&data), sizeof(UInt32));
UInt8* buf = new UInt8[requestDA.getObjectSize()];
requestDA.copyToRawArray(buf);
UInt8 respBuf[100];
UInt32 respSize = sizeof(respBuf);
CError err = mpIpc->request(mMsgIdGen.next(), buf, requestDA.getObjectSize(), respBuf,
respSize);
delete[] buf;
if (!err.isNoError())
{
LOG4CPLUS_WARN(logger, static_cast<std::string>(err));
ret = ERR_FAIL;
mAllocateRequestCond.lock();
mAllocateRequestMap.erase(channel_id);
mAllocateRequestCond.unlock();
LOG4CPLUS_WARN(logger,
"CConnectivityAgentProxy::allocateChannel() => ERROR: failed to send request");
} else
{
CDataAccessor responseDA;
if (respSize > 0)
{
responseDA = CDataAccessor(respBuf, respSize);
ret = static_cast<ERROR_CODE>(responseDA.getErrorCode());
mAllocateRequestCond.lock();
mAllocateRequestMap.erase(channel_id);
mAllocateRequestCond.unlock();
LOG4CPLUS_WARN(logger,
"CConnectivityAgentProxy::allocateChannel() => ERROR: got error response");
} else
{
mAllocateRequestCond.lock();
while (true)
{
tAllocateRequestMap::iterator it = mAllocateRequestMap.find(channel_id);
if (it == mAllocateRequestMap.end())
{
ret = ERR_FAIL;
LOG4CPLUS_WARN(logger,
"CConnectivityAgentProxy::allocateChannel() => ERROR: request was removed");
break;
}
AllocateRequestInfo & info = it->second;
if (info.mRequestDone)
{
LOG4CPLUS_INFO(logger,
"CConnectivityAgentProxy::allocateChannel() => request done");
ret = info.mResult;
//.........这里部分代码省略.........