source: branches/help/ARBDB/ad_remote.h

Last change on this file was 15176, checked in by westram, 8 years ago
File size: 4.1 KB
Line 
1// ============================================================= //
2//                                                               //
3//   File      : ad_remote.h                                     //
4//   Purpose   :                                                 //
5//                                                               //
6//   Coded by Ralf Westram (coder@reallysoft.de) in April 2013   //
7//   Institute of Microbiology (Technical University Munich)     //
8//   http://www.arb-home.de/                                     //
9//                                                               //
10// ============================================================= //
11
12#ifndef AD_REMOTE_H
13#define AD_REMOTE_H
14
15#ifndef ARB_ASSERT_H
16#include "arb_assert.h"
17#endif
18#ifndef ARBDBT_H
19#include "arbdbt.h"
20#endif
21#ifndef ARB_SLEEP_H
22#include <arb_sleep.h>
23#endif
24
25struct MacroTalkSleep : public ARB_inc_sleep {
26    MacroTalkSleep() : ARB_inc_sleep(30, 250, MS, 20) {}
27};
28
29#define REMOTE_BASE_LEN     11 // len of REMOTE_BASE
30#define MAX_REMOTE_APP_LEN  30 // max len of application (e.g. "ARB_EDIT4")
31#define MAX_REMOTE_ITEM_LEN 7  // max len of item in APP container ("action", "result", ...)
32
33#define MAX_REMOTE_PATH_LEN (REMOTE_BASE_LEN + MAX_REMOTE_APP_LEN + 1 + MAX_REMOTE_ITEM_LEN)
34
35// --------------------------------------------------------------------------------
36
37class remote_awars {
38    mutable char  name[MAX_REMOTE_PATH_LEN+1];
39    int           length; // of awar-path inclusive last '/'
40    char         *app_id;
41
42    const char *item(const char *itemname) const {
43        arb_assert(strlen(itemname) <= MAX_REMOTE_ITEM_LEN);
44        strcpy(name+length, itemname);
45        return name;
46    }
47
48    void init() {
49#if defined(ASSERTION_USED)
50        size_t alen = strlen(app_id);
51        arb_assert(alen>0 && alen <= MAX_REMOTE_APP_LEN);
52#endif
53        length = sprintf(name, REMOTE_BASE "%s/", app_id);
54        arb_assert((length+MAX_REMOTE_ITEM_LEN) <= MAX_REMOTE_PATH_LEN);
55    }
56
57public:
58    remote_awars(const char *application)   : app_id(ARB_strdup(application))  { init(); }
59    remote_awars(const remote_awars& other) : app_id(ARB_strdup(other.app_id)) { init(); }
60    DECLARE_ASSIGNMENT_OPERATOR(remote_awars);
61    ~remote_awars() {
62        free(app_id);
63    }
64
65    // definition of term as used here:
66    // server = process running DB server ( = macro recorder/executor)
67    // client = process performing remote actions (e.g. "ARB_EDIT4"; is identical with server when executing a remote cmd for "ARB_NTREE")
68    // macro  = the executed perl macro
69
70    // The following DB entries trigger GUI interaction in ../SL/MACROS/dbserver.cxx@check_for_remote_command
71    // check_for_remote_command creates 'action', 'awar' and 'value' as soon as a client is ready to remote-execute.
72    const char *action() const { return item("action"); } // contains name of GUI-action to be performed
73    const char *result() const { return item("result"); } //
74    const char *awar() const   { return item("awar"); }
75    const char *value() const  { return item("value"); }
76
77    // synchronization (needed to avoid that multiple clients with same application_id randomly accept remote-commands)
78    const char *authReq() const  { return item("authReq"); } // == 1 -> a macro wants to remote-execute in some client [set to 1 by macro, reset to 0 by server when last macro terminates]
79    const char *authAck() const  { return item("authAck"); } // == pid -> client received and accepted 'authReq' [set to its pid by client, reset to 0 by macro when granting authorization or by server when last macro terminates]
80    const char *granted() const  { return item("granted"); } // == pid -> client with pid is authorized to remote-execute commands [set to the clients pid by macro, reset by server when last macro terminates]
81
82    const char *recAuth() const  { return item("recAuth"); } // == pid -> client/server with pid is authorized to record commands [set/cleared by client/server; results in error if multiple pids try to authorize]
83
84    const char *appID() const { return app_id; }
85};
86
87#else
88#error ad_remote.h included twice
89#endif // AD_REMOTE_H
Note: See TracBrowser for help on using the repository browser.