Added functions ControllerMessage::msgClass(), ControllerMessage::model(), ControllerMessage::getIntMessage() and ControllerMessage::hasParameter()
This commit is contained in:
parent
0b12c53794
commit
183cc7ca0d
2 changed files with 60 additions and 22 deletions
|
@ -2,12 +2,14 @@
|
||||||
#include "Device.h"
|
#include "Device.h"
|
||||||
#include "Strings.h"
|
#include "Strings.h"
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class ControllerMessage::PrivateData {
|
class ControllerMessage::PrivateData {
|
||||||
public:
|
public:
|
||||||
std::map<std::string, std::string> parameters;
|
std::map<std::string, std::string> parameters;
|
||||||
std::string protocol;
|
std::string protocol, model, msgClass;
|
||||||
int method;
|
int method;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,8 +26,12 @@ ControllerMessage::ControllerMessage(const std::string &message) {
|
||||||
if (delim == std::string::npos) {
|
if (delim == std::string::npos) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (param.substr(0, delim).compare("protocol") == 0) {
|
if (param.substr(0, delim).compare("class") == 0) {
|
||||||
|
d->msgClass = param.substr(delim+1, param.length()-delim);
|
||||||
|
} else if (param.substr(0, delim).compare("protocol") == 0) {
|
||||||
d->protocol = param.substr(delim+1, param.length()-delim);
|
d->protocol = param.substr(delim+1, param.length()-delim);
|
||||||
|
} else if (param.substr(0, delim).compare("model") == 0) {
|
||||||
|
d->model = param.substr(delim+1, param.length()-delim);
|
||||||
} else if (param.substr(0, delim).compare("method") == 0) {
|
} else if (param.substr(0, delim).compare("method") == 0) {
|
||||||
d->method = Device::methodId(param.substr(delim+1, param.length()-delim));
|
d->method = Device::methodId(param.substr(delim+1, param.length()-delim));
|
||||||
} else {
|
} else {
|
||||||
|
@ -39,6 +45,10 @@ ControllerMessage::~ControllerMessage(){
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string ControllerMessage::msgClass() const {
|
||||||
|
return d->msgClass;
|
||||||
|
}
|
||||||
|
|
||||||
int ControllerMessage::method() const {
|
int ControllerMessage::method() const {
|
||||||
return d->method;
|
return d->method;
|
||||||
}
|
}
|
||||||
|
@ -47,10 +57,33 @@ std::wstring ControllerMessage::protocol() const {
|
||||||
return TelldusCore::charToWstring(d->protocol.c_str());
|
return TelldusCore::charToWstring(d->protocol.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ControllerMessage::getParameter(const std::string &key){
|
std::wstring ControllerMessage::model() const {
|
||||||
|
return TelldusCore::charToWstring(d->model.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
int ControllerMessage::getIntParameter(const std::string &key) const {
|
||||||
|
std::string strValue = getParameter(key);
|
||||||
|
if (strValue.compare("") == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (strValue.substr(0,2).compare("0x") == 0) {
|
||||||
|
return strtol(strValue.c_str(), NULL, 16);
|
||||||
|
}
|
||||||
|
return strtol(strValue.c_str(), NULL, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ControllerMessage::getParameter(const std::string &key) const {
|
||||||
std::map<std::string, std::string>::iterator it = d->parameters.find(key);
|
std::map<std::string, std::string>::iterator it = d->parameters.find(key);
|
||||||
if (it == d->parameters.end()) {
|
if (it == d->parameters.end()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return d->parameters[key];
|
return d->parameters[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ControllerMessage::hasParameter(const std::string &key) const {
|
||||||
|
std::map<std::string, std::string>::iterator it = d->parameters.find(key);
|
||||||
|
if (it == d->parameters.end()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -1,20 +1,25 @@
|
||||||
#ifndef CONTROLLERMESSAGE_H
|
#ifndef CONTROLLERMESSAGE_H
|
||||||
#define CONTROLLERMESSAGE_H
|
#define CONTROLLERMESSAGE_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class ControllerMessage {
|
class ControllerMessage {
|
||||||
public:
|
public:
|
||||||
ControllerMessage(const std::string &rawMessage);
|
ControllerMessage(const std::string &rawMessage);
|
||||||
virtual ~ControllerMessage();
|
virtual ~ControllerMessage();
|
||||||
|
|
||||||
std::string getParameter(const std::string &key);
|
std::string msgClass() const;
|
||||||
int method() const;
|
int getIntParameter(const std::string &key) const;
|
||||||
std::wstring protocol() const;
|
std::string getParameter(const std::string &key) const;
|
||||||
|
int method() const;
|
||||||
private:
|
std::wstring protocol() const;
|
||||||
class PrivateData;
|
std::wstring model() const;
|
||||||
PrivateData *d;
|
|
||||||
};
|
bool hasParameter(const std::string &key) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
class PrivateData;
|
||||||
|
PrivateData *d;
|
||||||
|
};
|
||||||
|
|
||||||
#endif //CONTROLLERMESSAGE_H
|
#endif //CONTROLLERMESSAGE_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue