[Debian-iot-packaging] [openzwave-controlpanel] 54/81: add multi instance association support

Dara Adib daradib-guest at moszumanska.debian.org
Thu Dec 22 16:57:52 UTC 2016


This is an automated email from the git hooks/post-receive script.

daradib-guest pushed a commit to branch debian/master
in repository openzwave-controlpanel.

commit 021f2e82e809f4e1be61903a6e5635853dbf18d1
Author: xs4 <xs4 at xs4me.net>
Date:   Mon Jul 27 13:22:01 2015 +0200

    add multi instance association support
---
 cp.js         | 29 ++++++++++++++++++++++++-----
 ozwcp.cpp     | 41 ++++++++++++++++++++++++++---------------
 ozwcp.h       |  4 ++--
 webserver.cpp |  4 +---
 4 files changed, 53 insertions(+), 25 deletions(-)

diff --git a/cp.js b/cp.js
index ec2ab02..8889ad2 100644
--- a/cp.js
+++ b/cp.js
@@ -1640,18 +1640,37 @@ function CreateGroup(ind)
   grp = 1;
   for (i = 0; i < nodes[ind].groups.length; i++) {
     nodegrp[ind]=nodegrp[ind]+'<option value="'+nodes[ind].groups[i].id+'">'+nodes[ind].groups[i].label+' ('+nodes[ind].groups[i].id+')</option>';
-    nodegrpgrp[ind][grp] = '<td><div id="nodegrp" name="nodegrp" style="float: right;"><select id="groups" multiple size="4" style="vertical-align: top; margin-left: 5px;">';
+    nodegrpgrp[ind][grp] = '<td><div id="nodegrp" name="nodegrp" style="float: right;"><select id="groups" multiple size="8" style="vertical-align: top; margin-left: 5px;">';
     k = 0;
     for (j = 1; j < nodes.length; j++) {
       if (nodes[j] == null)
 	continue;
+
+	  // build a list of instances 
+      var instances = [ String(j) ];
+      for (var l = 0; l < nodes[j].values.length; l++) {
+	  	instances[ l + 1] =  j + '.' + nodes[j].values[l].instance;
+	  	instances.push( j + '.' + nodes[j].values[l].instance);
+      }	
+	
+		// make unique
+	  instances = instances.filter(function(item, i, ar){ return ar.indexOf(item) === i; });
+
+	  // only show when we have found multiple instances
+	  if ( instances.length <= 2 ) {
+		instances = [ String(j) ];
+	  }
+
       if (nodes[ind].groups[i].nodes != null)
 	while (k < nodes[ind].groups[i].nodes.length && nodes[ind].groups[i].nodes[k] < j)
 	  k++;
-      if (nodes[ind].groups[i].nodes[k] == j)
-	nodegrpgrp[ind][grp]=nodegrpgrp[ind][grp]+'<option selected="true">'+j+'</option>';
-      else
-	nodegrpgrp[ind][grp]=nodegrpgrp[ind][grp]+'<option>'+j+'</option>';
+	  
+	  for (var l=0; l< instances.length; l++) { 
+	      if (nodes[ind].groups[i].nodes.indexOf(instances[l]) != -1 )
+			nodegrpgrp[ind][grp]=nodegrpgrp[ind][grp]+'<option selected="true">'+instances[l]+'</option>';
+	      else
+			nodegrpgrp[ind][grp]=nodegrpgrp[ind][grp]+'<option>'+instances[l]+'</option>';
+	  }			
     }
     nodegrpgrp[ind][grp]=nodegrpgrp[ind][grp]+'</select></td><td><button type="submit" style="margin-left: 5px;" onclick="return DoGrpPost();">Submit</button></div></td></tr>';
     grp++;
diff --git a/ozwcp.cpp b/ozwcp.cpp
index 7b3af62..50b25e5 100644
--- a/ozwcp.cpp
+++ b/ozwcp.cpp
@@ -214,7 +214,7 @@ void MyNode::newGroup (uint8 node)
  * MyNode::addGroup
  * Add group membership based on notification updates.
  */
-void MyNode::addGroup (uint8 node, uint8 g, uint8 n, uint8 *v)
+void MyNode::addGroup (uint8 node, uint8 g, uint8 n, InstanceAssociation *v)
 {
 	fprintf(stderr, "addGroup: node %d group %d n %d\n", node, g, n);
 	if (groups.size() == 0)
@@ -222,8 +222,14 @@ void MyNode::addGroup (uint8 node, uint8 g, uint8 n, uint8 *v)
 	for (vector<MyGroup*>::iterator it = groups.begin(); it != groups.end(); ++it)
 		if ((*it)->groupid == g) {
 			(*it)->grouplist.clear();
-			for (int i = 0; i < n; i++)
-				(*it)->grouplist.push_back(v[i]);
+			for (int i = 0; i < n; i++) {
+				char str[32];
+				if (v[i].m_instance == 0)
+					snprintf( str, 32, "%d", v[i].m_nodeId );
+				else
+					snprintf( str, 32, "%d.%d", v[i].m_nodeId, v[i].m_instance );
+				(*it)->grouplist.push_back(str);
+			}
 			setTime(time(NULL));
 			setChanged(true);
 			return;
@@ -252,7 +258,7 @@ void MyNode::updateGroup (uint8 node, uint8 grp, char *glist)
 	char *p = glist;
 	vector<MyGroup*>::iterator it;
 	char *np;
-	uint8 *v;
+	vector<string> v;
 	uint8 n;
 	uint8 j;
 
@@ -264,31 +270,36 @@ void MyNode::updateGroup (uint8 node, uint8 grp, char *glist)
 		fprintf(stderr, "updateGroup: node %d group %d not found\n", node, grp);
 		return;
 	}
-	v = new uint8((*it)->max);
 	n = 0;
 	while (p != NULL && *p && n < (*it)->max) {
 		np = strsep(&p, ",");
-		v[n++] = strtol(np, NULL, 10);
+		v.push_back( np );
+		n++;
 	}
 	/* Look for nodes in the passed-in argument list, if not present add them */
-	vector<uint8>::iterator nit;
+	vector<string>::iterator nit;
 	for (j = 0; j < n; j++) {
 		for (nit = (*it)->grouplist.begin(); nit != (*it)->grouplist.end(); ++nit)
-			if (*nit == v[j])
+			if (v[j].compare( *nit ) == 0 )
 				break;
-		if (nit == (*it)->grouplist.end()) // not found
-			Manager::Get()->AddAssociation(homeId, node, grp, v[j]);
+		if (nit == (*it)->grouplist.end()) { // not found
+			int nodeId = 0,  instance = 0;
+			sscanf(v[j].c_str(),"%d.%d", &nodeId, &instance);
+			Manager::Get()->AddAssociation(homeId, node, grp, nodeId, instance);
+		}
 	}
 	/* Look for nodes in the vector (current list) and those not found in
      the passed-in list need to be removed */
 	for (nit = (*it)->grouplist.begin(); nit != (*it)->grouplist.end(); ++nit) {
 		for (j = 0; j < n; j++)
-			if (*nit == v[j])
+			if (v[j].compare( *nit ) == 0 )
 				break;
-		if (j >= n)
-			Manager::Get()->RemoveAssociation(homeId, node, grp, *nit);
+		if (j >= n) {
+			int nodeId = 0,  instance = 0;
+			sscanf(nit->c_str(),"%d.%d", &nodeId, &instance);
+			Manager::Get()->RemoveAssociation(homeId, node, grp, nodeId, instance);
+		}
 	}
-	delete [] v;
 }
 
 /*
@@ -502,7 +513,7 @@ void OnNotification (Notification const* _notification, void* _context)
 		{
 			Log::Write(LogLevel_Info, "Notification: Group Home 0x%08x Node %d Group %d",
 					_notification->GetHomeId(), _notification->GetNodeId(), _notification->GetGroupIdx());
-			uint8 *v = NULL;
+			InstanceAssociation *v = NULL;
 			int8 n = Manager::Get()->GetAssociations(homeId, _notification->GetNodeId(), _notification->GetGroupIdx(), &v);
 			pthread_mutex_lock(&nlock);
 			nodes[_notification->GetNodeId()]->addGroup(_notification->GetNodeId(), _notification->GetGroupIdx(), n, v);
diff --git a/ozwcp.h b/ozwcp.h
index d817859..7f8e0c0 100644
--- a/ozwcp.h
+++ b/ozwcp.h
@@ -76,7 +76,7 @@ typedef struct {
   uint8 groupid;
   uint8 max;
   string label;
-  vector<uint8> grouplist;
+  vector<string> grouplist;
 } MyGroup;
 
 class MyNode {
@@ -100,7 +100,7 @@ public:
   static void addRemoved(uint8 node) { removed.push_back(node); }
   static uint32 getRemovedCount() { return removed.size(); }
   static uint8 getRemoved();
-  void addGroup(uint8 node, uint8 g, uint8 n, uint8 *v);
+  void addGroup(uint8 node, uint8 g, uint8 n, InstanceAssociation *v);
   MyGroup *getGroup(uint8 i);
   void updateGroup(uint8 node, uint8 grp, char *glist);
   uint8 numGroups() { return groups.size(); }
diff --git a/webserver.cpp b/webserver.cpp
index 9f9568e..dce86bd 100644
--- a/webserver.cpp
+++ b/webserver.cpp
@@ -207,9 +207,7 @@ void Webserver::web_get_groups (int n, TiXmlElement *ep)
 		groupElement->SetAttribute("label", p->label.c_str());
 		string str = "";
 		for (uint j = 0; j < p->grouplist.size(); j++) {
-			char s[12];
-			snprintf(s, sizeof(s), "%d", p->grouplist[j]);
-			str += s;
+			str += p->grouplist[j];
 			if (j + 1 < p->grouplist.size())
 				str += ",";
 		}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-iot/openzwave-controlpanel.git



More information about the Debian-iot-packaging mailing list