Added parameter int supportedMethods in tdLastSentCommand(), closes #36
This commit is contained in:
parent
33d3e60ebf
commit
fbbb117a05
25 changed files with 71 additions and 94 deletions
|
@ -22,6 +22,9 @@ Device::~Device(void) {
|
|||
|
||||
int Device::switchState( int newState, const std::string &value ) {
|
||||
int retVal = TELLSTICK_ERROR_METHOD_NOT_SUPPORTED;
|
||||
if (!Device::maskUnsupportedMethods(this->methods(), newState)) {
|
||||
return retVal;
|
||||
}
|
||||
std::string stateValue = "";
|
||||
|
||||
switch (newState) {
|
||||
|
@ -128,3 +131,12 @@ bool Device::setName(const std::string & newName) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int TelldusCore::Device::maskUnsupportedMethods(int methods, int supportedMethods) {
|
||||
// Bell -> On
|
||||
if ((methods & TELLSTICK_BELL) && !(supportedMethods & TELLSTICK_BELL)) {
|
||||
methods |= TELLSTICK_TURNON;
|
||||
}
|
||||
//Cut of the rest of the unsupported methods we donät have a fallback for
|
||||
return methods & supportedMethods;
|
||||
}
|
||||
|
|
|
@ -6,12 +6,6 @@
|
|||
|
||||
namespace TelldusCore {
|
||||
|
||||
const int ALL_METHODS =
|
||||
TELLSTICK_TURNON |
|
||||
TELLSTICK_TURNOFF |
|
||||
TELLSTICK_BELL |
|
||||
TELLSTICK_DIM;
|
||||
|
||||
class Device
|
||||
{
|
||||
public:
|
||||
|
@ -19,7 +13,7 @@ namespace TelldusCore {
|
|||
virtual ~Device(void);
|
||||
|
||||
int switchState( int newState, const std::string &value = "" );
|
||||
virtual int methods(int methodsSupported) = 0;
|
||||
virtual int methods() = 0;
|
||||
virtual std::string getProtocol() const = 0;
|
||||
virtual bool parameterMatches( const std::string &name, const std::string &value ) const = 0;
|
||||
bool setParameter(const std::string &strName, const std::string &strValue);
|
||||
|
@ -30,6 +24,7 @@ namespace TelldusCore {
|
|||
bool setName( const std::string &newName );
|
||||
|
||||
static int methodId( const std::string &methodName );
|
||||
static int maskUnsupportedMethods( int methods, int supportedMethods );
|
||||
|
||||
#ifdef _LINUX
|
||||
void setDevice(const std::string &device);
|
||||
|
|
|
@ -87,7 +87,7 @@ bool DeviceBrateck::parameterMatches( const std::string &name, const std::string
|
|||
/*
|
||||
* Has the device got the method?
|
||||
*/
|
||||
int DeviceBrateck::methods(int){
|
||||
int DeviceBrateck::methods(){
|
||||
return (TELLSTICK_TURNON | TELLSTICK_TURNOFF);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace TelldusCore {
|
|||
DeviceBrateck(int id, const std::string &model, const std::string &name);
|
||||
virtual ~DeviceBrateck(void);
|
||||
|
||||
virtual int methods(int methodsSupported);
|
||||
virtual int methods();
|
||||
virtual std::string getProtocol() const;
|
||||
virtual bool parameterMatches( const std::string &name, const std::string &value ) const;
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ int DeviceGroup::turnOn(void) {
|
|||
int retVal = TELLSTICK_ERROR_UNKNOWN;
|
||||
|
||||
for (DeviceList::const_iterator it = deviceList.begin(); it != deviceList.end(); ++it) {
|
||||
int methods = (*it)->methods(ALL_METHODS);
|
||||
int methods = (*it)->methods();
|
||||
if (methods & TELLSTICK_TURNON) {
|
||||
int success = (*it)->switchState( TELLSTICK_TURNON );
|
||||
if (retVal != TELLSTICK_SUCCESS) {
|
||||
|
@ -75,7 +75,7 @@ int DeviceGroup::turnOff(void) {
|
|||
int retVal = TELLSTICK_ERROR_UNKNOWN;
|
||||
|
||||
for (DeviceList::const_iterator it = deviceList.begin(); it != deviceList.end(); ++it) {
|
||||
int methods = (*it)->methods(ALL_METHODS);
|
||||
int methods = (*it)->methods();
|
||||
if (methods & TELLSTICK_TURNOFF) {
|
||||
int success = (*it)->switchState( TELLSTICK_TURNOFF );
|
||||
if (retVal != TELLSTICK_SUCCESS) {
|
||||
|
@ -93,7 +93,7 @@ int DeviceGroup::bell(void){
|
|||
int retVal = TELLSTICK_ERROR_UNKNOWN;
|
||||
|
||||
for (DeviceList::const_iterator it = deviceList.begin(); it != deviceList.end(); ++it) {
|
||||
int methods = (*it)->methods(ALL_METHODS);
|
||||
int methods = (*it)->methods();
|
||||
if (methods & TELLSTICK_BELL) {
|
||||
int success = (*it)->switchState( TELLSTICK_BELL );
|
||||
if (retVal != TELLSTICK_SUCCESS) {
|
||||
|
@ -111,7 +111,7 @@ int DeviceGroup::dim(unsigned char level){
|
|||
int retVal = TELLSTICK_ERROR_UNKNOWN;
|
||||
|
||||
for (DeviceList::const_iterator it = deviceList.begin(); it != deviceList.end(); ++it) {
|
||||
int methods = (*it)->methods(ALL_METHODS);
|
||||
int methods = (*it)->methods();
|
||||
if (methods & TELLSTICK_DIM) {
|
||||
int success = (*it)->switchState( TELLSTICK_DIM, (char*)&level);
|
||||
if (retVal != TELLSTICK_SUCCESS) {
|
||||
|
@ -129,11 +129,11 @@ bool DeviceGroup::parameterMatches( const std::string &name, const std::string &
|
|||
/*
|
||||
* Has the device got the method?
|
||||
*/
|
||||
int DeviceGroup::methods(int supportedMethods){
|
||||
int DeviceGroup::methods(){
|
||||
int retVal = 0;
|
||||
|
||||
for (DeviceList::const_iterator it = deviceList.begin(); it != deviceList.end(); ++it) {
|
||||
retVal = retVal | (*it)->methods(supportedMethods);
|
||||
retVal = retVal | (*it)->methods();
|
||||
}
|
||||
|
||||
return retVal;
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace TelldusCore {
|
|||
DeviceGroup(int id, const std::string &model, const std::string &name);
|
||||
~DeviceGroup(void);
|
||||
|
||||
virtual int methods(int methodsSupported);
|
||||
virtual int methods();
|
||||
virtual std::string getProtocol() const;
|
||||
virtual bool parameterMatches( const std::string &name, const std::string &value ) const;
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ bool DeviceIkea::parameterMatches( const std::string &name, const std::string &v
|
|||
/*
|
||||
* Has the device got the method?
|
||||
*/
|
||||
int DeviceIkea::methods(int){
|
||||
int DeviceIkea::methods(){
|
||||
return (TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_DIM);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace TelldusCore {
|
|||
DeviceIkea(int id, const std::string &model, const std::string &name);
|
||||
virtual ~DeviceIkea(void);
|
||||
|
||||
virtual int methods(int methodsSupported);
|
||||
virtual int methods();
|
||||
virtual std::string getProtocol() const;
|
||||
virtual bool parameterMatches( const std::string &name, const std::string &value ) const;
|
||||
|
||||
|
|
|
@ -63,7 +63,9 @@ bool DeviceNexa::setDeviceParameter(const std::string &strName, const std::strin
|
|||
* Turn on this device
|
||||
*/
|
||||
int DeviceNexa::turnOn(void){
|
||||
|
||||
if (strcasecmp(this->getModel().c_str(), "bell") == 0) {
|
||||
return bell();
|
||||
}
|
||||
try{
|
||||
std::string strCode = "";
|
||||
if (isDimmer()) {
|
||||
|
@ -243,7 +245,7 @@ bool DeviceNexa::parameterMatches( const std::string &name, const std::string &v
|
|||
/*
|
||||
* Has the device got the method?
|
||||
*/
|
||||
int DeviceNexa::methods(int methodsSupported){
|
||||
int DeviceNexa::methods(){
|
||||
std::string strModel = this->getModel();
|
||||
|
||||
if ( strcasecmp(strModel.c_str(), "codeswitch") == 0
|
||||
|
@ -254,11 +256,7 @@ int DeviceNexa::methods(int methodsSupported){
|
|||
return (TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_DIM);
|
||||
|
||||
} else if (strcasecmp(strModel.c_str(), "bell") == 0) {
|
||||
if (methodsSupported & TELLSTICK_BELL) {
|
||||
return TELLSTICK_BELL;
|
||||
} else if (methodsSupported & TELLSTICK_TURNON) {
|
||||
return TELLSTICK_TURNON;
|
||||
}
|
||||
return TELLSTICK_BELL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace TelldusCore {
|
|||
{
|
||||
public:
|
||||
DeviceNexa(int id, const std::string &model, const std::string &name);
|
||||
virtual int methods(int methodsSupported);
|
||||
virtual int methods();
|
||||
virtual std::string getProtocol() const;
|
||||
virtual bool parameterMatches( const std::string &name, const std::string &value ) const;
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ bool DeviceRisingSun::parameterMatches( const std::string &name, const std::stri
|
|||
/*
|
||||
* Has the device got the method?
|
||||
*/
|
||||
int DeviceRisingSun::methods(int methodsSupported){
|
||||
int DeviceRisingSun::methods(){
|
||||
return (TELLSTICK_TURNON | TELLSTICK_TURNOFF);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace TelldusCore {
|
|||
{
|
||||
public:
|
||||
DeviceRisingSun(int id, const std::string &model, const std::string &name);
|
||||
virtual int methods(int methodsSupported);
|
||||
virtual int methods();
|
||||
virtual std::string getProtocol() const;
|
||||
virtual bool parameterMatches( const std::string &name, const std::string &value ) const;
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ bool DeviceSartano::parameterMatches( const std::string &name, const std::string
|
|||
/*
|
||||
* Has the device got the method?
|
||||
*/
|
||||
int DeviceSartano::methods(int){
|
||||
int DeviceSartano::methods(){
|
||||
return (TELLSTICK_TURNON | TELLSTICK_TURNOFF);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace TelldusCore {
|
|||
DeviceSartano(int id, const std::string &model, const std::string &name);
|
||||
virtual ~DeviceSartano(void);
|
||||
|
||||
virtual int methods(int methodsSupported);
|
||||
virtual int methods();
|
||||
virtual std::string getProtocol() const;
|
||||
virtual bool parameterMatches( const std::string &name, const std::string &value ) const;
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ bool DeviceUndefined::parameterMatches( const std::string &name, const std::stri
|
|||
/*
|
||||
* Has the device got the method?
|
||||
*/
|
||||
int DeviceUndefined::methods(int methodsSupported){
|
||||
int DeviceUndefined::methods(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace TelldusCore {
|
|||
{
|
||||
public:
|
||||
DeviceUndefined(int id, const std::string &model, const std::string &name);
|
||||
virtual int methods(int methodsSupported);
|
||||
virtual int methods();
|
||||
virtual std::string getProtocol() const;
|
||||
virtual bool parameterMatches( const std::string &name, const std::string &value ) const;
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ bool DeviceUpm::parameterMatches( const std::string &name, const std::string &va
|
|||
/*
|
||||
* Has the device got the method?
|
||||
*/
|
||||
int DeviceUpm::methods(int){
|
||||
int DeviceUpm::methods(){
|
||||
return (TELLSTICK_TURNON | TELLSTICK_TURNOFF);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace TelldusCore {
|
|||
DeviceUpm(int id, const std::string &model, const std::string &name);
|
||||
virtual ~DeviceUpm(void);
|
||||
|
||||
virtual int methods(int methodsSupported);
|
||||
virtual int methods();
|
||||
virtual std::string getProtocol() const;
|
||||
virtual bool parameterMatches( const std::string &name, const std::string &value ) const;
|
||||
|
||||
|
|
|
@ -39,6 +39,6 @@ int DeviceWaveman::turnOff(void){
|
|||
/*
|
||||
* Has the device got the method?
|
||||
*/
|
||||
int DeviceWaveman::methods(int){
|
||||
int DeviceWaveman::methods(){
|
||||
return (TELLSTICK_TURNON | TELLSTICK_TURNOFF);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace TelldusCore {
|
|||
{
|
||||
public:
|
||||
DeviceWaveman(int id, const std::string &model, const std::string &name);
|
||||
virtual int methods(int methodsSupported);
|
||||
virtual int methods();
|
||||
|
||||
protected:
|
||||
virtual int turnOff(void);
|
||||
|
|
|
@ -193,7 +193,7 @@ bool DeviceX10::parameterMatches( const std::string &name, const std::string &va
|
|||
/*
|
||||
* Has the device got the method?
|
||||
*/
|
||||
int DeviceX10::methods(int methodsSupported){
|
||||
int DeviceX10::methods(){
|
||||
return (TELLSTICK_TURNON | TELLSTICK_TURNOFF);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace TelldusCore {
|
|||
{
|
||||
public:
|
||||
DeviceX10(int id, const std::string &model, const std::string &name);
|
||||
virtual int methods(int methodsSupported);
|
||||
virtual int methods();
|
||||
virtual std::string getProtocol() const;
|
||||
virtual bool parameterMatches( const std::string &name, const std::string &value ) const;
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@ void Manager::parseMessage( const std::string &message ) {
|
|||
if (it->second->getProtocol().compare(protocol) != 0) {
|
||||
continue;
|
||||
}
|
||||
if (! (it->second->methods(ALL_METHODS) & method)) {
|
||||
if (! (it->second->methods() & method)) {
|
||||
continue;
|
||||
}
|
||||
bool found = true;
|
||||
|
|
|
@ -106,17 +106,7 @@ int WINAPI tdTurnOn(int intDeviceId){
|
|||
Manager *manager = Manager::getInstance();
|
||||
Device* dev = manager->getDevice(intDeviceId);
|
||||
if(dev != NULL){
|
||||
int methods = dev->methods( TELLSTICK_TURNON );
|
||||
|
||||
int retval = 0;
|
||||
|
||||
if ( !(methods & TELLSTICK_TURNON) ) {
|
||||
retval = TELLSTICK_ERROR_METHOD_NOT_SUPPORTED;
|
||||
} else {
|
||||
retval = dev->switchState(TELLSTICK_TURNON);
|
||||
}
|
||||
|
||||
return retval;
|
||||
return dev->switchState(TELLSTICK_TURNON);
|
||||
} else{
|
||||
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
|
||||
}
|
||||
|
@ -139,18 +129,8 @@ int WINAPI tdTurnOff(int intDeviceId){
|
|||
Manager *manager = Manager::getInstance();
|
||||
Device* dev = manager->getDevice(intDeviceId);
|
||||
if(dev != NULL){
|
||||
int methods = dev->methods( TELLSTICK_TURNOFF );
|
||||
int retval = 0;
|
||||
|
||||
if ( !(methods & TELLSTICK_TURNOFF) ) {
|
||||
retval = TELLSTICK_ERROR_METHOD_NOT_SUPPORTED;
|
||||
} else {
|
||||
retval = dev->switchState(TELLSTICK_TURNOFF);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
else{
|
||||
return dev->switchState(TELLSTICK_TURNOFF);
|
||||
} else {
|
||||
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
@ -171,19 +151,9 @@ int WINAPI tdBell(int intDeviceId){
|
|||
try{
|
||||
Manager *manager = Manager::getInstance();
|
||||
Device* dev = manager->getDevice(intDeviceId);
|
||||
if(dev != NULL){
|
||||
int methods = dev->methods( TELLSTICK_BELL );
|
||||
int retval = 0;
|
||||
|
||||
if ( !(methods & TELLSTICK_BELL) ) {
|
||||
retval = TELLSTICK_ERROR_METHOD_NOT_SUPPORTED;
|
||||
} else {
|
||||
retval = dev->switchState( TELLSTICK_BELL );
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
else{
|
||||
if (dev != NULL){
|
||||
return dev->switchState( TELLSTICK_BELL );
|
||||
} else {
|
||||
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
@ -205,24 +175,17 @@ int WINAPI tdDim(int intDeviceId, unsigned char level){
|
|||
Manager *manager = Manager::getInstance();
|
||||
Device* dev = manager->getDevice(intDeviceId);
|
||||
if(dev != NULL){
|
||||
int methods = dev->methods( TELLSTICK_DIM );
|
||||
int retval = 0;
|
||||
|
||||
if ( !(methods & TELLSTICK_DIM) ) {
|
||||
retval = TELLSTICK_ERROR_METHOD_NOT_SUPPORTED;
|
||||
if (level == 0) {
|
||||
retval = dev->switchState( TELLSTICK_TURNOFF );
|
||||
} else if (level == 255) {
|
||||
retval = dev->switchState( TELLSTICK_TURNON );
|
||||
} else {
|
||||
if (level == 0) {
|
||||
retval = dev->switchState( TELLSTICK_TURNOFF );
|
||||
} else if (level == 255) {
|
||||
retval = dev->switchState( TELLSTICK_TURNON );
|
||||
} else {
|
||||
retval = dev->switchState( TELLSTICK_DIM, (char *)&level);
|
||||
}
|
||||
retval = dev->switchState( TELLSTICK_DIM, (char *)&level);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
@ -235,12 +198,21 @@ int WINAPI tdDim(int intDeviceId, unsigned char level){
|
|||
/**
|
||||
* Returns the last sent command to a specific device
|
||||
* @param intDeviceId The device id to query
|
||||
* @param methodsSupported The methods supported by the client. See tdMethods() for more information.
|
||||
* @returns the last sent command as integer, example TELLSTICK_TURNON or TELLSTICK_TURNOFF
|
||||
*/
|
||||
int WINAPI tdLastSentCommand( int intDeviceId ) {
|
||||
int WINAPI tdLastSentCommand( int intDeviceId, int methodsSupported ) {
|
||||
Manager *manager = Manager::getInstance();
|
||||
int lastSentCommand = manager->getDeviceState( intDeviceId );
|
||||
return (lastSentCommand > 0 ? lastSentCommand : TELLSTICK_TURNOFF );
|
||||
int lastSentCommand = Device::maskUnsupportedMethods(manager->getDeviceState( intDeviceId ), methodsSupported);
|
||||
|
||||
if (lastSentCommand == TELLSTICK_BELL) {
|
||||
//Bell is not a state
|
||||
lastSentCommand = TELLSTICK_TURNOFF;
|
||||
}
|
||||
if (lastSentCommand == 0) {
|
||||
lastSentCommand = TELLSTICK_TURNOFF;
|
||||
}
|
||||
return lastSentCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -496,14 +468,14 @@ int WINAPI tdMethods(int id, int methodsSupported){
|
|||
Manager *manager = Manager::getInstance();
|
||||
Device* dev = manager->getDevice(id);
|
||||
if (dev != NULL) {
|
||||
intMethods = dev->methods(methodsSupported);
|
||||
intMethods = dev->methods();
|
||||
}
|
||||
}
|
||||
catch(exception e){
|
||||
intMethods = 0;
|
||||
handleException(e);
|
||||
}
|
||||
intMethods = intMethods & methodsSupported; //Strip the methods not supported by client.
|
||||
intMethods = Device::maskUnsupportedMethods(intMethods, methodsSupported); //Strip the methods not supported by client.
|
||||
return intMethods;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ extern "C" {
|
|||
TELLSTICK_API int WINAPI tdBell(int intDeviceId);
|
||||
TELLSTICK_API int WINAPI tdDim(int intDeviceId, unsigned char level);
|
||||
TELLSTICK_API int WINAPI tdMethods(int id, int methodsSupported);
|
||||
TELLSTICK_API int WINAPI tdLastSentCommand( int intDeviceId );
|
||||
TELLSTICK_API int WINAPI tdLastSentCommand( int intDeviceId, int methodsSupported );
|
||||
TELLSTICK_API char *WINAPI tdLastSentValue( int intDeviceId );
|
||||
|
||||
TELLSTICK_API int WINAPI tdGetNumberOfDevices();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue