merge
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Sat, 23 Jun 2018 09:16:35 +0200
changeset 2191 b579e2155d02
parent 2190 b7d803fc44db (current diff)
parent 2188 7f59aa398669 (diff)
child 2192 09d5d1456616
merge
--- a/bacnet/runtime/server.c	Mon Jun 18 12:17:07 2018 +0300
+++ b/bacnet/runtime/server.c	Sat Jun 23 09:16:35 2018 +0200
@@ -428,6 +428,10 @@
 }
 
 
+// This mutex blocks execution of __init_%(locstr)s() until initialization is done
+static int init_done = 0;
+static pthread_mutex_t init_done_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t init_done_cond = PTHREAD_COND_INITIALIZER;
 
 /** Main function of server demo. **/
 int bn_server_run(server_node_t *server_node) {
@@ -450,6 +454,12 @@
     bvlc_bdt_restore_local();
     /* Initiliaze the bacnet server 'device' */    
     Device_Init(server_node->device_name);
+
+    pthread_mutex_lock(&init_done_lock);
+    init_done = 1;
+    pthread_cond_signal(&init_done_cond);
+    pthread_mutex_unlock(&init_done_lock);
+
     /* Set the password (max 31 chars) for Device Communication Control request. */
     /* Default in the BACnet stack is hardcoded as "filister" */
     /* (char *) cast is to remove the cast. The function is incorrectly declared/defined in the BACnet stack! */
@@ -549,6 +559,7 @@
 int __init_%(locstr)s (int argc, char **argv){
 	int index;
 
+    init_done = 0;
 	/* init each local server */
 	/* NOTE: All server_nodes[].init_state are initialised to 0 in the code 
 	 *       generated by the BACnet plugin 
@@ -567,6 +578,13 @@
 			goto error_exit;
 		}
 	}
+
+    pthread_mutex_lock(&init_done_lock);
+    while (!init_done) {
+        pthread_cond_wait(&init_done_cond, &init_done_lock);
+    }
+    pthread_mutex_unlock(&init_done_lock);
+
 	server_node.init_state = 2; // we have created the node and thread
 
 	return 0;
--- a/wxglade_hmi/wxglade_hmi.py	Mon Jun 18 12:17:07 2018 +0300
+++ b/wxglade_hmi/wxglade_hmi.py	Sat Jun 23 09:16:35 2018 +0200
@@ -90,7 +90,10 @@
 
     def CTNGenerate_C(self, buildpath, locations):
 
-        hmi_frames = []
+        # list containing description of all objects declared in wxglade
+        hmi_objects = []
+        # list containing only description of the main frame object 
+        main_frames = []
 
         wxgfile_path = self._getWXGLADEpath()
         if os.path.exists(wxgfile_path):
@@ -100,12 +103,17 @@
 
             for node in wxgtree.childNodes[1].childNodes:
                 if node.nodeType == wxgtree.ELEMENT_NODE:
-                    hmi_frames.append({
-                        "name": node.getAttribute("name"),
+                    name = node.getAttribute("name")
+                    wxglade_object_desc = {
+                        "name": name,
                         "class": node.getAttribute("class"),
                         "handlers": [
                             hnode.firstChild.data for hnode in
-                            node.getElementsByTagName("handler")]})
+                            node.getElementsByTagName("handler")]}
+
+                    hmi_objects.append(wxglade_object_desc)
+                    if name == self.CTNName() :
+                        main_frames.append(wxglade_object_desc)
 
             hmipyfile_path = os.path.join(self._getBuildPath(), "hmi.py")
             if wx.Platform == '__WXMSW__':
@@ -122,12 +130,12 @@
         else:
             define_hmi = ""
 
-        declare_hmi = "\n".join(["%(name)s = None\n" % x +
-                                 "\n".join(["%(class)s.%(h)s = %(h)s" %
+        declare_hmi = "\n".join(["%(name)s = None\n" % x for x in main_frames])
+        declare_hmi += "\n".join(["\n".join(["%(class)s.%(h)s = %(h)s" %
                                             dict(x, h=h) for h in x['handlers']])
-                                 for x in hmi_frames])
+                                 for x in hmi_objects])
         global_hmi = ("global %s\n" % ",".join(
-            [x["name"] for x in hmi_frames]) if len(hmi_frames) > 0 else "")
+            [x["name"] for x in main_frames]) if len(main_frames) > 0 else "")
         init_hmi = "\n".join(["""\
 def OnCloseFrame(evt):
     wx.MessageBox(_("Please stop PLC to close"))
@@ -135,10 +143,10 @@
 %(name)s = %(class)s(None)
 %(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame)
 %(name)s.Show()
-""" % x for x in hmi_frames])
+""" % x for x in main_frames])
         cleanup_hmi = "\n".join(
             ["if %(name)s is not None: %(name)s.Destroy()" % x
-             for x in hmi_frames])
+             for x in main_frames])
 
         self.PreSectionsTexts = {
             "globals": define_hmi,
@@ -150,6 +158,11 @@
             "start":   init_hmi,
         }
 
+        if len(main_frames) == 0 and \
+           len(getattr(self.CodeFile, "start").getanyText().strip()) == 0:
+                self.GetCTRoot().logger.write_warning(
+                    _("Warning: WxGlade HMI has no object with name identical to extension name, and no python code is provided in start section to create object.\n"))
+            
         return PythonFileCTNMixin.CTNGenerate_C(self, buildpath, locations)
 
     def _editWXGLADE(self):