Add Context::request() builder

This commit is contained in:
Michael Davidsaver
2020-07-26 20:46:12 -07:00
parent e36db5527c
commit 2d475eed74
2 changed files with 39 additions and 14 deletions
+29
View File
@@ -184,6 +184,7 @@ class GetBuilder;
class PutBuilder;
class RPCBuilder;
class MonitorBuilder;
class RequestBuilder;
/** An independent PVA protocol client instance
*
@@ -352,6 +353,23 @@ public:
inline
MonitorBuilder monitor(const std::string& pvname);
/** Compose a pvRequest independently of a network operation.
*
* This is not a network operation.
*
* Use of request() is optional. pvRequests can be composed
* with individual network operation Builders.
*
* @code
* Value pvReq = Context::request()
* .pvRequest("field(value)field(blah)")
* .record("pipeline", true)
* .build();
* @endcode
*/
static inline
RequestBuilder request();
/** Request prompt search of any disconnected channels.
*
* Optional. Equivalent to detection of a new server.
@@ -612,6 +630,17 @@ public:
};
MonitorBuilder Context::monitor(const std::string& name) { return MonitorBuilder{pvt, name}; }
class RequestBuilder : public detail::CommonBuilder<RequestBuilder, detail::CommonBase>
{
public:
RequestBuilder() :CommonBuilder{nullptr,std::string()} {}
//! Return composed pvRequest
Value build() const {
return _buildReq();
}
};
RequestBuilder Context::request() { return RequestBuilder{}; }
struct PVXS_API Config {
//! List of unicast and broadcast addresses
std::vector<std::string> addressList;
+10 -14
View File
@@ -28,10 +28,6 @@ struct TestBuilder : client::detail::CommonBuilder<TestBuilder, client::detail::
:client::detail::CommonBuilder<TestBuilder, client::detail::PRBase>(nullptr, "")
{}
Value makeReq() const {
return _buildReq();
}
template<typename T>
TestBuilder& set(const std::string& name, const T& val, bool required=true) {
const typename impl::StoreAs<T>::store_t& norm(impl::StoreTransform<T>::in(val));
@@ -52,7 +48,7 @@ void testEmpty()
{
testShow()<<__func__;
auto req = TestBuilder().makeReq();
auto req = client::Context::request().build();
testShow()<<req;
testStrEq(std::string(SB()<<req),
@@ -67,12 +63,12 @@ void testAssemble()
{
testShow()<<__func__;
auto req = TestBuilder()
auto req = client::Context::request()
.field("foo")
.field("bar.baz")
.record("abc", "xyz")
.record("pipeline", true)
.makeReq();
.build();
testShow()<<req;
testStrEq(std::string(SB()<<req),
@@ -99,9 +95,9 @@ void testParse1()
{
testShow()<<__func__;
auto req = TestBuilder()
auto req = client::Context::request()
.pvRequest("field(foo)field(bar.baz)record[abc=xyz]record[pipeline=true]")
.makeReq();
.build();
testShow()<<req;
testStrEq(std::string(SB()<<req),
@@ -128,9 +124,9 @@ void testParse2()
{
testShow()<<__func__;
auto req = TestBuilder()
auto req = client::Context::request()
.pvRequest("field(foo,bar.baz)record[abc=xyz,pipeline=true]")
.makeReq();
.build();
testShow()<<req;
testStrEq(std::string(SB()<<req),
@@ -170,7 +166,7 @@ void testValid()
for(auto& pvr : valid) {
try {
testCase(true)<<pvr<<"\n"<<TestBuilder().pvRequest(pvr).makeReq();
testCase(true)<<pvr<<"\n"<<client::Context::request().pvRequest(pvr).build();
}catch(std::exception& e){
testCase(false)<<pvr<<" : "<<typeid(e).name()<<" : "<<e.what();
}
@@ -198,9 +194,9 @@ void testError()
for(auto& pvr : errors) {
testThrows<std::runtime_error>([&pvr](){
auto req = TestBuilder()
auto req = client::Context::request()
.pvRequest(pvr)
.makeReq();
.build();
testShow()<<req;
})<<pvr;
}