iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Common.H
Go to the documentation of this file.
1 /*! @file
2  @author Unknown
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 #ifndef SRC_APPS_NRTDESIGNER_COMMON_H
35 #define SRC_APPS_NRTDESIGNER_COMMON_H
36 
39 #include <thread>
40 #include <iostream>
41 #include <mutex>
42 
44 NRT_BEGIN_UNCHECKED_INCLUDES
45 #include <QVariant>
46 #include <QString>
47 #include <QMap>
48 #include <QImage>
49 #include <QPixmap>
50 NRT_END_UNCHECKED_INCLUDES
51 
52 
53 // Z values determine who gets drawn on top of whom. Higher Z is more on top
54 #define ZVALUE_CONNECTION 0.0F
55 #define ZVALUE_CONNECTIONREQUEST 0.0F
56 #define ZVALUE_BORDERREP 1.0F
57 #define ZVALUE_MODULEREPBASE 2.0F
58 #define ZVALUE_MODULEREPBASE_SELECTED 3.0F
59 
60 
61 typedef QMap<QString, QVariant> ModuleData_t;
62 typedef QMap<QString, QVariant> ParamData_t;
63 
64 
65 // ######################################################################
66 inline bool matchMessageTypes(QString const & typ1, QString const & typ2)
67 {
68  if (typ1 == typ2 || typ1 == "nrt::AnyMessage" || typ2 == "nrt::AnyMessage") return true;
69  return false;
70 }
71 
72 // ######################################################################
73 struct ModuleDescr
74 {
75  // A small icon just for the tree-view
76  QPixmap smallIcon;
77 
78  // The original size icon
79  QImage icon;
80 
81  // The logical path
82  QString logicalpath;
83 
84  // The full path to the .so file for modules or .yaml file for macro-modules
85  QString fullpath;
86 
87  // The full manifest
88  nrt::ModuleManifest manifest;
89 };
90 
91 // ######################################################################
92 struct Tracer
93 {
94  std::mutex mtx;
95  static std::map<std::thread::id, int> indents;
96  static std::map<std::thread::id, int> threadIds;
97 
98  Tracer(std::string const& functionname) :
99  itsFunctionName(functionname)
100  {
101  std::lock_guard<std::mutex> lock(mtx);
102  std::thread::id tid = std::this_thread::get_id();
103 
104  if(threadIds.count(tid) == 0)
105  threadIds[tid] = threadIds.size();
106 
107  int & indent = indents[tid];
108  std::string indentstring = "";
109  for(int i=0; i<indent; i++) indentstring += " ";
110  std::cout << indentstring.c_str() << "-Begin :" << functionname.c_str()
111  << " tid[" << threadIds[tid] << "] s[" << indent << "]" << std::endl;
112  indent++;
113  }
114 
115  ~Tracer()
116  {
117  std::lock_guard<std::mutex> lock(mtx);
118 
119  std::thread::id tid = std::this_thread::get_id();
120 
121  int & indent = indents[tid];
122  indent--;
123  std::string indentstring = "";
124  for(int i=0; i<indent; i++) indentstring += " ";
125  std::cout << indentstring.c_str() << "-End :" << itsFunctionName.c_str()
126  << " tid[" << threadIds[tid] << "] s[" << indent << "]" << std::endl;
127  if(indent < 0) indent = 0;
128  }
129 
130  std::string const itsFunctionName;
131 };
132 
133 
134 //#define TRACE Tracer nrt_TRACE_helper(__PRETTY_FUNCTION__)
135 #define TRACE /**/
136 
137 
138 // ######################################################################
139 // Use reportExceptionQt() to report exceptions as QT MessageBox and swallow them, like this:
140 //
141 // try { risky_stuff(); } catch (...) { reportExceptionQt("Error doing risky stuff"); }
142 void reportExceptionQt(std::string const & msg);
143 
144 #endif // SRC_APPS_NRTDESIGNER_COMMON_H
145