COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
CoviseBase.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 #ifndef COVISE_BASE_H
9 #define COVISE_BASE_H
10 
11 #if !defined(__linux__) && !defined(_WIN32)
12 #define COVISE_Signals
13 #endif
14 
15 #include <covise/covise.h>
16 #include <util/coTypes.h>
17 
18 #ifndef _WIN32
19 #include <dirent.h>
20 #endif
21 
22 #ifdef USE_X11
23 #include <X11/Intrinsic.h>
24 #include <X11/StringDefs.h>
25 #include <X11/keysym.h>
26 #endif
27 
28 #ifdef COVISE_Signals
29 #include <covise/covise_signal.h>
30 #endif
31 
32 #include <covise/covise_msg.h>
33 
34 namespace covise
35 {
36 
37 class ApplicationProcess;
38 class coDistributedObject;
39 
40 const int MAXTOKENS = 10;
41 
43 {
44  DESCRIPTION = 0, //0
47  PARIN, //3
48  PAROUT //4
49 };
50 
52 {
53  string mapName;
54  vector<float> mapValues;
55 };
56 
57 /*
58  * Covise callbacks
59  */
60 typedef void CoviseCallback(void *userData, void *callbackData);
61 typedef void CoviseParamCallback(bool inMapLoading, void *userData, void *callbackData);
62 
64 {
65 public:
66  CoviseBase();
67 
68  enum
69  {
70  MAX_PORTS = 4096
71  };
72  enum
73  {
75  DEL_OBJ
76  };
77 
78 protected:
79  // Error flag
80  static int error;
81 
82  // Communication data
83  static char *reply_keyword;
84  static char *reply_param_name;
85  static char *reply_param_type;
86  static const char **reply_buffer;
87  static int no_of_reply_tokens;
88  static vector<string> tokenlist;
89  static Message *applMsg;
90  static int socket_id;
91  static const char *h_name;
92  static const char *m_name;
93  static const char *instance;
95  static char *emergency_data;
96  static const char *module_description;
97  static bool master;
98 
99  static char *port_name[MAX_PORTS];
100  static char *port_description[MAX_PORTS];
101  static enum appl_port_type port_type[MAX_PORTS];
102  static const char *port_default[MAX_PORTS];
103  static char *port_datatype[MAX_PORTS];
104  static char *port_dependency[MAX_PORTS];
105  static int port_required[MAX_PORTS];
106 
107 #ifdef USE_X11
108  static XtInputId X_id;
109  static XtAppContext appContext;
110 #endif
111 
112  // Flag for initialization
113  static int init_flag;
114 
115  static char *feedback_info;
116 
117  // protected member funcs
118  static void remove_socket(int sock_id);
119 
120  static void doProgress();
121  static void doCustom(Message *m);
122  static void doMasterSwitch();
123  static void doSlaveSwitch();
124 //static int doQuit();
125 #ifndef _WIN32
126 #ifdef COVISE_Signals
127  static void signal_handler(int signo, void *);
128 #endif
129 #endif
130  static void init_emergency_message(void);
131 #ifdef USE_X11
132  static void socketCommunicationCB(XtPointer client_data, int *source, XtInputId *id);
133 #endif
134 
135  // callback stuff
137  static void *progressUserData;
138  static void *progressCallbackData;
140  static void *quitUserData;
141  static void *quitCallbackData;
143  static void *quitInfoUserData;
144  static void *quitInfoCallbackData;
146  static void *customUserData;
147  static void *customCallbackData;
149  static void *masterSwitchUserData;
151  static void *paramUserData;
152  static void *paramCallbackData;
153  static void callProgressCallback(void);
154  static void callQuitCallback(void);
155  static void callQuitInfoCallback(void);
156  static void callCustomCallback(void);
157  static void callMasterSwitchCallback(void);
158  static void callParamCallback(bool inMapLoading);
159 
160 public:
161  static int parseMessage(char *line, char *token[], int tmax, const char *sep);
162 
163  static void set_progress_callback(CoviseCallback *f, void *userData);
164  static void set_quit_callback(CoviseCallback *f, void *userData);
165  static void set_quit_info_callback(CoviseCallback *f, void *userData);
166  static void set_custom_callback(CoviseCallback *f, void *userData);
167  static void set_param_callback(CoviseParamCallback *f, void *userData);
168  static void remove_progress_callback();
169  static void remove_quit_callback();
170  static void remove_quit_info_callback();
171  static void remove_custom_callback();
172  static void remove_param_callback();
173 
174  static void set_master_switch_callback(CoviseCallback *f, void *userData);
175  static void remove_master_switch_callback();
176 
177  static bool is_master()
178  {
179  return master;
180  };
181 
182  static int request_param(const char *name);
183  static void enable_param(const char *name);
184  static void disable_param(const char *name);
185  static void hide_param(const char *name);
186  static void show_param(const char *name);
187  static void cancel_param(const char *name);
188  static void reopen_param(const char *name);
189 
190  static int get_reply_passwd(const char **host, const char **user, const char **passwd);
191  static int get_reply_cli(const char **command);
192  static int get_reply_int_slider(long *min, long *max, long *val);
193  static int get_reply_float_slider(float *min, float *max, float *val);
194  static int get_reply_int_vector(int pos, long *val);
195  static int get_reply_float_vector(int pos, float *val);
196  static int get_reply_int_scalar(long *val);
197  static int get_reply_float_scalar(float *val);
198  static int get_reply_boolean(int *);
199  static int get_reply_string(const char **string);
200  static int get_reply_browser(const char **file);
201  static int get_reply_timer(long *start, long *delta, long *state);
202  static int get_reply_arrayset(const char **msg_buf);
203  static int get_reply_choice(int *selected_pos);
204  static int get_reply_choice(int pos, string *choiceLabels);
205  static int get_reply_colormapchoice(int *selected_pos);
206  static int get_reply_colormapchoice(TColormapChoice *values);
207  static int get_reply_material(string *value);
208  static int get_reply_colormap(float *min, float *max, int *len, colormap_type *type);
209  static int get_reply_colormap(int pos, float *r, float *g, float *b, float *a, float *x);
210  static int get_reply_color(float *r, float *g, float *b, float *a);
211 
212  static int update_slider_param(const char *name, long min, long max, long val);
213  static int update_slider_param(const char *name, float min, float max, float val);
214  static int update_scalar_param(const char *name, long val);
215  static int update_scalar_param(const char *name, float val);
216  static int update_vector_param(const char *name, int num, long *list);
217  static int update_vector_param(const char *name, int num, float *list);
218  static int update_string_param(const char *name, char *string);
219  static int update_text_param(const char *name, char *text, int linenum);
220  static int update_boolean_param(const char *name, int val);
221  static int update_choice_param(const char *name, int len, const char *const *list, int pos);
222  static int update_timer_param(const char *name, long start, long delta, long state);
223  static int update_colormap_param(const char *name, float min, float max, const string &cmap);
224  static int update_material_param(const char *name, const string &value);
225  static int update_colormapchoice_param(const char *name, int num, int pos, TColormapChoice *list);
226  static int update_color_param(const char *name, float r, float g, float b, float a);
227 
228  static int get_socket_id();
229  static const char *get_instance()
230  {
231  return instance;
232  }
233  static const char *get_host()
234  {
235  return h_name;
236  }
237  static const char *get_module()
238  {
239  return m_name;
240  }
241  static const char *get_reply_param_name()
242  {
243  return reply_param_name;
244  }
245 
246  //
247  // Messages to COVISE environment
248  //
249 
251  static void sendWarning(const char *fmt, ...)
252 #ifdef __GNUC__
253  __attribute__((format(printf, 1, 2)))
254 #endif
255  ;
256 
258  static void sendError(const char *fmt, ...)
259 #ifdef __GNUC__
260  __attribute__((format(printf, 1, 2)))
261 #endif
262  ;
263 
265  static void sendInfo(const char *string, ...)
266 #ifdef __GNUC__
267  __attribute__((format(printf, 1, 2)))
268 #endif
269  ;
270  static int send_message(covise_msg_type type, const char *msg_string);
271  static int send_ui_message(const char *keyword, const char *string);
272 
273  static int send_feedback_message(const char *keyword, const char *string);
274  static void set_feedback_info(const char *string);
275  static const char *get_feedback_info();
276  static char get_feedback_type();
277  static void send_quit_request();
278  static void log_message(int line, const char *file, const char *comment);
279 
281 
282  //
283  // File Open Utilities by Uwe Woessner
284  //
285  // define const char * functions as well...
286  static FILE *fopen(const char *file, const char *mode, char **returnPath = NULL);
287  static int open(const char *file, int mode);
288 #if !defined(_WIN32) && !defined(__alpha) && !defined(_AIX)
289  static DIR *opendir(const char *file);
290 #endif
291  static void getname(char *buf, const char *file, const char *addpath = NULL);
292  static bool getnameinpath(char *buf, const char *file, const char *path);
293 
294  // Add Interactor for feedback
295  static void addInteractor(coDistributedObject *obj, const char *name, const char *value);
296 
297  // Print out description for -d option
298  static void printDesc(const char *callname);
299 };
300 }
301 #endif
static const char * m_name
Definition: CoviseBase.h:92
static void * customUserData
Definition: CoviseBase.h:146
static void * quitInfoCallbackData
Definition: CoviseBase.h:144
GLsizei GLsizei GLchar * source
Definition: khronos-glext.h:6739
GLenum GLsizei len
Definition: khronos-glext.h:7440
static char * reply_param_type
Definition: CoviseBase.h:85
appl_port_type
Definition: CoviseBase.h:42
GLsizei GLsizei GLuint * obj
Definition: khronos-glext.h:6733
static void * masterSwitchUserData
Definition: CoviseBase.h:149
static void * paramUserData
Definition: CoviseBase.h:151
static ApplicationProcess * appmod
Definition: CoviseBase.h:280
static bool is_master()
Definition: CoviseBase.h:177
Definition: CoviseBase.h:48
static void * quitCallbackData
Definition: CoviseBase.h:141
GLuint const GLchar * name
Definition: khronos-glext.h:6722
static CoviseCallback * quitCallbackFunc
Definition: CoviseBase.h:139
static int socket_id
Definition: CoviseBase.h:90
static void * progressCallbackData
Definition: CoviseBase.h:138
static const char * instance
Definition: CoviseBase.h:93
GLboolean GLenum GLenum GLvoid * values
Definition: khronos-glext.h:6369
static void * customCallbackData
Definition: CoviseBase.h:147
Definition: CoviseBase.h:46
static CoviseCallback * progressCallbackFunc
Definition: CoviseBase.h:136
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: khronos-glext.h:6344
colormap_type
Definition: covise_msg.h:79
GLboolean GLboolean GLboolean b
Definition: khronos-glext.h:6895
Definition: CoviseBase.h:45
static char * feedback_info
Definition: CoviseBase.h:115
static int init_flag
Definition: CoviseBase.h:113
const int MAXTOKENS
Definition: CoviseBase.h:40
static void * progressUserData
Definition: CoviseBase.h:137
static int no_of_reply_tokens
Definition: CoviseBase.h:87
#define NULL
Definition: covise_list.h:22
Definition: message.h:111
static void * quitInfoUserData
Definition: CoviseBase.h:143
static char * emergency_data
Definition: CoviseBase.h:95
void CoviseCallback(void *userData, void *callbackData)
Definition: CoviseBase.h:60
static vector< string > tokenlist
Definition: CoviseBase.h:88
Definition: CoviseBase.h:74
static bool master
Definition: CoviseBase.h:97
GLuint GLfloat * val
Definition: khronos-glext.h:7898
static const char * get_module()
Definition: CoviseBase.h:237
GLint GLint GLint GLint GLint x
Definition: khronos-glext.h:6346
GLenum mode
Definition: khronos-glext.h:6908
GLdouble GLdouble GLdouble r
Definition: khronos-glext.h:6457
Definition: CoviseBase.h:63
vector< float > mapValues
Definition: CoviseBase.h:54
static const char * get_instance()
Definition: CoviseBase.h:229
Definition: covise_appproc.h:19
static CoviseCallback * masterSwitchCallbackFunc
Definition: CoviseBase.h:148
GLboolean GLboolean GLboolean GLboolean a
Definition: khronos-glext.h:6895
Definition: CoviseBase.h:44
static CoviseCallback * customCallbackFunc
Definition: CoviseBase.h:145
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: khronos-glext.h:8469
GLsizei const GLchar ** path
Definition: khronos-glext.h:7952
static void * paramCallbackData
Definition: CoviseBase.h:152
GLuint start
Definition: khronos-glext.h:6343
GLenum type
Definition: khronos-glext.h:6279
static CoviseParamCallback * paramCallbackFunc
Definition: CoviseBase.h:150
Definition: CoviseBase.h:51
covise_msg_type
Definition: message_types.h:64
static const char * get_host()
Definition: CoviseBase.h:233
const GLfloat * m
Definition: khronos-glext.h:12117
GLboolean GLboolean g
Definition: khronos-glext.h:6895
static const char ** reply_buffer
Definition: CoviseBase.h:86
void CoviseParamCallback(bool inMapLoading, void *userData, void *callbackData)
Definition: CoviseBase.h:61
static char * reply_param_name
Definition: CoviseBase.h:84
static CoviseCallback * quitInfoCallbackFunc
Definition: CoviseBase.h:142
Definition: CoviseBase.h:47
static Message * applMsg
Definition: CoviseBase.h:89
Definition: coDistributedObject.h:295
static const char * h_name
Definition: CoviseBase.h:91
static int error
Definition: CoviseBase.h:80
static Message emergency_message
Definition: CoviseBase.h:94
GLsizei const GLfloat * value
Definition: khronos-glext.h:6760
string mapName
Definition: CoviseBase.h:53
GLuint GLuint num
Definition: khronos-glext.h:10593
GLfloat f
Definition: khronos-glext.h:8258
static char * reply_keyword
Definition: CoviseBase.h:83
static const char * module_description
Definition: CoviseBase.h:96
static const char * get_reply_param_name()
Definition: CoviseBase.h:241
static void * quitUserData
Definition: CoviseBase.h:140
int min(int a, int b)
Definition: cutil_math.h:60
int max(int a, int b)
Definition: cutil_math.h:55
#define APPLEXPORT
Definition: coExport.h:57