00001
00015 #ifndef KERNEL_H
00016 #define KERNEL_H
00017
00018 #include <map>
00019 #include <list>
00020 #include <vector>
00021 #include <string>
00022 #include <errno.h>
00023
00024 #ifdef USE_PTHREAD
00025 #include <pthread.h>
00026 #include <sched.h>
00027 #else
00028 #include <pth.h>
00029 #endif
00030
00031 #ifdef SLIM_MINIGUI_ENGINE
00032 #include <minigui/common.h>
00033 #include <minigui/minigui.h>
00034 #include <minigui/gdi.h>
00035 #include <minigui/window.h>
00036 #include <minigui/control.h>
00037 #endif
00038
00039 #include "watchdog.h"
00040 #include "filter.h"
00041 #include "application.h"
00042 #include "signalmanager.h"
00043 #include "configuration.h"
00044
00046 #define SMP_RT_PRIORITY 10
00047
00048
00050 namespace SMP{
00051
00052
00053 typedef SMPFilter* (maker_t)(void);
00054 typedef void (disposer_t)(SMPFilter*);
00055
00056
00058 class SMPWatchdog;
00059
00063 class SMPKernel
00064 {
00065 friend class SMPWatchdog;
00066 private:
00067
00069 static SMPKernel *kernel;
00071 SMPKernel(void);
00072
00074
00075
00077 SMPConfiguration config;
00078
00080 SMPWatchdog *watchdog;
00081
00082
00084 char repository_path[100];
00085
00086 public:
00088 SMPSignalManager *signal_manager;
00089 private:
00090
00091
00092
00093
00094
00095
00096
00097
00103 map<string, maker_t*> filter_factory;
00105 vector<disposer_t*> filter_disposer;
00106
00108 vector<SMPBuffer*> smp_buffer;
00110 vector<SMPSignalBuffer*> smp_sigbuffer;
00112 vector<SMPFilter*> smp_filter;
00113
00115 vector<int> watchdog_unmonitored;
00116
00117
00118
00119
00120
00122 vector<void *> lib_handle;
00123
00124
00125
00126
00127
00128 #ifdef USE_PTHREAD
00129
00130 vector<pthread_t> thread_handle;
00131
00133 map<int, pthread_t> sig_thread_handle;
00134 #else
00135 vector<pth_t> thread_handle;
00136 #endif
00137
00138
00139
00140
00141
00142
00143
00144
00153 int register_filter(const char *name, void *handle);
00154
00159 int unregister_filters(void);
00160
00168 int load_filter(const char *soname);
00175 int unload_filters(void);
00176
00177
00178
00179
00180
00181 void reset_buffers(void);
00182
00183
00190 static void *run(void *arg);
00191
00192
00193 #ifdef USE_PTHREAD
00194
00195 static void *filter_sig_handler(void *arg);
00198 static void *filter_sig_handler_light(void *arg);
00199 #endif
00200
00201 #ifndef USE_PTHREAD
00202
00206 double get_pth_time(pth_time_t *t);
00207 #endif
00208
00212 static int acquire_realtime_scheduling (pthread_t thread, int priority);
00213
00217 static int drop_realtime_scheduling (pthread_t thread);
00218
00219
00220 public:
00221
00223 ~SMPKernel(void);
00224
00226 char version[6];
00231 static SMPKernel *get_kernel(void);
00232
00234 bool stopped;
00236 bool paused;
00237
00242 void pat_dog(int id);
00243
00249 void set_unmonitored(int fid);
00250
00251 inline SMPConfiguration& get_config();
00252 inline void set_config(SMPConfiguration &c);
00253
00254 inline void set_config(string name, int value);
00255
00256
00257
00258
00259
00273 #ifdef USE_PTHREAD
00274 int construct_component(const char *repos, const char *filter_name, int major_version, int minor_version,
00275 int *in_buffer, int num_in, int *out_buffer, int num_out,
00276 int *sig_in_buffer, int sig_num_in, int *sig_out_buffer, int sig_num_out,
00277 map<string, property_item> &prop);
00278 #elif
00279 int construct_component(const char *repos, const char *filter_name, int major_version, int minor_version,
00280 int *in_buffer, int num_in, int *out_buffer, int num_out, map<string, property_item> &prop);
00281 #endif
00282
00286 int destruct_filters(void);
00287
00288
00289
00290
00291
00303 int construct_binding(size_t size, int input, int input_port, vector<int> &output, vector<int> &output_port, int type);
00308 int destruct_buffers(void);
00309
00310
00311
00312
00313
00318 int init(void);
00320 void start(void);
00322 void pause(void);
00324 void resume(void);
00326 void stop(void);
00327 void halt(void);
00328
00329
00330
00331
00332
00333
00340
00341
00342
00349
00350
00351
00352
00353
00354
00355
00356
00365
00375
00376
00377
00378
00383
00384
00385
00386
00387
00388
00394 void set_buf_status(int buf_id, int status);
00399 int get_buf_status(int buf_id);
00400
00405 void flush_buffer(int buf_id);
00406
00407
00408
00410 ssize_t buf_read(int buf_id, void *buff, size_t nbytes, int fid=0);
00412 ssize_t buf_write(int buf_id, const void *buff, size_t nbytes);
00413
00414
00415
00417 ssize_t buf_read_nonblock(int buf_id, void *buff, size_t nbytes, int fid=0);
00419 ssize_t buf_write_nonblock(int buf_id, const void *buff, size_t nbytes);
00420
00421
00422 ssize_t buf_read_space(int buf_id, int fid);
00423 ssize_t buf_write_space(int buf_id);
00424
00425 #ifdef USE_PTHREAD
00426
00432 int signal_emit(int buf_id, SMPSignal *sig);
00433
00437 map<int, int> signal_timeout;
00443 void set_signal_timeout(int fid, int usec);
00449 int get_signal_timeout(int fid);
00450
00451
00456 void set_repos_path(const char *path);
00460 char *get_repos_path(void);
00461
00462 #endif
00463
00467 void show_buffers(void);
00468
00473 void show_buffer(int bid);
00474
00478 void show_threads(void);
00479
00484 void show_thread(int fid);
00485
00486
00487
00488
00489
00491 bool buf_rw_info;
00492
00498 void set_priority(int fid, int prio);
00499
00505 void update_property(int fid, map<string, property_item> &prop);
00506
00507
00508 #ifdef SLIM_MINIGUI_ENGINE
00509 private:
00513 static int SLIMWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam);
00514
00518 static void *start_MG_main_win(void *arg);
00519
00520 static pthread_t MG_tid;
00521 public:
00525 static void start_MG();
00526 static void join_MG();
00527
00528
00529 #endif
00530
00531
00532
00533 int argc;
00534 char **argv;
00535 void set_env(int pargc, char **pargv){ argc = pargc; argv = pargv;}
00536 void get_env(int *pargc, char ***pargv){ *pargc = argc; *pargv = argv;}
00537
00538
00539
00540 public:
00542 void run_additional();
00544 void begin();
00546 void join();
00547 private:
00548 pthread_mutex_t mutex_stop;
00549 pthread_cond_t cond_stop;
00550 bool stop_met;
00552 static void *_begin(void *arg);
00553
00554 };
00555
00556 SMPConfiguration& SMPKernel::get_config()
00557 {
00558 return config;
00559 }
00560 void SMPKernel::set_config(SMPConfiguration& c)
00561 {
00562 config = c;
00563 }
00564 void SMPKernel::set_config(string name, int value)
00565 {
00566 config.set_config(name, value);
00567 }
00568
00569
00570 }
00571
00572 #endif