Added function tdReleaseString(), closes #66
This commit is contained in:
parent
35a7320c38
commit
bf9685478b
4 changed files with 27 additions and 14 deletions
|
@ -35,4 +35,6 @@ EXPORTS
|
||||||
tdRegisterRawDeviceEvent @25
|
tdRegisterRawDeviceEvent @25
|
||||||
|
|
||||||
tdLearn @26
|
tdLearn @26
|
||||||
tdLastSentValue @27
|
tdLastSentValue @27
|
||||||
|
|
||||||
|
tdReleaseString @28
|
||||||
|
|
|
@ -97,6 +97,15 @@ void WINAPI tdClose(void) {
|
||||||
Manager::close();
|
Manager::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method releases resources allocated by telldus-core.
|
||||||
|
* It should be called on the returned value from all functions return <tt>char *</tt>
|
||||||
|
**/
|
||||||
|
void WINAPI tdReleaseString(char *string) {
|
||||||
|
free(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns a device on.
|
* Turns a device on.
|
||||||
* Make sure the device supports this by calling tdMethods() before any
|
* Make sure the device supports this by calling tdMethods() before any
|
||||||
|
|
|
@ -35,6 +35,8 @@ extern "C" {
|
||||||
TELLSTICK_API int WINAPI tdRegisterDeviceEvent( TDDeviceEvent eventFunction, void *context );
|
TELLSTICK_API int WINAPI tdRegisterDeviceEvent( TDDeviceEvent eventFunction, void *context );
|
||||||
TELLSTICK_API int WINAPI tdRegisterRawDeviceEvent( TDRawDeviceEvent eventFunction, void *context );
|
TELLSTICK_API int WINAPI tdRegisterRawDeviceEvent( TDRawDeviceEvent eventFunction, void *context );
|
||||||
TELLSTICK_API void WINAPI tdClose(void);
|
TELLSTICK_API void WINAPI tdClose(void);
|
||||||
|
TELLSTICK_API void WINAPI tdReleaseString(char *string);
|
||||||
|
|
||||||
TELLSTICK_API int WINAPI tdTurnOn(int intDeviceId);
|
TELLSTICK_API int WINAPI tdTurnOn(int intDeviceId);
|
||||||
TELLSTICK_API int WINAPI tdTurnOff(int intDeviceId);
|
TELLSTICK_API int WINAPI tdTurnOff(int intDeviceId);
|
||||||
TELLSTICK_API int WINAPI tdBell(int intDeviceId);
|
TELLSTICK_API int WINAPI tdBell(int intDeviceId);
|
||||||
|
|
|
@ -80,7 +80,7 @@ void print_device( int index ) {
|
||||||
int intId = tdGetDeviceId(index);
|
int intId = tdGetDeviceId(index);
|
||||||
char *name = tdGetName(intId);
|
char *name = tdGetName(intId);
|
||||||
printf("%i\t%s\t", intId, name);
|
printf("%i\t%s\t", intId, name);
|
||||||
free(name);
|
tdReleaseString(name);
|
||||||
int lastSentCommand = tdLastSentCommand(intId, SUPPORTED_METHODS);
|
int lastSentCommand = tdLastSentCommand(intId, SUPPORTED_METHODS);
|
||||||
char *level = 0;
|
char *level = 0;
|
||||||
switch(lastSentCommand) {
|
switch(lastSentCommand) {
|
||||||
|
@ -93,7 +93,7 @@ void print_device( int index ) {
|
||||||
case TELLSTICK_DIM:
|
case TELLSTICK_DIM:
|
||||||
level = tdLastSentValue(intId);
|
level = tdLastSentValue(intId);
|
||||||
printf("DIMMED:%s", level);
|
printf("DIMMED:%s", level);
|
||||||
free(level);
|
tdReleaseString(level);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("Unknown state");
|
printf("Unknown state");
|
||||||
|
@ -121,10 +121,10 @@ int find_device( char *device ) {
|
||||||
char *name = tdGetName( id );
|
char *name = tdGetName( id );
|
||||||
if (strcasecmp(name, device) == 0) {
|
if (strcasecmp(name, device) == 0) {
|
||||||
deviceId = id;
|
deviceId = id;
|
||||||
free(name);
|
tdReleaseString(name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(name);
|
tdReleaseString(name);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,13 +145,13 @@ void switch_device( bool turnOn, char *device ) {
|
||||||
(deviceType == TELLSTICK_TYPE_DEVICE ? "device" : "group"),
|
(deviceType == TELLSTICK_TYPE_DEVICE ? "device" : "group"),
|
||||||
deviceId,
|
deviceId,
|
||||||
name);
|
name);
|
||||||
free(name);
|
tdReleaseString(name);
|
||||||
|
|
||||||
int retval = (turnOn ? tdTurnOn( deviceId ) : tdTurnOff( deviceId ));
|
int retval = (turnOn ? tdTurnOn( deviceId ) : tdTurnOff( deviceId ));
|
||||||
char *errorString = tdGetErrorString(retval);
|
char *errorString = tdGetErrorString(retval);
|
||||||
|
|
||||||
printf(" - %s\n", errorString);
|
printf(" - %s\n", errorString);
|
||||||
free(errorString);
|
tdReleaseString(errorString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dim_device( char *device, int level ) {
|
void dim_device( char *device, int level ) {
|
||||||
|
@ -169,8 +169,8 @@ void dim_device( char *device, int level ) {
|
||||||
int retval = tdDim( deviceId, (unsigned char)level );
|
int retval = tdDim( deviceId, (unsigned char)level );
|
||||||
char *errorString = tdGetErrorString(retval);
|
char *errorString = tdGetErrorString(retval);
|
||||||
printf("Dimming device: %i %s to %i - %s\n", deviceId, name, level, errorString);
|
printf("Dimming device: %i %s to %i - %s\n", deviceId, name, level, errorString);
|
||||||
free(name);
|
tdReleaseString(name);
|
||||||
free(errorString);
|
tdReleaseString(errorString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bell_device( char *device ) {
|
void bell_device( char *device ) {
|
||||||
|
@ -184,8 +184,8 @@ void bell_device( char *device ) {
|
||||||
int retval = tdBell( deviceId );
|
int retval = tdBell( deviceId );
|
||||||
char *errorString = tdGetErrorString(retval);
|
char *errorString = tdGetErrorString(retval);
|
||||||
printf("Sending bell to: %i %s - %s\n", deviceId, name, errorString);
|
printf("Sending bell to: %i %s - %s\n", deviceId, name, errorString);
|
||||||
free(name);
|
tdReleaseString(name);
|
||||||
free(errorString);
|
tdReleaseString(errorString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void learn_device( char *device ) {
|
void learn_device( char *device ) {
|
||||||
|
@ -199,8 +199,8 @@ void learn_device( char *device ) {
|
||||||
int retval = tdLearn( deviceId );
|
int retval = tdLearn( deviceId );
|
||||||
char *errorString = tdGetErrorString(retval);
|
char *errorString = tdGetErrorString(retval);
|
||||||
printf("Learning device: %i %s - %s\n", deviceId, name, errorString);
|
printf("Learning device: %i %s - %s\n", deviceId, name, errorString);
|
||||||
free(name);
|
tdReleaseString(name);
|
||||||
free(errorString);
|
tdReleaseString(errorString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_raw_command( char *command ) {
|
void send_raw_command( char *command ) {
|
||||||
|
@ -223,7 +223,7 @@ void send_raw_command( char *command ) {
|
||||||
int retval = tdSendRawCommand( msg, 0 );
|
int retval = tdSendRawCommand( msg, 0 );
|
||||||
char *errorString = tdGetErrorString(retval);
|
char *errorString = tdGetErrorString(retval);
|
||||||
printf("Sending raw command: %s\n", errorString);
|
printf("Sending raw command: %s\n", errorString);
|
||||||
free(errorString);
|
tdReleaseString(errorString);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue