Added the rest of the functions exported by telldus-core to our php-wrapper
This commit is contained in:
parent
d1bb107b64
commit
c6e73fad70
2 changed files with 274 additions and 8 deletions
|
@ -1,22 +1,45 @@
|
|||
#ifndef PHP_TELLDUS_H
|
||||
#define PHP_TELLDUS_H 1
|
||||
|
||||
#define PHP_TELLDUS_VERSION "2.0.0"
|
||||
#define PHP_TELLDUS_VERSION "2.0.2"
|
||||
#define PHP_TELLDUS_EXTNAME "telldus"
|
||||
|
||||
PHP_MINIT_FUNCTION(telldus);
|
||||
PHP_MSHUTDOWN_FUNCTION(telldus);
|
||||
PHP_RINIT_FUNCTION(telldus);
|
||||
|
||||
PHP_FUNCTION(tdInit);
|
||||
PHP_FUNCTION(tdClose);
|
||||
|
||||
PHP_FUNCTION(tdTurnOn);
|
||||
PHP_FUNCTION(tdTurnOff);
|
||||
PHP_FUNCTION(tdBell);
|
||||
PHP_FUNCTION(tdDim);
|
||||
PHP_FUNCTION(tdLearn);
|
||||
PHP_FUNCTION(tdMethods);
|
||||
PHP_FUNCTION(tdLastSentCommand);
|
||||
PHP_FUNCTION(tdLastSentValue);
|
||||
|
||||
PHP_FUNCTION(tdGetNumberOfDevices);
|
||||
PHP_FUNCTION(tdGetDeviceId);
|
||||
PHP_FUNCTION(tdGetDeviceType);
|
||||
|
||||
PHP_FUNCTION(tdGetErrorString);
|
||||
|
||||
PHP_FUNCTION(tdGetName);
|
||||
PHP_FUNCTION(tdSetName);
|
||||
PHP_FUNCTION(tdGetProtocol);
|
||||
PHP_FUNCTION(tdSetProtocol);
|
||||
PHP_FUNCTION(tdGetModel);
|
||||
PHP_FUNCTION(tdSetModel);
|
||||
|
||||
PHP_FUNCTION(tdGetDeviceParameter);
|
||||
PHP_FUNCTION(tdSetDeviceParameter);
|
||||
|
||||
PHP_FUNCTION(tdAddDevice);
|
||||
PHP_FUNCTION(tdRemoveDevice);
|
||||
|
||||
PHP_FUNCTION(tdSendRawCommand);
|
||||
|
||||
extern zend_module_entry telldus_module_entry;
|
||||
#define phpext_telldus_ptr &telldus_module_entry
|
||||
|
|
|
@ -8,15 +8,39 @@
|
|||
|
||||
|
||||
static function_entry telldus_functions[] = {
|
||||
PHP_FE(tdInit, NULL)
|
||||
PHP_FE(tdClose, NULL)
|
||||
|
||||
PHP_FE(tdTurnOn, NULL)
|
||||
PHP_FE(tdTurnOff, NULL)
|
||||
PHP_FE(tdBell, NULL)
|
||||
PHP_FE(tdDim, NULL)
|
||||
PHP_FE(tdLearn, NULL)
|
||||
PHP_FE(tdMethods, NULL)
|
||||
PHP_FE(tdLastSentCommand, NULL)
|
||||
PHP_FE(tdLastSentValue, NULL)
|
||||
|
||||
PHP_FE(tdGetNumberOfDevices, NULL)
|
||||
PHP_FE(tdGetDeviceId, NULL)
|
||||
PHP_FE(tdGetDeviceType, NULL)
|
||||
|
||||
PHP_FE(tdGetErrorString, NULL)
|
||||
|
||||
PHP_FE(tdGetName, NULL)
|
||||
PHP_FE(tdSetName, NULL)
|
||||
PHP_FE(tdGetProtocol, NULL)
|
||||
PHP_FE(tdSetProtocol, NULL)
|
||||
PHP_FE(tdGetModel, NULL)
|
||||
PHP_FE(tdSetModel, NULL)
|
||||
|
||||
PHP_FE(tdGetDeviceParameter, NULL)
|
||||
PHP_FE(tdSetDeviceParameter, NULL)
|
||||
|
||||
PHP_FE(tdAddDevice, NULL)
|
||||
PHP_FE(tdRemoveDevice, NULL)
|
||||
|
||||
PHP_FE(tdSendRawCommand, NULL)
|
||||
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
|
@ -49,11 +73,25 @@ PHP_RINIT_FUNCTION(telldus)
|
|||
|
||||
PHP_MINIT_FUNCTION(telldus)
|
||||
{
|
||||
REGISTER_LONG_CONSTANT("TELLDUS_TURNON", TELLSTICK_TURNON, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLDUS_TURNOFF", TELLSTICK_TURNOFF, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLDUS_BELL", TELLSTICK_BELL, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLDUS_TOGGLE", TELLSTICK_TOGGLE, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLDUS_DIM", TELLSTICK_DIM, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_TURNON", TELLSTICK_TURNON, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_TURNOFF", TELLSTICK_TURNOFF, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_BELL", TELLSTICK_BELL, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_TOGGLE", TELLSTICK_TOGGLE, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_DIM", TELLSTICK_DIM, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_LEARN", TELLSTICK_LEARN, CONST_CS | CONST_PERSISTENT);
|
||||
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_SUCCESS", TELLSTICK_SUCCESS, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_NOT_FOUND", TELLSTICK_ERROR_NOT_FOUND, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_PERMISSION_DENIED", TELLSTICK_ERROR_PERMISSION_DENIED, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_DEVICE_NOT_FOUND", TELLSTICK_ERROR_DEVICE_NOT_FOUND, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_METHOD_NOT_SUPPORTED", TELLSTICK_ERROR_METHOD_NOT_SUPPORTED, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_COMMUNICATION", TELLSTICK_ERROR_COMMUNICATION, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_CONNECTING_SERVICE", TELLSTICK_ERROR_CONNECTING_SERVICE, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_UNKNOWN_RESPONSE", TELLSTICK_ERROR_UNKNOWN_RESPONSE, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_UNKNOWN", TELLSTICK_ERROR_UNKNOWN, CONST_CS | CONST_PERSISTENT);
|
||||
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_TYPE_DEVICE", TELLSTICK_TYPE_DEVICE, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_TYPE_GROUP", TELLSTICK_TYPE_GROUP, CONST_CS | CONST_PERSISTENT);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
@ -63,6 +101,18 @@ PHP_MSHUTDOWN_FUNCTION(telldus)
|
|||
return SUCCESS;
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdInit)
|
||||
{
|
||||
tdInit();
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdClose)
|
||||
{
|
||||
tdClose();
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdTurnOn)
|
||||
{
|
||||
long id;
|
||||
|
@ -111,6 +161,16 @@ PHP_FUNCTION(tdDim)
|
|||
RETURN_BOOL( tdDim( id, level ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdLearn)
|
||||
{
|
||||
long id;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
RETURN_BOOL( tdLearn( id ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdMethods)
|
||||
{
|
||||
|
@ -126,6 +186,35 @@ PHP_FUNCTION(tdMethods)
|
|||
RETURN_LONG(methods);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdLastSentCommand)
|
||||
{
|
||||
long id;
|
||||
long supportedMethods;
|
||||
long command;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &id, &supportedMethods) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
command = tdLastSentCommand( id, supportedMethods );
|
||||
RETURN_LONG(command);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdLastSentValue)
|
||||
{
|
||||
long id;
|
||||
char *value, *retval;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
value = tdLastSentValue( id );
|
||||
retval = estrdup(value);
|
||||
tdReleaseString(value);
|
||||
RETURN_STRING(retval, 0);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetNumberOfDevices)
|
||||
{
|
||||
int nbr = tdGetNumberOfDevices();
|
||||
|
@ -143,16 +232,170 @@ PHP_FUNCTION(tdGetDeviceId)
|
|||
RETURN_LONG( tdGetDeviceId( index ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetDeviceType)
|
||||
{
|
||||
long id;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_LONG(0);
|
||||
}
|
||||
|
||||
RETURN_LONG( tdGetDeviceType( id ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetErrorString)
|
||||
{
|
||||
long errorNo;
|
||||
char *errorString, *retval;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &errorNo) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
errorString = tdGetErrorString( errorNo );
|
||||
retval = estrdup(errorString);
|
||||
tdReleaseString(errorString);
|
||||
RETURN_STRING( retval, 0 );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetName)
|
||||
{
|
||||
long id;
|
||||
char *name;
|
||||
char *name, *retval;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
name = tdGetName( id );
|
||||
RETURN_STRING( name, 1 );
|
||||
retval = estrdup(name);
|
||||
tdReleaseString(name);
|
||||
RETURN_STRING( retval, 0 );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdSetName)
|
||||
{
|
||||
long id;
|
||||
char *name;
|
||||
int nameLen;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &id, &name, &nameLen) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_BOOL( tdSetName( id, name ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetProtocol)
|
||||
{
|
||||
long id;
|
||||
char *protocol, *retval;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
protocol = tdGetProtocol( id );
|
||||
retval = estrdup(protocol);
|
||||
tdReleaseString(protocol);
|
||||
RETURN_STRING( retval, 0 );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdSetProtocol)
|
||||
{
|
||||
long id;
|
||||
char *protocol;
|
||||
int protocolLen;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &id, &protocol, &protocolLen) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_BOOL( tdSetProtocol( id, protocol ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetModel)
|
||||
{
|
||||
long id;
|
||||
char *model, *retval;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
model = tdGetModel( id );
|
||||
retval = estrdup(model);
|
||||
tdReleaseString(model);
|
||||
RETURN_STRING( retval, 0 );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdSetModel)
|
||||
{
|
||||
long id;
|
||||
char *model;
|
||||
int modelLen;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &id, &model, &modelLen) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_BOOL( tdSetModel( id, model ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetDeviceParameter)
|
||||
{
|
||||
long id;
|
||||
char *param, *name, *defaultValue, *retval;
|
||||
int nameLen, defaultValueLen;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lss", &id, &name, &nameLen, &defaultValue, &defaultValueLen) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
param = tdGetDeviceParameter( id, name, defaultValue );
|
||||
retval = estrdup(param);
|
||||
tdReleaseString(param);
|
||||
RETURN_STRING( retval, 0 );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdSetDeviceParameter)
|
||||
{
|
||||
long id;
|
||||
char *name, *value;
|
||||
int nameLen, valueLen;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lss", &id, &name, &nameLen, &value, &valueLen) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_BOOL( tdSetDeviceParameter( id, name, value ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdAddDevice)
|
||||
{
|
||||
RETURN_LONG(tdAddDevice());
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdRemoveDevice)
|
||||
{
|
||||
long deviceId;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &deviceId) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_BOOL(tdRemoveDevice(deviceId));
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdSendRawCommand)
|
||||
{
|
||||
char *command;
|
||||
int commandLen;
|
||||
long reserved = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &command, &commandLen, &reserved) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_LONG(tdSendRawCommand(command, reserved));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue