Add function Device::isMethodSupported()
This function both checks if a method is supported and also "upmask" a method if it was masked previously.
This commit is contained in:
parent
35dbc0a980
commit
2368b6e564
2 changed files with 30 additions and 15 deletions
|
@ -148,23 +148,11 @@ int Device::doAction(int action, unsigned char data, Controller *controller) {
|
|||
return TELLSTICK_ERROR_CONFIG_SYNTAX;
|
||||
}
|
||||
// Try to determine if we need to call another method due to masking
|
||||
int methods = p->methods();
|
||||
if ((action & methods) == 0) {
|
||||
// Loop all methods an see if any method masks to this one
|
||||
for(int i = 1; i <= methods; i <<= 1) {
|
||||
if ((i & methods) == 0) {
|
||||
continue;
|
||||
}
|
||||
if (this->maskUnsupportedMethods(i, action)) {
|
||||
action = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((action & methods) == 0) {
|
||||
int method = this->isMethodSupported(action);
|
||||
if (method <= 0) {
|
||||
return TELLSTICK_ERROR_METHOD_NOT_SUPPORTED;
|
||||
}
|
||||
std::string code = p->getStringForMethod(action, data, controller);
|
||||
std::string code = p->getStringForMethod(method, data, controller);
|
||||
if (code == "") {
|
||||
return TELLSTICK_ERROR_METHOD_NOT_SUPPORTED;
|
||||
}
|
||||
|
@ -189,6 +177,32 @@ int Device::doAction(int action, unsigned char data, Controller *controller) {
|
|||
return controller->send(code);
|
||||
}
|
||||
|
||||
int Device::isMethodSupported(int method) const {
|
||||
Protocol *p = this->retrieveProtocol();
|
||||
if (!p) {
|
||||
// Syntax error in configuration, no such protocol
|
||||
return TELLSTICK_ERROR_CONFIG_SYNTAX;
|
||||
}
|
||||
// Try to determine if we need to call another method due to masking
|
||||
int methods = p->methods();
|
||||
if ((method & methods) == 0) {
|
||||
// Loop all methods an see if any method masks to this one
|
||||
for(int i = 1; i <= methods; i <<= 1) {
|
||||
if ((i & methods) == 0) {
|
||||
continue;
|
||||
}
|
||||
if (this->maskUnsupportedMethods(i, method)) {
|
||||
method = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((method & methods) == 0) {
|
||||
return TELLSTICK_ERROR_METHOD_NOT_SUPPORTED;
|
||||
}
|
||||
return method;
|
||||
}
|
||||
|
||||
Protocol* Device::retrieveProtocol() const {
|
||||
if (d->protocol) {
|
||||
return d->protocol;
|
||||
|
|
|
@ -19,6 +19,7 @@ public:
|
|||
~Device(void);
|
||||
|
||||
int doAction(int action, unsigned char data, Controller *controller);
|
||||
int isMethodSupported(int method) const;
|
||||
std::wstring getStateValue();
|
||||
int getLastSentCommand(int methodsSupported);
|
||||
int getMethods() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue