From abfcb819eda12c8032a5e4969d401e5b456068cd Mon Sep 17 00:00:00 2001 From: Ren RenJuan Date: Sat, 11 Jan 2014 19:56:19 +0000 Subject: [PATCH] migrate original XMLRPC-C stuff --- APIG/Makefile | 5 ++ APIG/client/coretestbucket.cpp | 117 +++++++++++++++++++++++++++++++ APIG/client/mdClientBehavior.cpp | 21 ++++++ APIG/client/mdClientState.cpp | 37 ++++++++++ APIG/include/mdClientBehavior.h | 33 +++++++++ APIG/include/mdClientState.h | 39 +++++++++++ 6 files changed, 252 insertions(+) create mode 100644 APIG/client/coretestbucket.cpp create mode 100644 APIG/client/mdClientBehavior.cpp create mode 100644 APIG/client/mdClientState.cpp create mode 100644 APIG/include/mdClientBehavior.h create mode 100644 APIG/include/mdClientState.h diff --git a/APIG/Makefile b/APIG/Makefile index 0f76e7c..7e9e34d 100644 --- a/APIG/Makefile +++ b/APIG/Makefile @@ -64,6 +64,11 @@ build/commander.o: client/commander.cpp include/mdCommander.h build/$(CLIENT)-cd: $(ACOBJS) $(CC) $(CFLAGS) -o build/$(CLIENT)-cd $(SINCL) $(LIBS) $(ACOBJS) $(SLIBS) +build/apig-cli: build/mdClientBehavior.o build/mdClientState.o build/mdClientDevice.o \ + build/tools.o build/coretestbucket.o client/apig-cli.cpp + $(CC) $(CFLAGS) client/apig-cli.cpp $(CLIBS) $(CINCL) -o build/apig-cli build/tools.o build/coretestbucket.o \ + build/mdClientBehavior.o build/mdClientState.o build/mdClientDevice.o + doxygen/index.html: etc/doxygen.config doxygen etc/doxygen.config diff --git a/APIG/client/coretestbucket.cpp b/APIG/client/coretestbucket.cpp new file mode 100644 index 0000000..2666d0b --- /dev/null +++ b/APIG/client/coretestbucket.cpp @@ -0,0 +1,117 @@ + +#include "mdclient.h" + +using namespace std; + +typedef struct _DE { + char sig; + const char * name; } newDEs; + + // Test bogus name last. + const char *predefinedObservables[5] = { "spintime", "omega-squared", "pressure", "temperature", "adsfasdf" }; + const char *randomValues[4] = { "333.333", "111.111", "34.43", "7777.777" }; + const char *requiredCmdSubSys[2] = { "SYSTEM", "STATUS" }; + string debug1,debug2,success("OK"); + newDEs otherP1Elements[6] = { {'d', "absorbance"}, {'d', "acceleration"}, + {'b', "_powered" }, {'t', "_uptime"}, + {'i', "_vacuum" }, {'d', "_rotorspeed"} + }; + +void mdCoreAPITestSuite::bucket01(char const *title) { + + phase = string("core API test bucket"); + + int nTests=(sizeof(predefinedObservables)/sizeof(char *)),variation; + XmlRpcValue focus,gotten[nTests]; + cout << "\nTest Bucket: " << title << endl; + + // Get predefined data and test a bogus dataname + + for ( variation=0; variation < nTests; variation++) { + + cout << ".Get '" << predefinedObservables[variation] << "'\n"; + gotten[variation] = testState->get(mdServerHandle,predefinedObservables[variation]).getStruct(); + focus = gotten[variation].structGetValue("dataname"); + if (variation < (nTests - 1)) + TEST(focus.getString() == string(predefinedObservables[variation])); + else TEST(focus.getString() == string("not found")); + + } + + // Set to some value. + + for (variation=0;variation < (nTests - 1);variation++) { + cout << ".Set '" << predefinedObservables[variation] << "'\n"; + gotten[variation].structSetValue("sValue",XmlRpcValue::makeString(randomValues[variation])); + TEST(string("OK") == testState->set(mdServerHandle,gotten[variation])); + } + + // Get and compare. + + for ( variation=0; variation < (nTests -1); variation++) { + + cout << ".Cmp '" << predefinedObservables[variation] << "'\n"; + gotten[variation] = testState->get(mdServerHandle,predefinedObservables[variation]).getStruct(); + focus = gotten[variation].structGetValue("sValue"); + debug1 = focus.getString(); + debug2 = string(randomValues[variation]); + TEST(focus.getString() == string(randomValues[variation])); + + } + +} +void mdCoreAPITestSuite::bucket02(char const *title) { + + int nRequired=(sizeof(requiredCmdSubSys)/sizeof(char *)),nthCmd=0,i,found=0; + XmlRpcValue response; + cout << "\nTest Bucket: " << title << endl; + + response = testBehavior->getCommandList(mdServerHandle,string("")).getArray(); + + TEST(response.arraySize() >= nRequired); + + for (nthCmd = 0; nthCmd < response.arraySize(); nthCmd++) { + for (i=0;icreate(mdServerHandle,newType,otherP1Elements[nthNew].name)); + + } + + cout << "Note: you cannot run this bucket again without restarting MD." << endl; + +} +void mdCoreAPITestSuite::bucket04(char const *title) { + + cout << "\nTest Bucket: " << title << " test variations not implemented yet." << endl; + +} +void mdCoreAPITestSuite::bucket05(char const *title) { + + cout << "\nTest Bucket: " << title << " test variations not implemented yet." << endl; + +} +void mdCoreAPITestSuite::bucket06(char const *title) { + + cout << "\nTest Bucket: " << title << " test variations not implemented yet.\n" << endl; + +} diff --git a/APIG/client/mdClientBehavior.cpp b/APIG/client/mdClientBehavior.cpp new file mode 100644 index 0000000..60c51d6 --- /dev/null +++ b/APIG/client/mdClientBehavior.cpp @@ -0,0 +1,21 @@ +// mdClientBehavior.cc - xmlrpc-c C++ proxy class +// Auto-generated by xml-rpc-api2cpp. + +#include +#include "mdClientBehavior.h" + +XmlRpcValue /*array*/ mdClientBehavior::getCommandList (XmlRpcValue::int32 const int1, std::string const string2) { + XmlRpcValue params(XmlRpcValue::makeArray()); + params.arrayAppendItem(XmlRpcValue::makeInt(int1)); + params.arrayAppendItem(XmlRpcValue::makeString(string2)); + XmlRpcValue result(this->mClient.call("behavior.getCommandList", params)); + return result; +} + +std::string mdClientBehavior::command (XmlRpcValue::int32 const int1, XmlRpcValue /*struct*/ struct2) { + XmlRpcValue params(XmlRpcValue::makeArray()); + params.arrayAppendItem(XmlRpcValue::makeInt(int1)); + params.arrayAppendItem(struct2); + XmlRpcValue result(this->mClient.call("behavior.command", params)); + return result.getString(); +} diff --git a/APIG/client/mdClientState.cpp b/APIG/client/mdClientState.cpp new file mode 100644 index 0000000..ae2926e --- /dev/null +++ b/APIG/client/mdClientState.cpp @@ -0,0 +1,37 @@ +// mdClientState.cc - xmlrpc-c C++ proxy class +// Auto-generated by xml-rpc-api2cpp. + +#include +#include "mdClientState.h" + +XmlRpcValue::int32 mdClientState::getMDversion (std::string const string1) { + XmlRpcValue params(XmlRpcValue::makeArray()); + params.arrayAppendItem(XmlRpcValue::makeString(string1)); + XmlRpcValue result(this->mClient.call("state.getMDversion", params)); + return result.getInt(); +} + +std::string mdClientState::create (XmlRpcValue::int32 const int1, std::string const string2, std::string const string3) { + XmlRpcValue params(XmlRpcValue::makeArray()); + params.arrayAppendItem(XmlRpcValue::makeInt(int1)); + params.arrayAppendItem(XmlRpcValue::makeString(string2)); + params.arrayAppendItem(XmlRpcValue::makeString(string3)); + XmlRpcValue result(this->mClient.call("state.create", params)); + return result.getString(); +} + +XmlRpcValue /*struct*/ mdClientState::get (XmlRpcValue::int32 const int1, std::string const string2) { + XmlRpcValue params(XmlRpcValue::makeArray()); + params.arrayAppendItem(XmlRpcValue::makeInt(int1)); + params.arrayAppendItem(XmlRpcValue::makeString(string2)); + XmlRpcValue result(this->mClient.call("state.get", params)); + return result; +} + +std::string mdClientState::set (XmlRpcValue::int32 const int1, XmlRpcValue /*struct*/ struct2) { + XmlRpcValue params(XmlRpcValue::makeArray()); + params.arrayAppendItem(XmlRpcValue::makeInt(int1)); + params.arrayAppendItem(struct2); + XmlRpcValue result(this->mClient.call("state.set", params)); + return result.getString(); +} diff --git a/APIG/include/mdClientBehavior.h b/APIG/include/mdClientBehavior.h new file mode 100644 index 0000000..b139085 --- /dev/null +++ b/APIG/include/mdClientBehavior.h @@ -0,0 +1,33 @@ +// mdClientBehavior.h - xmlrpc-c C++ proxy class +// Auto-generated by xml-rpc-api2cpp. + +#ifndef _mdClientBehavior_H_ +#define _mdClientBehavior_H_ 1 + +#include + +class mdClientBehavior { + XmlRpcClient mClient; + +public: + mdClientBehavior (const XmlRpcClient& client) + : mClient(client) {} + mdClientBehavior (const std::string& server_url) + : mClient(XmlRpcClient(server_url)) {} + mdClientBehavior (const mdClientBehavior& o) + : mClient(o.mClient) {} + + mdClientBehavior& operator= (const mdClientBehavior& o) { + if (this != &o) mClient = o.mClient; + return *this; + } + + /* Send handle, and the SCPI subsystem or subcommand. Use empty string to get the full subsystem list. Reply will be an array of the available command/subsystems */ + XmlRpcValue /*array*/ getCommandList (XmlRpcValue::int32 const int1, std::string const string2); + + /* Send the full text of a SCPI command and the device handle of the device to process it. If the command is valid MD answers OK and in that case the command will be sent to specified device, otherwise answers error text. Whether or not the OK indicates anything other than a valid command depends on the configured behavior of the device. */ + std::string command (XmlRpcValue::int32 const int1, XmlRpcValue /*struct*/ struct2); +}; + +#endif /* _mdClientBehavior_H_ */ + diff --git a/APIG/include/mdClientState.h b/APIG/include/mdClientState.h new file mode 100644 index 0000000..e8356d6 --- /dev/null +++ b/APIG/include/mdClientState.h @@ -0,0 +1,39 @@ +// mdClientState.h - xmlrpc-c C++ proxy class +// Auto-generated by xml-rpc-api2cpp. + +#ifndef _mdClientState_H_ +#define _mdClientState_H_ 1 + +#include + +class mdClientState { + XmlRpcClient mClient; + +public: + mdClientState (const XmlRpcClient& client) + : mClient(client) {} + mdClientState (const std::string& server_url) + : mClient(XmlRpcClient(server_url)) {} + mdClientState (const mdClientState& o) + : mClient(o.mClient) {} + + mdClientState& operator= (const mdClientState& o) { + if (this != &o) mClient = o.mClient; + return *this; + } + + /* Accepts a device handle and returns the version identification of the MD. */ + XmlRpcValue::int32 getMDversion (std::string const string1); + + /* Given a device handle, type, and dataname create the element. The type string uses the standard xmplrpc-c single character type signatures which if preceed by an underscore implies an operational data element otherwise it's an observable. Any text following the type signature is preserved as a comment. Answers 'OK' or error text */ + std::string create (XmlRpcValue::int32 const int1, std::string const string2, std::string const string3); + + /* Send handle, dataname, get structure answer. The dataname can be prefixed by a non-alphabetic mode character. The first entry in the structure is always the state of the call which will either the supplied dataname indicating success or error text. The remainder of the structure is specific to the API. */ + XmlRpcValue /*struct*/ get (XmlRpcValue::int32 const int1, std::string const string2); + + /* Process a gotten structure with changes. Answers 'OK' or error text */ + std::string set (XmlRpcValue::int32 const int1, XmlRpcValue /*struct*/ struct2); +}; + +#endif /* _mdClientState_H_ */ +