Permalink
Browse files

patch dummy ping() method to squelch useless message

  • Loading branch information...
1 parent 7639bf2 commit ce1112f4955011f285cb028cdc887cc298c67e66 @ekarak ekarak committed Mar 31, 2013
Showing with 55 additions and 25 deletions.
  1. +25 −16 Main.cpp
  2. +2 −2 Makefile
  3. +25 −4 RemoteManager_server.cpp.patch
  4. +2 −3 gen-cpp/RemoteManager_server.cpp.patched
  5. +1 −0 ozw-monitor.rb
  6. BIN ozwd
View
@@ -41,7 +41,7 @@ for more information on the LGPL, see:
#include <boost/program_options.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
-// alse we're using boost's filesystem classes
+// also we're using boost's filesystem classes
#include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/exception/info.hpp>
@@ -80,7 +80,10 @@ typedef struct
static list<NodeInfo*> g_nodes;
// OpenZWave includes
+#include "Manager.h"
#include "Notification.h"
+#include "Log.h"
+
static uint32 g_homeId = 0;
static bool g_initFailed = false;
//
@@ -93,9 +96,11 @@ static boost::mutex initMutex;
static STOMP::BoostStomp* stomp_client;
static string* notifications_topic = new string("/queue/zwave/monitor");
+// JSON body indicator
+static bool jsonMessageBody = false;
-//JSON body indicator
-static bool jsonMessageBody =false;
+// Show OZW+BoostStomp debug messages?
+static bool debugMsg = false;
//-----------------------------------------------------------------------------
// <GetNodeInfo>
@@ -124,7 +129,7 @@ NodeInfo* GetNodeInfo
// <jsonifyHeaders>
// Represent headers as JSON object
//-----------------------------------------------------------------------------
-string jsonifyHeaders(STOMP::hdrmap headers)
+string jsonifyHeaders(STOMP::hdrmap& headers)
{
string hdrjson="";
STOMP::hdrmap::iterator it;
@@ -323,14 +328,14 @@ void OnNotification
/**< All nodes have been queried, so client application can expected complete data. */
case Notification::Type_AllNodesQueried:
{
- initCond.notify_all();
+ //initCond.notify_all();
break;
}
case Notification::Type_AllNodesQueriedSomeDead:
{
// TODO: mark dead nodes for deletion?
- initCond.notify_all();
+ //initCond.notify_all();
break;
}
@@ -350,12 +355,9 @@ void OnNotification
headers["ValueID"] = to_string<uint64_t>(_notification->GetValueID().GetId(), std::hex);
}
//
- string response = "" ;
- if (jsonMessageBody) {
- response = jsonifyHeaders(headers);
- }
+ string body = jsonMessageBody ? jsonifyHeaders(headers) : "";
//
- stomp_client->send(*notifications_topic, headers, response);
+ stomp_client->send(*notifications_topic, headers, body);
}
//
g_criticalSection.unlock();
@@ -377,10 +379,8 @@ void send_all_values() {
headers["HomeID"] = to_string<uint32_t>(v.GetHomeId(), std::hex);
headers["ValueID"] = to_string<uint64_t>(v.GetId(), std::hex);
//
- string response = "" ;
- if(jsonMessageBody)
- response=jsonifyHeaders(headers);
- stomp_client->send(*notifications_topic, headers,response );
+ string response = jsonMessageBody ? jsonifyHeaders(headers) : "";
+ stomp_client->send(*notifications_topic, headers,response );
}
}
//
@@ -422,6 +422,7 @@ int main(int argc, char *argv[]) {
("ozwuser,u", po::value<string>(&ozw_user)->default_value(current_dir.string()), "our OpenZWave user config database")
("ozwport,p", po::value<string>(&ozw_port)->default_value("/dev/ttyUSB0"), "our OpenZWave driver port")
("json,j", po::bool_switch(&jsonMessageBody), "Should stomp messages have JSON body?")
+ ("debug,d", po::bool_switch(&debugMsg), "Show debug logging from OpenZwave and BoostStomp?")
;
// a boost:program_options variable map
po::variables_map vm;
@@ -436,7 +437,7 @@ int main(int argc, char *argv[]) {
}
catch (exception& e)
{
- dump_trace(e, " parsing command-line options");
+ dump_trace(e, "parsing command-line options");
return 2;
}
@@ -445,6 +446,7 @@ int main(int argc, char *argv[]) {
// connect to STOMP server in order to send openzwave notifications
stomp_client = new STOMP::BoostStomp(stomp_host, stomp_port);
stomp_client->start();
+ stomp_client->enable_debug_msgs(debugMsg);
}
catch (exception& e)
{
@@ -470,6 +472,13 @@ int main(int argc, char *argv[]) {
// Add a Z-Wave Driver
Manager::Get()->AddDriver( ozw_port );
+
+ // Set OpenZwave's log level
+ LogLevel ll_save = debugMsg ? LogLevel_Debug : LogLevel_None;
+ LogLevel ll_queue = debugMsg ? LogLevel_Debug : LogLevel_Detail;
+ LogLevel ll_dump = debugMsg ? LogLevel_Warning : LogLevel_Error;
+ Log::SetLoggingState(ll_save, ll_queue, ll_dump);
+
}
catch (exception& e)
{
View
@@ -77,11 +77,11 @@ LIBS := $(GNUTLS) $(LIBUSB) $(LIBBOOST) $(LIBTHRIFT) $(LIBBOOSTSTOMP)
all: openzwave booststomp ozwd
gen-cpp/RemoteManager_server.cpp: create_server.rb gen-cpp/RemoteManager.cpp
- patch -p0 gen-cpp/ozw_types.h < ozw_types.h.patch
+ patch -N -p0 gen-cpp/ozw_types.h < ozw_types.h.patch
ruby create_server.rb --ozwroot=${OPENZWAVE} --thriftroot=$(THRIFT)
cp gen-cpp/RemoteManager_server.cpp gen-cpp/RemoteManager_server.cpp.orig
cp gen-cpp/ozw_types.h gen-cpp/ozw_types.h.orig
- patch -p0 gen-cpp/RemoteManager_server.cpp < RemoteManager_server.cpp.patch
+ patch -N -p0 gen-cpp/RemoteManager_server.cpp < RemoteManager_server.cpp.patch
gen-cpp/RemoteManager.cpp: ozw.thrift
thrift --gen cocoa --gen cpp --gen csharp --gen erl --gen go --gen java --gen js --gen perl --gen php --gen py --gen rb ozw.thrift
@@ -1,5 +1,5 @@
-*** gen-cpp/RemoteManager_server.cpp.orig 2013-03-09 21:01:53.973455995 +0200
---- gen-cpp/RemoteManager_server.cpp.patched 2013-03-10 09:25:27.455986522 +0200
+*** gen-cpp/RemoteManager_server.cpp.orig 2013-03-31 10:13:47.323382427 +0300
+--- gen-cpp/RemoteManager_server.cpp.patched 2013-03-31 10:29:40.404108479 +0300
***************
*** 1,11 ****
// Automatically generated OpenZWave::Manager_server wrapper
@@ -231,7 +231,7 @@
void SceneGetValueAsBool(Bool_Bool& _return, const int8_t _sceneId, const RemoteValueID& _valueId) {
***************
-*** 1138,1145 ****
+*** 1138,1150 ****
}
void SendAllValues() {
@@ -240,7 +240,12 @@
}
void ping() {
---- 1169,1177 ----
+! // Your implementation goes here
+! printf("ping\n");
+ }
+
+ };
+--- 1169,1181 ----
}
void SendAllValues() {
@@ -250,3 +255,19 @@
}
void ping() {
+! // Dummy method to keep Thrift connection alive over NAT routers
+ }
+
+ };
+***************
+*** 1162,1165 ****
+ // return 0;
+ // }
+ //
+! //
+\ No newline at end of file
+--- 1193,1196 ----
+ // return 0;
+ // }
+ //
+! //
@@ -1175,8 +1175,7 @@ class RemoteManagerHandler : virtual public RemoteManagerIf {
}
void ping() {
- // Your implementation goes here
- printf("ping\n");
+ // Dummy method to keep Thrift connection alive over NAT routers
}
};
@@ -1194,4 +1193,4 @@ class RemoteManagerHandler : virtual public RemoteManagerIf {
// return 0;
// }
//
-//
+//
View
@@ -101,6 +101,7 @@ class OZW_EventID_id1 < BitStruct
puts " #{hdr} : #{val}"
end
}
+ puts " --- message body: ---\n#{msg.body}" unless msg.body.empty?
end
rescue Exception => e
puts e.inspect
View
BIN ozwd
Binary file not shown.

0 comments on commit ce1112f

Please sign in to comment.