Added namespace 'TelldusCore' to classes in library telldus-core

This commit is contained in:
Micke Prag 2009-01-07 21:14:59 +00:00
parent df4615f8f8
commit f1e9f2f9f2
14 changed files with 144 additions and 114 deletions

View file

@ -1,11 +1,12 @@
#include "Device.h" #include "Device.h"
#include <stdlib.h> #include <stdlib.h>
using namespace TelldusCore;
/* /*
* Constructor * Constructor
*/ */
Device::Device(int model) Device::Device(int m)
: model(model) : model(m)
{ {
} }

View file

@ -4,30 +4,34 @@
#include <string> #include <string>
//#include <QMutex> //#include <QMutex>
class Device namespace TelldusCore {
{
public:
Device(int model);
~Device(void);
virtual int turnOn(void);
virtual int turnOff(void);
virtual int bell(void);
virtual int dim(unsigned char level);
virtual int methods(int methodsSupported) = 0;
virtual std::string getProtocol() = 0;
int getModel();
#ifdef _LINUX
void setDevice(const std::string &device);
protected:
std::string strDevice;
#endif
protected: class Device
int send(const std::string &strMessage); {
public:
Device(int model);
~Device(void);
virtual int turnOn(void);
virtual int turnOff(void);
virtual int bell(void);
virtual int dim(unsigned char level);
virtual int methods(int methodsSupported) = 0;
virtual std::string getProtocol() = 0;
int getModel();
#ifdef _LINUX
void setDevice(const std::string &device);
protected:
std::string strDevice;
#endif
protected:
int send(const std::string &strMessage);
private:
int model;
// static QMutex deviceMutex;
};
private: }
int model;
// static QMutex deviceMutex;
};

View file

@ -10,6 +10,8 @@
#define strcasecmp(x, y) _strcmpi(x, y) #define strcasecmp(x, y) _strcmpi(x, y)
#endif #endif
using namespace TelldusCore;
/* /*
* Constructor * Constructor
*/ */

View file

@ -2,23 +2,26 @@
#include "Device.h" #include "Device.h"
#include <string> #include <string>
class DeviceIkea : public Device namespace TelldusCore {
{
public: class DeviceIkea : public Device
DeviceIkea(int model, const std::string &strSystem, const std::string &strUnits, const std::string &strFadeStyle); {
virtual int turnOn(void); public:
virtual int turnOff(void); DeviceIkea(int model, const std::string &strSystem, const std::string &strUnits, const std::string &strFadeStyle);
virtual int dim(unsigned char level); virtual int turnOn(void);
virtual int methods(int methodsSupported); virtual int turnOff(void);
virtual std::string getProtocol(); virtual int dim(unsigned char level);
virtual int methods(int methodsSupported);
virtual std::string getProtocol();
public:
~DeviceIkea(void);
public: protected:
~DeviceIkea(void); int intSystem;
int intUnits;
protected: int intFadeStyle;
int intSystem; std::string getStringCode(unsigned char);
int intUnits; };
int intFadeStyle;
std::string getStringCode(unsigned char); }
};

View file

@ -6,6 +6,8 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
using namespace TelldusCore;
/* /*
* Constructor * Constructor
*/ */

View file

@ -2,22 +2,25 @@
#include "Device.h" #include "Device.h"
#include <string> #include <string>
class DeviceNexa : public Device namespace TelldusCore {
{
public:
DeviceNexa(int model, const std::string &strHouse, const std::string &strCode);
virtual int turnOn(void);
virtual int turnOff(void);
virtual int bell(void);
virtual int methods(int methodsSupported);
virtual std::string getProtocol();
public: class DeviceNexa : public Device
~DeviceNexa(void); {
public:
protected: DeviceNexa(int model, const std::string &strHouse, const std::string &strCode);
int intHouse; virtual int turnOn(void);
int intCode; virtual int turnOff(void);
std::string getStringCode(int); virtual int bell(void);
}; virtual int methods(int methodsSupported);
virtual std::string getProtocol();
public:
~DeviceNexa(void);
protected:
int intHouse;
int intCode;
std::string getStringCode(int);
};
}

View file

@ -5,7 +5,7 @@
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
using namespace std; using namespace TelldusCore;
/* /*
* Constructor * Constructor
@ -70,7 +70,7 @@ int DeviceSartano::methods(int){
/* /*
* Convert an integer to byte string where 0 is represented by $k and 1 by k$, reversed and padded with 0's as needed * Convert an integer to byte string where 0 is represented by $k and 1 by k$, reversed and padded with 0's as needed
*/ */
string DeviceSartano::getStringCode(void){ std::string DeviceSartano::getStringCode(void){
std::string strReturn = strCode; std::string strReturn = strCode;

View file

@ -2,19 +2,22 @@
#include "Device.h" #include "Device.h"
#include <string> #include <string>
namespace TelldusCore {
class DeviceSartano : public Device class DeviceSartano : public Device
{ {
public: public:
DeviceSartano(int model, const std::string &strCode); DeviceSartano(int model, const std::string &strCode);
virtual int turnOn(void); virtual int turnOn(void);
virtual int turnOff(void); virtual int turnOff(void);
virtual int methods(int methodsSupported); virtual int methods(int methodsSupported);
virtual std::string getProtocol(); virtual std::string getProtocol();
~DeviceSartano(void);
protected:
std::string getStringCode(void);
std::string strCode;
};
~DeviceSartano(void); }
protected:
std::string getStringCode(void);
std::string strCode;
};

View file

@ -6,7 +6,7 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
using namespace std; using namespace TelldusCore;
/* /*
* Constructor * Constructor
@ -21,8 +21,8 @@ DeviceWaveman::DeviceWaveman(int model, const std::string &strHouse, const std::
int DeviceWaveman::turnOff(void){ int DeviceWaveman::turnOff(void){
try{ try{
string strCode = getStringCode(intHouse); std::string strCode = getStringCode(intHouse);
string strUnit = getStringCode(intCode); std::string strUnit = getStringCode(intCode);
strCode.append(strUnit); strCode.append(strUnit);
strCode.insert(0, "S"); strCode.insert(0, "S");

View file

@ -2,10 +2,14 @@
#include "DeviceNexa.h" #include "DeviceNexa.h"
#include <string> #include <string>
class DeviceWaveman : public DeviceNexa namespace TelldusCore {
{
public: class DeviceWaveman : public DeviceNexa
DeviceWaveman(int model, const std::string &strHouse, const std::string &strCode); {
virtual int turnOff(void); public:
virtual int methods(int methodsSupported); DeviceWaveman(int model, const std::string &strHouse, const std::string &strCode);
}; virtual int turnOff(void);
virtual int methods(int methodsSupported);
};
}

View file

@ -25,6 +25,8 @@
#define strcasecmp _stricmp #define strcasecmp _stricmp
#endif #endif
using namespace TelldusCore;
Manager *Manager::instance = 0; Manager *Manager::instance = 0;
Manager::Manager() { Manager::Manager() {

View file

@ -14,29 +14,32 @@
#include "Settings.h" #include "Settings.h"
#include <map> #include <map>
class Device;
typedef std::map<int, Device *> DeviceMap; namespace TelldusCore {
class Device;
/** typedef std::map<int, Device *> DeviceMap;
@author Micke Prag <micke.prag@telldus.se>
*/ /**
class Manager { @author Micke Prag <micke.prag@telldus.se>
public: */
~Manager(); class Manager {
public:
Device *getDevice(int deviceId); ~Manager();
static Manager *getInstance(); Device *getDevice(int deviceId);
static void close();
static Manager *getInstance();
private: static void close();
Manager();
private:
Settings settings; Manager();
DeviceMap devices;
Settings settings;
static Manager *instance; DeviceMap devices;
};
static Manager *instance;
};
}
#endif #endif

View file

@ -5,6 +5,8 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
using namespace TelldusCore;
/* /*
* Send message to the USB dongle * Send message to the USB dongle
*/ */

View file

@ -19,6 +19,7 @@
void handleException(std::exception e); void handleException(std::exception e);
using namespace std; using namespace std;
using namespace TelldusCore;
inline char *wrapStdString( const std::string &string); inline char *wrapStdString( const std::string &string);
@ -465,8 +466,8 @@ char * WINAPI tdGetErrorString(int intErrorNo) {
//* //*
void handleException(exception e){ void handleException(exception e){
std::string strLogName = "errorlog.txt"; // std::string strLogName = "errorlog.txt";
//char* strLogName = ""; std::string strLogName = "";
if(strLogName.length() > 0){ if(strLogName.length() > 0){
ofstream errorfile(strLogName.c_str(), ios::app); ofstream errorfile(strLogName.c_str(), ios::app);