Skip to content

Commit

Permalink
Merge pull request #12 from chadparry/master
Browse files Browse the repository at this point in the history
Update to modern OpenZWave API
  • Loading branch information
ekarak committed Dec 19, 2015
2 parents 112330c + acebeda commit a686f03
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 107 deletions.
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ RANLIB := ranlib
# Change for DEBUG or RELEASE
TARGET := DEBUG

DEBUG_CFLAGS := -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -Wall -Wno-format -g -DDEBUG -Werror -O0 -DDEBUG_BOOSTSTOMP
# TODO: Restore the -Werror flag after removing calls to the deprecated
# Manager::BeginControllerCommand method.
DEBUG_CFLAGS := -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -Wall -Wno-format -g -DDEBUG -O0 -DDEBUG_BOOSTSTOMP
RELEASE_CFLAGS := -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -Wall -Wno-unknown-pragmas -Wno-format -O3 -DNDEBUG

DEBUG_LDFLAGS := -g
Expand Down Expand Up @@ -53,16 +55,16 @@ INCLUDES := -I $(OPENZWAVE_INC) -I $(OPENZWAVE_INC)/command_classes/ -I $(OPENZW
#GNUTLS := -lgnutls

LIBZWAVE_STATIC := $(OPENZWAVE_LIB)/libopenzwave.a
LIBZWAVE_DYNAMIC := $(OPENZWAVE_LIB)/libopenzwave.so.1.0
LIBZWAVE_DYNAMIC := $(OPENZWAVE_LIB)/libopenzwave.so.1.3
LIBZWAVE := -lopenzwave
LIBUSB := -ludev

# for Mac OS X comment out above 2 lines and uncomment next 2 lines
#LIBZWAVE := $(wildcard $(OPENZWAVE)/cpp/lib/mac/*.a)
#LIBUSB := -framework IOKit -framework CoreFoundation

LIBBOOST := -lboost_thread-mt -lboost_program_options -lboost_system -lboost_filesystem -lpthread
LIBBOOST_STATIC := -lboost_thread-mt -lboost_program_options -lboost_system -lboost_filesystem
LIBBOOST := -lboost_thread -lboost_program_options -lboost_system -lboost_filesystem -lpthread
LIBBOOST_STATIC := -lboost_thread -lboost_program_options -lboost_system -lboost_filesystem
LIBTHRIFT := -lthrift
LIBBOOSTSTOMP := -lbooststomp
LIBBOOSTSTOMP_STATIC := libbooststomp.a
Expand Down Expand Up @@ -107,8 +109,7 @@ openzwave:
cd $(OPENZWAVE); make

openzwave-install: openzwave
cd $(OPENZWAVE)/cpp/lib/linux; cp libopenzwave.so libopenzwave.so.1.0
cd $(OPENZWAVE); sudo make -f debian/Makefile install
cd $(OPENZWAVE); sudo make install

booststomp:
#cd $(BOOSTSTOMP); make
Expand Down
194 changes: 194 additions & 0 deletions RemoteManager_server.cpp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
--- gen-cpp/RemoteManager_server.cpp.orig 2015-12-14 01:08:55.315767324 -0800
+++ gen-cpp/RemoteManager_server.cpp 2015-12-14 01:16:56.983717848 -0800
@@ -1,11 +1,11 @@
// Automatically generated OpenZWave::Manager_server wrapper
-// (c) 2011 Elias Karakoulakis <[email protected]>
+// (c) 2011-2012 Elias Karakoulakis <[email protected]>

#include "RemoteManager.h"
-#include <thrift/protocol/TBinaryProtocol.h>
-#include <thrift/server/TSimpleServer.h>
-#include <thrift/transport/TServerSocket.h>
-#include <thrift/transport/TBufferTransports.h>
+#include <protocol/TBinaryProtocol.h>
+#include <server/TSimpleServer.h>
+#include <transport/TServerSocket.h>
+#include <transport/TBufferTransports.h>

using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
@@ -17,7 +17,17 @@
using namespace ::OpenZWave;

void BeginControllerCommand_callback(OpenZWave::Driver::ControllerState arg1, OpenZWave::Driver::ControllerError arg2, void* arg3) {
- // FIXME: fill in the blanks (sorry!)
+ g_criticalSection.lock();
+ //
+ STOMP::hdrmap headers;
+ headers["ControllerState"] = to_string<uint16_t>(arg1, std::hex);
+ if (arg2 != OpenZWave::Driver::ControllerError_None ) {
+ headers["ControllerError"] = to_string<uint16_t>(arg2, std::hex);
+ }
+ string empty = "" ;
+ stomp_client->send(*notifications_topic, headers, empty);
+ //
+ g_criticalSection.unlock();
}

class RemoteManagerHandler : virtual public RemoteManagerIf {
@@ -283,10 +293,15 @@
}

void GetNodeNeighbors(UInt32_ListByte& _return, const int32_t _homeId, const int8_t _nodeId) {
+ uint8* arr;
Manager* mgr = Manager::Get();
g_criticalSection.lock();
- _return.retval = mgr->GetNodeNeighbors((::uint32 const) _homeId, (::uint8 const) _nodeId, (::uint8**) &_return._nodeNeighbors);
+ _return.retval = mgr->GetNodeNeighbors((::uint32 const) _homeId, (::uint8 const) _nodeId, (::uint8**) &arr);
g_criticalSection.unlock();
+ if (_return.retval > 0) {
+ for (int i=0; i<_return.retval; i++) _return._nodeNeighbors.push_back(arr[i]);
+ delete arr;
+ }
}

void GetNodeManufacturerName(std::string& _return, const int32_t _homeId, const int8_t _nodeId) {
@@ -571,11 +586,15 @@
g_criticalSection.unlock();
}

- void GetValueListItems(Bool_ListString& _return, const RemoteValueID& _id) {
+ void GetValueListItems(Bool_ListString& _return, const RemoteValueID& _id) {
+ std::vector<std::string> o_values;
Manager* mgr = Manager::Get();
g_criticalSection.lock();
- _return.retval = mgr->GetValueListItems(_id.toValueID(), (std::vector<std::string, std::allocator<std::string> >*) &_return.o_value);
+ _return.retval = mgr->GetValueListItems(_id.toValueID(), &o_values);
g_criticalSection.unlock();
+ if (_return.retval > 0) {
+ for (int i=0; i< _return.retval; i++) _return.o_value.push_back(std::string(o_values[i]));
+ }
}

void GetValueFloatPrecision(Bool_UInt8& _return, const RemoteValueID& _id) {
@@ -604,7 +623,7 @@
bool SetValue_UInt8_UInt8(const RemoteValueID& _id, const std::vector<int8_t> & _value, const int8_t _length) {
Manager* mgr = Manager::Get();
g_criticalSection.lock();
- bool function_result = mgr->SetValue(_id.toValueID(), (::uint8 const*) &_value, (::uint8 const) _length);
+ bool function_result = mgr->SetValue(_id.toValueID(), (const uint8*) _value.data(), _value.size());
g_criticalSection.unlock();
return(function_result);
}
@@ -658,10 +677,10 @@
}

void SetChangeVerified(const RemoteValueID& _id, const bool _verify) {
- Manager* mgr = Manager::Get();
- g_criticalSection.lock();
- mgr->SetChangeVerified(_id.toValueID(), (bool) _verify);
- g_criticalSection.unlock();
+ Manager* mgr = Manager::Get();
+ g_criticalSection.lock();
+ mgr->SetChangeVerified(_id.toValueID(), (bool) _verify);
+ g_criticalSection.unlock();
}

bool PressButton(const RemoteValueID& _id) {
@@ -762,11 +781,16 @@
return(function_result);
}

- void GetAssociations_uint8(GetAssociationsReturnStruct& _return, const int32_t _homeId, const int8_t _nodeId, const int8_t _groupIdx) {
+ void GetAssociations(GetAssociationsReturnStruct& _return, const int32_t _homeId, const int8_t _nodeId, const int8_t _groupIdx) {
+ uint8* o_associations;
Manager* mgr = Manager::Get();
g_criticalSection.lock();
- _return.retval = mgr->GetAssociations((::uint32 const) _homeId, (::uint8 const) _nodeId, (::uint8 const) _groupIdx, (::uint8**) &_return.o_associations);
+ _return.retval = mgr->GetAssociations((::uint32 const) _homeId, (::uint8 const) _nodeId, (::uint8 const) _groupIdx, (::uint8**) &o_associations);
g_criticalSection.unlock();
+ if (_return.retval > 0) {
+ for (int i=0; i<_return.retval; i++) _return.o_associations.push_back(o_associations[i]);
+ delete o_associations;
+ }
}

int8_t GetMaxAssociations(const int32_t _homeId, const int8_t _nodeId, const int8_t _groupIdx) {
@@ -784,17 +808,17 @@
g_criticalSection.unlock();
}

- void AddAssociation(const int32_t _homeId, const int8_t _nodeId, const int8_t _groupIdx, const int8_t _targetNodeId, const int8_t _instance) {
+ void AddAssociation(const int32_t _homeId, const int8_t _nodeId, const int8_t _groupIdx, const int8_t _targetNodeId) {
Manager* mgr = Manager::Get();
g_criticalSection.lock();
- mgr->AddAssociation((::uint32 const) _homeId, (::uint8 const) _nodeId, (::uint8 const) _groupIdx, (::uint8 const) _targetNodeId, (::uint8 const) _instance);
+ mgr->AddAssociation((::uint32 const) _homeId, (::uint8 const) _nodeId, (::uint8 const) _groupIdx, (::uint8 const) _targetNodeId);
g_criticalSection.unlock();
}

- void RemoveAssociation(const int32_t _homeId, const int8_t _nodeId, const int8_t _groupIdx, const int8_t _targetNodeId, const int8_t _instance) {
+ void RemoveAssociation(const int32_t _homeId, const int8_t _nodeId, const int8_t _groupIdx, const int8_t _targetNodeId) {
Manager* mgr = Manager::Get();
g_criticalSection.lock();
- mgr->RemoveAssociation((::uint32 const) _homeId, (::uint8 const) _nodeId, (::uint8 const) _groupIdx, (::uint8 const) _targetNodeId, (::uint8 const) _instance);
+ mgr->RemoveAssociation((::uint32 const) _homeId, (::uint8 const) _nodeId, (::uint8 const) _groupIdx, (::uint8 const) _targetNodeId);
g_criticalSection.unlock();
}

@@ -865,10 +889,15 @@
}

void GetAllScenes(GetAllScenesReturnStruct& _return) {
+ uint8* _sceneIds;
Manager* mgr = Manager::Get();
g_criticalSection.lock();
- _return.retval = mgr->GetAllScenes((::uint8**) &_return._sceneIds);
+ _return.retval = mgr->GetAllScenes((::uint8**) &_sceneIds);
g_criticalSection.unlock();
+ if (_return.retval>0) {
+ for (int i=0; i<_return.retval; i++) _return._sceneIds.push_back(_sceneIds[i]);
+ delete(_sceneIds);
+ }
}

void RemoveAllScenes(const int32_t _homeId) {
@@ -967,10 +996,12 @@
}

void SceneGetValues(SceneGetValuesReturnStruct& _return, const int8_t _sceneId) {
+ std::vector<OpenZWave::ValueID> o_values;
Manager* mgr = Manager::Get();
g_criticalSection.lock();
- _return.retval = mgr->SceneGetValues((::uint8 const) _sceneId, _return.o_value.toValueID());
+ _return.retval = mgr->SceneGetValues((::uint8 const) _sceneId, &o_values);
g_criticalSection.unlock();
+ for (int i=0; i< _return.retval; i++) _return.o_value.push_back(RemoteValueID(o_values[i]));
}

void SceneGetValueAsBool(Bool_Bool& _return, const int8_t _sceneId, const RemoteValueID& _valueId) {
@@ -1138,13 +1169,13 @@
}

void SendAllValues() {
- // Your implementation goes here
- printf("SendAllValues\n");
+ g_criticalSection.lock();
+ send_all_values();
+ g_criticalSection.unlock();
}

void ping() {
- // Your implementation goes here
- printf("ping\n");
+ // Dummy method to keep Thrift connection alive over NAT routers
}

};
@@ -1162,4 +1193,4 @@
// return 0;
// }
//
-//
\ No newline at end of file
+//
Loading

0 comments on commit a686f03

Please sign in to comment.