diff --git a/pvAccessApp/client/pvAccess.h b/pvAccessApp/client/pvAccess.h index cabd16e..7f59f9b 100644 --- a/pvAccessApp/client/pvAccess.h +++ b/pvAccessApp/client/pvAccess.h @@ -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; }; /** diff --git a/pvAccessApp/remoteClient/clientContextImpl.cpp b/pvAccessApp/remoteClient/clientContextImpl.cpp index 9a162cb..c9cf0ee 100644 --- a/pvAccessApp/remoteClient/clientContextImpl.cpp +++ b/pvAccessApp/remoteClient/clientContextImpl.cpp @@ -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); diff --git a/pvAccessApp/server/responseHandlers.cpp b/pvAccessApp/server/responseHandlers.cpp index 9e20e9e..a1699e0 100644 --- a/pvAccessApp/server/responseHandlers.cpp +++ b/pvAccessApp/server/responseHandlers.cpp @@ -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(); { diff --git a/pvAccessCPP.files b/pvAccessCPP.files index a0e4c1e..7a38550 100644 --- a/pvAccessCPP.files +++ b/pvAccessCPP.files @@ -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 diff --git a/testApp/remote/channelAccessIFTest.cpp b/testApp/remote/channelAccessIFTest.cpp index cdd1307..492bbb9 100755 --- a/testApp/remote/channelAccessIFTest.cpp +++ b/testApp/remote/channelAccessIFTest.cpp @@ -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; diff --git a/testApp/remote/syncTestRequesters.h b/testApp/remote/syncTestRequesters.h index 705d01d..d100e03 100755 --- a/testApp/remote/syncTestRequesters.h +++ b/testApp/remote/syncTestRequesters.h @@ -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()) { diff --git a/testApp/remote/testRemoteClientImpl.cpp b/testApp/remote/testRemoteClientImpl.cpp index 6161fd9..0d0c8ab 100644 --- a/testApp/remote/testRemoteClientImpl.cpp +++ b/testApp/remote/testRemoteClientImpl.cpp @@ -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 ); diff --git a/testApp/remote/testServer.cpp b/testApp/remote/testServer.cpp index 75ab021..a70f593 100644 --- a/testApp/remote/testServer.cpp +++ b/testApp/remote/testServer.cpp @@ -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(offset); - if (count == -1) count = static_cast(m_pvArray->getLength()); - size_t c = static_cast(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(offset); - if (count == -1) count = static_cast(m_pvStructureArray->getLength()); - size_t c = static_cast(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)