diff --git a/src/client/pvAccess.h b/src/client/pvAccess.h index 586bb3e..4347566 100644 --- a/src/client/pvAccess.h +++ b/src/client/pvAccess.h @@ -166,16 +166,15 @@ namespace pvAccess { virtual void getArray(size_t offset = 0, size_t count = 0, size_t stride = 1) = 0; /** - * Get the length and the capacity. + * Get the length. */ virtual void getLength() = 0; /** * Set the length and/or the capacity. * @param length The new length. - * @param capacity The new capacity, 0 means do "do not change the capacity". */ - virtual void setLength(size_t length, size_t capacity = 0) = 0; + virtual void setLength(size_t length) = 0; }; /** @@ -221,12 +220,11 @@ namespace pvAccess { * @param status Completion status. * @param channelArray The channelArray interface. * @param length The length of the array, 0 if the request failed. - * @param capacity The capacity of the array, 0 if the request failed. */ virtual void getLengthDone( const epics::pvData::Status& status, ChannelArray::shared_pointer const & channelArray, - size_t length, size_t capacity) = 0; + size_t length) = 0; /** * The request is done. This is always called with no locks held. diff --git a/src/remoteClient/clientContextImpl.cpp b/src/remoteClient/clientContextImpl.cpp index 9775d5c..ff29f00 100644 --- a/src/remoteClient/clientContextImpl.cpp +++ b/src/remoteClient/clientContextImpl.cpp @@ -1574,7 +1574,6 @@ namespace epics { size_t m_stride; size_t m_length; - size_t m_capacity; Mutex m_structureMutex; @@ -1583,7 +1582,7 @@ namespace epics { m_channelArrayRequester(channelArrayRequester), m_pvRequest(pvRequest), m_offset(0), m_count(0), - m_length(0), m_capacity(0) + m_length(0) { PVACCESS_REFCOUNT_MONITOR_CONSTRUCT(channelArray); } @@ -1651,7 +1650,6 @@ namespace epics { { // lock... see comment below SerializeHelper::writeSize(m_length, buffer, control); - SerializeHelper::writeSize(m_capacity, buffer, control); } else if (pendingRequest & QOS_PROCESS) // i.e. getLength { @@ -1721,9 +1719,8 @@ namespace epics { else if (qos & QOS_PROCESS) { size_t length = SerializeHelper::readSize(payloadBuffer, transport.get()); - size_t capacity = SerializeHelper::readSize(payloadBuffer, transport.get()); - EXCEPTION_GUARD(m_channelArrayRequester->getLengthDone(status, thisChannelArray, length, capacity)); + EXCEPTION_GUARD(m_channelArrayRequester->getLengthDone(status, thisChannelArray, length)); } else { @@ -1813,7 +1810,7 @@ namespace epics { } } - virtual void setLength(size_t length, size_t capacity) { + virtual void setLength(size_t length) { ChannelArray::shared_pointer thisChannelArray = dynamic_pointer_cast(shared_from_this()); @@ -1838,7 +1835,6 @@ namespace epics { { Lock lock(m_structureMutex); m_length = length; - m_capacity = capacity; } m_channel->checkAndGetTransport()->enqueueSendRequest(shared_from_this()); } catch (std::runtime_error &rte) { @@ -1855,17 +1851,17 @@ namespace epics { { Lock guard(m_mutex); if (m_destroyed) { - EXCEPTION_GUARD(m_channelArrayRequester->getLengthDone(destroyedStatus, thisChannelArray, 0, 0)); + EXCEPTION_GUARD(m_channelArrayRequester->getLengthDone(destroyedStatus, thisChannelArray, 0)); return; } if (!m_initialized) { - EXCEPTION_GUARD(m_channelArrayRequester->getLengthDone(notInitializedStatus, thisChannelArray, 0, 0)); + EXCEPTION_GUARD(m_channelArrayRequester->getLengthDone(notInitializedStatus, thisChannelArray, 0)); return; } } if (!startRequest(m_lastRequest.get() ? QOS_DESTROY | QOS_PROCESS : QOS_PROCESS)) { - EXCEPTION_GUARD(m_channelArrayRequester->getLengthDone(otherRequestPendingStatus, thisChannelArray, 0, 0)); + EXCEPTION_GUARD(m_channelArrayRequester->getLengthDone(otherRequestPendingStatus, thisChannelArray, 0)); return; } @@ -1873,7 +1869,7 @@ namespace epics { m_channel->checkAndGetTransport()->enqueueSendRequest(shared_from_this()); } catch (std::runtime_error &rte) { stopRequest(); - EXCEPTION_GUARD(m_channelArrayRequester->getLengthDone(channelNotConnected, thisChannelArray, 0, 0)); + EXCEPTION_GUARD(m_channelArrayRequester->getLengthDone(channelNotConnected, thisChannelArray, 0)); } } diff --git a/src/server/responseHandlers.cpp b/src/server/responseHandlers.cpp index 7dc672b..341e6c1 100644 --- a/src/server/responseHandlers.cpp +++ b/src/server/responseHandlers.cpp @@ -1801,8 +1801,7 @@ void ServerArrayHandler::handleResponse(osiSockAddr* responseFrom, else if (setLength) { size_t length = SerializeHelper::readSize(payloadBuffer, transport.get()); - size_t capacity = SerializeHelper::readSize(payloadBuffer, transport.get()); - request->getChannelArray()->setLength(length, capacity); + request->getChannelArray()->setLength(length); } else if (getLength) { @@ -1909,13 +1908,12 @@ void ServerChannelArrayRequesterImpl::setLengthDone(const Status& status, Channe } void ServerChannelArrayRequesterImpl::getLengthDone(const Status& status, ChannelArray::shared_pointer const & /*channelArray*/, - size_t length, size_t capacity) + size_t length) { { Lock guard(_mutex); _status = status; _length = length; - _capacity = capacity; } TransportSender::shared_pointer thisSender = shared_from_this(); _transport->enqueueSendRequest(thisSender); @@ -1987,7 +1985,6 @@ void ServerChannelArrayRequesterImpl::send(ByteBuffer* buffer, TransportSendCont { //Lock guard(_mutex); SerializeHelper::writeSize(_length, buffer, control); - SerializeHelper::writeSize(_capacity, buffer, control); } else if ((QOS_INIT & request) != 0) { diff --git a/src/server/responseHandlers.h b/src/server/responseHandlers.h index 2b32846..94ee96f 100644 --- a/src/server/responseHandlers.h +++ b/src/server/responseHandlers.h @@ -584,7 +584,7 @@ namespace pvAccess { void putArrayDone(const epics::pvData::Status& status, ChannelArray::shared_pointer const & channelArray); void setLengthDone(const epics::pvData::Status& status, ChannelArray::shared_pointer const & channelArray); void getLengthDone(const epics::pvData::Status& status, ChannelArray::shared_pointer const & channelArray, - std::size_t length, std::size_t capacity); + std::size_t length); void lock(); void unlock(); void destroy(); @@ -605,7 +605,6 @@ namespace pvAccess { epics::pvData::PVArray::shared_pointer _pvPutArray; std::size_t _length; - std::size_t _capacity; epics::pvData::Status _status; }; diff --git a/testApp/remote/channelAccessIFTest.cpp b/testApp/remote/channelAccessIFTest.cpp index dbb307e..740449e 100755 --- a/testApp/remote/channelAccessIFTest.cpp +++ b/testApp/remote/channelAccessIFTest.cpp @@ -43,9 +43,9 @@ std::string ChannelAccessIFTest::TEST_ARRAY_CHANNEL_NAME = "testArray1"; int ChannelAccessIFTest::runAllTest() { #ifdef ENABLE_STRESS_TESTS - testPlan(159); + testPlan(158); #else - testPlan(154); + testPlan(153); #endif test_implementation(); @@ -1904,7 +1904,7 @@ void ChannelAccessIFTest::test_channelArray() { //testOk(data1[2] == 2.2 , "%s: check 2: %f", CURRENT_FUNCTION, data1[2]); - succStatus = arrayReq->syncSetLength(false, 3, 0, getTimeoutSec()); + succStatus = arrayReq->syncSetLength(false, 3, getTimeoutSec()); if (!succStatus) { testFail("%s: an array setLength failed ", CURRENT_FUNCTION); return; @@ -1925,9 +1925,8 @@ 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, currentLength, newCap, getTimeoutSec()); + size_t newLength = 2; + succStatus = arrayReq->syncSetLength(false, newLength, getTimeoutSec()); if (!succStatus) { testFail("%s: an array setLength failed (2) ", CURRENT_FUNCTION); return; @@ -1942,14 +1941,14 @@ void ChannelAccessIFTest::test_channelArray() { //checking 1.1 2.2 PVDoubleArrayPtr array3 = static_pointer_cast(arrayReq->getArray()); PVDoubleArray::const_svector data3(array3->view()); - testOk(data3.size() == newCap, - "%s: data size after calling setLength should be %zu", CURRENT_FUNCTION, newCap); + testOk(data3.size() == newLength, + "%s: data size after calling setLength should be %zu", CURRENT_FUNCTION, newLength); testOk(data3[0] == 1.1 , "%s: 3.check 0: %f", CURRENT_FUNCTION, data3[0]); testOk(data3[1] == 2.2 , "%s: 3.check 1: %f", CURRENT_FUNCTION, data3[1]); size_t bigCapacity = 10000; - succStatus = arrayReq->syncSetLength(false, bigCapacity, bigCapacity, getTimeoutSec()); + succStatus = arrayReq->syncSetLength(false, bigCapacity, getTimeoutSec()); if (!succStatus) { testFail("%s: an array setLength failed (3) ", CURRENT_FUNCTION); return; @@ -1985,9 +1984,8 @@ void ChannelAccessIFTest::test_channelArray() { } */ - // test setLength with capacity 0 (no change) and getLength size_t newLen = bigCapacity/2; - succStatus = arrayReq->syncSetLength(false, newLen, bigCapacity, getTimeoutSec()); + succStatus = arrayReq->syncSetLength(false, newLen, getTimeoutSec()); if (!succStatus) { testFail("%s: an array setLength failed (4) ", CURRENT_FUNCTION); return; @@ -1998,7 +1996,6 @@ void ChannelAccessIFTest::test_channelArray() { return; } testOk(arrayReq->getLength() == newLen, "%s: retrieved length should be %zu", CURRENT_FUNCTION, newLen); - testOk(arrayReq->getCapacity() == bigCapacity, "%s: retrieved capacity should be %zu", CURRENT_FUNCTION, bigCapacity); channel->destroy(); @@ -2045,7 +2042,7 @@ void ChannelAccessIFTest::test_channelArrayTestNoConnection() { } - succStatus = arrayReq->syncSetLength(false, 1, 2, getTimeoutSec()); + succStatus = arrayReq->syncSetLength(false, 1, getTimeoutSec()); if (succStatus) { testFail("%s: an array syncSetLength should fail after the channel had been destroyed ", CURRENT_FUNCTION); } diff --git a/testApp/remote/syncTestRequesters.h b/testApp/remote/syncTestRequesters.h index c875cca..8a4ae56 100755 --- a/testApp/remote/syncTestRequesters.h +++ b/testApp/remote/syncTestRequesters.h @@ -1261,7 +1261,7 @@ class SyncChannelArrayRequesterImpl : public ChannelArrayRequester, public SyncB } - bool syncSetLength(bool lastRequest, size_t length, size_t capacity, long timeOut) + bool syncSetLength(bool lastRequest, size_t length, long timeOut) { if (!getConnectedStatus()) { @@ -1271,7 +1271,7 @@ class SyncChannelArrayRequesterImpl : public ChannelArrayRequester, public SyncB resetEvent(); if (lastRequest) m_channelArray->lastRequest(); - m_channelArray->setLength(length, capacity); + m_channelArray->setLength(length); return waitUntilSetLengthDone(timeOut); } @@ -1390,7 +1390,7 @@ class SyncChannelArrayRequesterImpl : public ChannelArrayRequester, public SyncB virtual void getLengthDone(const epics::pvData::Status& status, ChannelArray::shared_pointer const & channelArray, - size_t length, size_t capacity) + size_t length) { if (m_debug) std::cout << getRequesterName() << ".getLengthDone(" << status << ")" << std::endl; @@ -1399,7 +1399,6 @@ class SyncChannelArrayRequesterImpl : public ChannelArrayRequester, public SyncB m_channelArray = channelArray; m_length = length; - m_capacity = capacity; m_lengthArrayStatus = status.isSuccess(); signalEvent(); @@ -1410,11 +1409,6 @@ class SyncChannelArrayRequesterImpl : public ChannelArrayRequester, public SyncB return m_length; } - size_t getCapacity() - { - return m_capacity; - } - private: bool waitUntilGetArrayDone(double timeOut) @@ -1478,7 +1472,6 @@ class SyncChannelArrayRequesterImpl : public ChannelArrayRequester, public SyncB ChannelArray::shared_pointer m_channelArray; epics::pvData::PVArray::shared_pointer m_pvArray; size_t m_length; - size_t m_capacity; }; #endif diff --git a/testApp/remote/testRemoteClientImpl.cpp b/testApp/remote/testRemoteClientImpl.cpp index d2b8942..dcb54e5 100644 --- a/testApp/remote/testRemoteClientImpl.cpp +++ b/testApp/remote/testRemoteClientImpl.cpp @@ -290,9 +290,9 @@ class ChannelArrayRequesterImpl : public ChannelArrayRequester } virtual void getLengthDone(const epics::pvData::Status& status, ChannelArray::shared_pointer const &, - size_t length, size_t capacity) + size_t length) { - std::cout << "getLengthDone(" << status << "," << length << "," << capacity << ")" << std::endl; + std::cout << "getLengthDone(" << status << "," << length << ")" << std::endl; } }; @@ -475,7 +475,7 @@ int main() // TODO !!! //channelArray->putArray(0,0,1); //epicsThreadSleep ( SLEEP_TIME ); - channelArray->setLength(3,4); + channelArray->setLength(3); epicsThreadSleep ( SLEEP_TIME ); channelArray->getLength(); epicsThreadSleep ( SLEEP_TIME ); diff --git a/testApp/remote/testServer.cpp b/testApp/remote/testServer.cpp index c8ab719..da3fc57 100644 --- a/testApp/remote/testServer.cpp +++ b/testApp/remote/testServer.cpp @@ -1812,10 +1812,12 @@ public: // TODO stride support if (stride == 1) { - - size_t o = offset; - if (count == 0) count = pvArray->getLength(); + + size_t len = pvArray->getLength(); + + size_t o = offset < len ? offset : len; size_t c = count; + if (c == 0 || ((o + c) > len)) c = len - o; Field::const_shared_pointer field = pvArray->getField(); Type type = field->getType(); @@ -1916,16 +1918,9 @@ public: destroy(); } - virtual void setLength(size_t length, size_t capacity) + virtual void setLength(size_t length) { - if (capacity > 0) { - m_pvStructureArray->setCapacity(capacity); - m_pvStructureArray->setLength(length > capacity ? capacity : length); - } - else - { - m_pvStructureArray->setLength(length); - } + m_pvStructureArray->setLength(length); m_channelArrayRequester->setLengthDone(Status::Ok, shared_from_this()); @@ -1937,7 +1932,7 @@ public: { m_channelArrayRequester->getLengthDone(Status::Ok, shared_from_this(), - m_pvStructureArray->getLength(), m_pvStructureArray->getCapacity()); + m_pvStructureArray->getLength()); if (m_lastRequest.get()) destroy();