| 1 | // ========================================================= // |
|---|
| 2 | // // |
|---|
| 3 | // File : xcmd.hxx // |
|---|
| 4 | // Purpose : support to run commands in (x)terminal // |
|---|
| 5 | // // |
|---|
| 6 | // Coded by Ralf Westram (coder@reallysoft.de) in Sep 25 // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // ========================================================= // |
|---|
| 10 | |
|---|
| 11 | #ifndef XCMD_HXX |
|---|
| 12 | #define XCMD_HXX |
|---|
| 13 | |
|---|
| 14 | #ifndef ARBDB_BASE_H |
|---|
| 15 | #include <arbdb_base.h> |
|---|
| 16 | #endif |
|---|
| 17 | #ifndef AW_BASE_HXX |
|---|
| 18 | #include <aw_base.hxx> |
|---|
| 19 | #endif |
|---|
| 20 | |
|---|
| 21 | enum XCMD_TYPE { |
|---|
| 22 | // internal (do not use; use public values below): |
|---|
| 23 | _XCMD__ASYNC = 1, // run asynchronously (otherwise wait until command finishes). |
|---|
| 24 | _XCMD__WAITKEY = 2, // after command always wait for keypress (otherwise only in case of error!). |
|---|
| 25 | _XCMD__ACCESS_DB = 4, // command may access database. |
|---|
| 26 | _XCMD__HIDDEN = 8, // do not run in terminal window (never waits for key) |
|---|
| 27 | |
|---|
| 28 | // rest is public ---------------------------------------- |
|---|
| 29 | |
|---|
| 30 | // the XCMD_ASYNC_... types do not block the database server, but also do not wait for the tool to finish. |
|---|
| 31 | // Has to be used if window shall remain open with command running continously (e.g. to tail a log). |
|---|
| 32 | XCMD_ASYNC_WAITKEY = _XCMD__ASYNC | _XCMD__ACCESS_DB | _XCMD__WAITKEY, |
|---|
| 33 | XCMD_ASYNC_WAIT_ON_ERROR = _XCMD__ASYNC | _XCMD__ACCESS_DB, |
|---|
| 34 | XCMD_ASYNC_HIDDEN = _XCMD__ASYNC | _XCMD__ACCESS_DB | _XCMD__HIDDEN, |
|---|
| 35 | |
|---|
| 36 | // Important note: the XCMD_SYNC_... types block the database server, if started from there. |
|---|
| 37 | // I.e. they are normally critical esp. in arb_ntree, which normally runs as server. |
|---|
| 38 | // This means: if the started tool tries to access the served database, |
|---|
| 39 | // it will not be able to do so (effectively causes a deadlock!) |
|---|
| 40 | // Use of XCMD_SYNC_...-modes is not recommended, unless you really know what you are doing! |
|---|
| 41 | XCMD_SYNC_WAITKEY = _XCMD__WAITKEY, |
|---|
| 42 | XCMD_SYNC_WAIT_ON_ERROR = 0, |
|---|
| 43 | XCMD_SYNC_HIDDEN = _XCMD__HIDDEN, |
|---|
| 44 | |
|---|
| 45 | // the XCMD_SERVSYNC_... types do not block the database server, but wait until the command finishes. |
|---|
| 46 | // |
|---|
| 47 | // This is a compromise between the XCMD_SERVSYNC_...- and XCMD_ASYNC_...-modes, which uses the database |
|---|
| 48 | // to synchronise between running command and its caller (arb) w/o blocking communication between them. |
|---|
| 49 | XCMD_SERVSYNC_WAITKEY = _XCMD__ACCESS_DB | _XCMD__WAITKEY, |
|---|
| 50 | XCMD_SERVSYNC_WAIT_ON_ERROR = _XCMD__ACCESS_DB, |
|---|
| 51 | XCMD_SERVSYNC_HIDDEN = _XCMD__ACCESS_DB | _XCMD__HIDDEN, |
|---|
| 52 | }; |
|---|
| 53 | |
|---|
| 54 | class XCmdType { |
|---|
| 55 | XCMD_TYPE type; |
|---|
| 56 | GBDATA *gb_main; |
|---|
| 57 | |
|---|
| 58 | public: |
|---|
| 59 | XCmdType(XCMD_TYPE type_, GBDATA *gb_main_) |
|---|
| 60 | : type(type_) , gb_main(gb_main_) |
|---|
| 61 | {} |
|---|
| 62 | |
|---|
| 63 | XCMD_TYPE get_type() const { return type; } |
|---|
| 64 | GBDATA *get_gb_main() const { return gb_main; } |
|---|
| 65 | }; |
|---|
| 66 | |
|---|
| 67 | GB_ERROR ARB_system(const char *cmd, XCmdType boundExectype); |
|---|
| 68 | |
|---|
| 69 | // ---------------------------------------- see also ../../AWT/awt_misc.hxx@SHELL_INTERFACE |
|---|
| 70 | // system/shell interface (for GUI apps) |
|---|
| 71 | // Notes: |
|---|
| 72 | // - AW_window parameter is an unused callback-dummy) |
|---|
| 73 | |
|---|
| 74 | class XCmdType; |
|---|
| 75 | |
|---|
| 76 | void ARB_system_in_console_cb(AW_window*, const char *command, const XCmdType *exectype); |
|---|
| 77 | |
|---|
| 78 | // for direct calls use these: |
|---|
| 79 | inline void ARB_system_in_console(const char *command, const XCmdType& exectype) { ARB_system_in_console_cb(NULp, command, &exectype); } |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | #else |
|---|
| 83 | #error xcmd.hxx included twice |
|---|
| 84 | #endif // XCMD_HXX |
|---|