ChannelArray int to size_t

This commit is contained in:
Matej Sekoranja
2014-04-04 12:36:11 +02:00
parent 4405346384
commit d2fb05ddd8
8 changed files with 47 additions and 46 deletions

View File

@@ -128,25 +128,25 @@ namespace pvAccess {
* put to the remote array.
* @param lastRequest Is this the last request.
* @param offset The offset in the remote array, i.e. the PVArray returned by ChannelArrayRequester.channelArrayConnect.
* @param count The number of elements to put.
* @param count The number of elements to put, 0 means "enture array".
*/
virtual void putArray(bool lastRequest, int offset, int count) = 0;
virtual void putArray(bool lastRequest, size_t offset = 0, size_t count = 0) = 0;
/**
* get from the remote array.
* @param lastRequest Is this the last request.
* @param offset The offset in the remote array, i.e. the PVArray returned by ChannelArrayRequester.channelArrayConnect.
* @param count The number of elements to get.
* @param count The number of elements to get, 0 means "till the end of an array".
*/
virtual void getArray(bool lastRequest, int offset, int count) = 0;
virtual void getArray(bool lastRequest, size_t offset = 0, size_t count = 0) = 0;
/**
* Set the length and/or the capacity.
* @param lastRequest Is this the last request.
* @param length The new length. -1 means do not change.
* @param capacity The new capacity. -1 means do not change.
* @param length The new length.
* @param capacity The new capacity, 0 means do "do not change the capacity".
*/
virtual void setLength(bool lastRequest, int length, int capacity) = 0;
virtual void setLength(bool lastRequest, size_t length, size_t capacity = 0) = 0;
};
/**

View File

@@ -1388,12 +1388,11 @@ namespace epics {
PVArray::shared_pointer m_structure;
// TODO revise int32 !!!
int32 m_offset;
int32 m_count;
size_t m_offset;
size_t m_count;
int32 m_length;
int32 m_capacity;
size_t m_length;
size_t m_capacity;
Mutex m_structureMutex;
@@ -1402,7 +1401,7 @@ namespace epics {
m_channelArrayRequester(channelArrayRequester),
m_pvRequest(pvRequest),
m_offset(0), m_count(0),
m_length(-1), m_capacity(-1)
m_length(0), m_capacity(0)
{
PVACCESS_REFCOUNT_MONITOR_CONSTRUCT(channelArray);
}
@@ -1478,7 +1477,7 @@ namespace epics {
// no need to lock here, since it is already locked via TransportSender IF
//Lock lock(m_structureMutex);
SerializeHelper::writeSize(m_offset, buffer, control);
m_structure->serialize(buffer, control, 0, m_count); // put from 0 offset; TODO count out-of-bounds check?!
m_structure->serialize(buffer, control, 0, m_count ? m_count : m_structure->getLength()); // put from 0 offset (see API doc), m_count == 0 means entire array
}
}
@@ -1543,7 +1542,7 @@ namespace epics {
}
virtual void getArray(bool lastRequest, int offset, int count) {
virtual void getArray(bool lastRequest, size_t offset, size_t count) {
{
Lock guard(m_mutex);
@@ -1575,7 +1574,7 @@ namespace epics {
}
}
virtual void putArray(bool lastRequest, int offset, int count) {
virtual void putArray(bool lastRequest, size_t offset, size_t count) {
{
Lock guard(m_mutex);
@@ -1607,7 +1606,7 @@ namespace epics {
}
}
virtual void setLength(bool lastRequest, int length, int capacity) {
virtual void setLength(bool lastRequest, size_t length, size_t capacity) {
{
Lock guard(m_mutex);

View File

@@ -1481,20 +1481,20 @@ void ServerArrayHandler::handleResponse(osiSockAddr* responseFrom,
if (get)
{
const int32 offset = SerializeHelper::readSize(payloadBuffer, transport.get());
const int32 count = SerializeHelper::readSize(payloadBuffer, transport.get());
size_t offset = SerializeHelper::readSize(payloadBuffer, transport.get());
size_t count = SerializeHelper::readSize(payloadBuffer, transport.get());
request->getChannelArray()->getArray(lastRequest, offset, count);
}
else if (setLength)
{
const int32 length = SerializeHelper::readSize(payloadBuffer, transport.get());
const int32 capacity = SerializeHelper::readSize(payloadBuffer, transport.get());
size_t length = SerializeHelper::readSize(payloadBuffer, transport.get());
size_t capacity = SerializeHelper::readSize(payloadBuffer, transport.get());
request->getChannelArray()->setLength(lastRequest, length, capacity);
}
else
{
// deserialize data to put
int32 offset;
size_t offset;
ChannelArray::shared_pointer channelArray = request->getChannelArray();
PVArray::shared_pointer array = request->getPVArray();
{

View File

@@ -121,3 +121,6 @@ pvAccessApp/ca/caProvider.cpp
pvAccessApp/ca/caChannel.h
pvAccessApp/ca/caChannel.cpp
testApp/utils/Makefile
testApp/remote/channelAccessIFTest.h
testApp/remote/channelAccessIFTest.cpp
testApp/remote/syncTestRequesters.h

View File

@@ -1754,13 +1754,13 @@ void ChannelAccessIFTest::test_channelArray() {
array->replace(freeze(newdata));
succStatus = arrayReq->syncPut(false, 0, -1, getTimeoutSec());
succStatus = arrayReq->syncPut(false, 0, 0, getTimeoutSec());
if (!succStatus) {
testFail("%s: an array syncPut failed (2) ", CURRENT_FUNCTION);
return;
}
succStatus = arrayReq->syncGet(false, 0, -1, getTimeoutSec());
succStatus = arrayReq->syncGet(false, 0, 0, getTimeoutSec());
if (!succStatus) {
testFail("%s: an array syncGet failed (3) ", CURRENT_FUNCTION);
return;
@@ -1800,13 +1800,13 @@ void ChannelAccessIFTest::test_channelArray() {
//testOk(data1[2] == 2.2 , "%s: check 2: %f", CURRENT_FUNCTION, data1[2]);
succStatus = arrayReq->syncSetLength(false, 3, -1, getTimeoutSec());
succStatus = arrayReq->syncSetLength(false, 3, 0, getTimeoutSec());
if (!succStatus) {
testFail("%s: an array setLength failed ", CURRENT_FUNCTION);
return;
}
succStatus = arrayReq->syncGet(false, 0, -1, getTimeoutSec());
succStatus = arrayReq->syncGet(false, 0, 0, getTimeoutSec());
if (!succStatus) {
testFail("%s: an array syncGet failed (7) ", CURRENT_FUNCTION);
return;
@@ -1821,14 +1821,15 @@ void ChannelAccessIFTest::test_channelArray() {
testOk(data2[1] == 2.2 , "%s: 2.check 1: %f", CURRENT_FUNCTION, data2[1]);
testOk(data2[2] == 3.3, "%s: 2.check 2: %f", CURRENT_FUNCTION, data2[2]);
size_t currentLength = 3;
size_t newCap = 2;
succStatus = arrayReq->syncSetLength(false, -1, newCap, getTimeoutSec());
succStatus = arrayReq->syncSetLength(false, currentLength, newCap, getTimeoutSec());
if (!succStatus) {
testFail("%s: an array setLength failed (2) ", CURRENT_FUNCTION);
return;
}
succStatus = arrayReq->syncGet(false, 0, -1, getTimeoutSec());
succStatus = arrayReq->syncGet(false, 0, 0, getTimeoutSec());
if (!succStatus) {
testFail("%s: an array syncGet failed (8) ", CURRENT_FUNCTION);
return;
@@ -1850,7 +1851,7 @@ void ChannelAccessIFTest::test_channelArray() {
return;
}
succStatus = arrayReq->syncGet(false, 0, -1, getTimeoutSec());
succStatus = arrayReq->syncGet(false, 0, 0, getTimeoutSec());
if (!succStatus) {
testFail("%s: an array syncGet failed (9) ", CURRENT_FUNCTION);
return;

View File

@@ -1134,7 +1134,7 @@ class SyncChannelArrayRequesterImpl : public ChannelArrayRequester, public SyncB
m_lengthArrayStatus(false) {}
bool syncPut(bool lastRequest, int offset, int count, long timeOut)
bool syncPut(bool lastRequest, size_t offset, size_t count, long timeOut)
{
if (!getConnectedStatus()) {
@@ -1146,7 +1146,7 @@ class SyncChannelArrayRequesterImpl : public ChannelArrayRequester, public SyncB
}
bool syncGet(bool lastRequest, int offset, int count, long timeOut)
bool syncGet(bool lastRequest, size_t offset, size_t count, long timeOut)
{
if (!getConnectedStatus()) {
@@ -1158,7 +1158,7 @@ class SyncChannelArrayRequesterImpl : public ChannelArrayRequester, public SyncB
}
bool syncSetLength(bool lastRequest, int length, int capacity, long timeOut)
bool syncSetLength(bool lastRequest, size_t length, size_t capacity, long timeOut)
{
if (!getConnectedStatus()) {

View File

@@ -539,9 +539,9 @@ int main()
ChannelArray::shared_pointer channelArray = channel->createChannelArray(channelArrayRequesterImpl, pvRequest);
epicsThreadSleep ( 1.0 );
channelArray->getArray(false,0,-1);
channelArray->getArray(false,0,0);
epicsThreadSleep ( 1.0 );
channelArray->putArray(false,0,-1);
channelArray->putArray(false,0,0);
epicsThreadSleep ( 1.0 );
channelArray->setLength(false,3,4);
epicsThreadSleep ( 1.0 );

View File

@@ -1693,11 +1693,11 @@ public:
to->replace(freeze(temp));
}
virtual void putArray(bool lastRequest, int offset, int count)
virtual void putArray(bool lastRequest, size_t offset, size_t count)
{
size_t o = static_cast<size_t>(offset);
if (count == -1) count = static_cast<int>(m_pvArray->getLength());
size_t c = static_cast<size_t>(count);
size_t o = offset;
if (count == 0) count = m_pvArray->getLength();
size_t c = count;
Field::const_shared_pointer field = m_pvArray->getField();
Type type = field->getType();
@@ -1745,11 +1745,11 @@ public:
}
virtual void getArray(bool lastRequest, int offset, int count)
virtual void getArray(bool lastRequest, size_t offset, size_t count)
{
size_t o = static_cast<size_t>(offset);
if (count == -1) count = static_cast<int>(m_pvStructureArray->getLength());
size_t c = static_cast<size_t>(count);
size_t o = offset;
if (count == 0) count = m_pvStructureArray->getLength();
size_t c = count;
Field::const_shared_pointer field = m_pvArray->getField();
Type type = field->getType();
@@ -1781,15 +1781,13 @@ public:
destroy();
}
virtual void setLength(bool lastRequest, int length, int capacity)
virtual void setLength(bool lastRequest, size_t length, size_t capacity)
{
if (capacity > 0) {
m_pvStructureArray->setCapacity(capacity);
}
if (length > 0) {
m_pvStructureArray->setLength(length);
}
m_pvStructureArray->setLength(length);
m_channelArrayRequester->setLengthDone(Status::Ok);
if (lastRequest)