migrate original XMLRPC-C stuff

This commit is contained in:
Ren RenJuan 2014-01-11 19:56:19 +00:00
parent 40c9248227
commit abfcb819ed
6 changed files with 252 additions and 0 deletions

View File

@ -64,6 +64,11 @@ build/commander.o: client/commander.cpp include/mdCommander.h
build/$(CLIENT)-cd: $(ACOBJS) build/$(CLIENT)-cd: $(ACOBJS)
$(CC) $(CFLAGS) -o build/$(CLIENT)-cd $(SINCL) $(LIBS) $(ACOBJS) $(SLIBS) $(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/index.html: etc/doxygen.config
doxygen etc/doxygen.config doxygen etc/doxygen.config

View File

@ -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;i<nRequired;i++)
if (response.arrayGetItem(nthCmd).getString() == string(requiredCmdSubSys[i])) {
cout << ".Has '" << requiredCmdSubSys[i] << "'\n"; // visually check for dups
found++;
}
}
TEST(found == nRequired);
}
void mdCoreAPITestSuite::bucket03(char const *title) {
int nNew=(sizeof(otherP1Elements)/sizeof(newDEs)),nthNew=0;
std::string newType(" ");
XmlRpcValue response;
cout << "\nTest Bucket: " << title << endl;
for (;nthNew < nNew;nthNew++) {
cout << ".Add '" << otherP1Elements[nthNew].name
<< "' with signature: '" << otherP1Elements[nthNew].sig << "'\n";
newType.replace(0,1,1,otherP1Elements[nthNew].sig);
TEST(success == testState->create(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;
}

View File

@ -0,0 +1,21 @@
// mdClientBehavior.cc - xmlrpc-c C++ proxy class
// Auto-generated by xml-rpc-api2cpp.
#include <xmlrpc-c/oldcppwrapper.hpp>
#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();
}

View File

@ -0,0 +1,37 @@
// mdClientState.cc - xmlrpc-c C++ proxy class
// Auto-generated by xml-rpc-api2cpp.
#include <xmlrpc-c/oldcppwrapper.hpp>
#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();
}

View File

@ -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 <xmlrpc-c/oldcppwrapper.hpp>
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_ */

View File

@ -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 <xmlrpc-c/oldcppwrapper.hpp>
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_ */