17 #ifndef AGXIO_REMOTE_COMMAND_SERVER_H 18 #define AGXIO_REMOTE_COMMAND_SERVER_H 20 #include <agx/config/AGX_USE_WEBSOCKETS.h> 22 #if AGX_USE_WEBSOCKETS() 25 #include <civetweb/civetweb.h> 53 virtual ~ScriptListener() {}
60 class QueryArgumentTable;
63 static RemoteCommandServer *instance();
64 static bool hasInstance();
68 bool start(
agx::UInt16 port = 5656,
bool allowExternalRequests =
false);
75 bool isStarted()
const;
76 bool isUsingSSL()
const;
78 void setAuthenticationToken(
const agx::String& token);
81 bool add( agxIO::RemoteCommandServer::ScriptListener* scriptListener );
82 bool remove( agxIO::RemoteCommandServer::ScriptListener* scriptListener );
88 typedef std::function<bool (RemoteCommandServer *, mg_connection *, const QueryArgumentTable&)> CallbackFunction;
91 RequestHandler(
const CallbackFunction& func) : m_callback(func) {}
93 template<
class ClassT>
94 RequestHandler(
bool (ClassT::*fun)(RemoteCommandServer *, mg_connection *,
const QueryArgumentTable&), ClassT* obj) : m_callback(
std::bind(fun, obj,
std::placeholders:: _1,
std::placeholders:: _2,
std::placeholders:: _3)) {}
98 return m_callback ? true :
false;
101 bool operator() (RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments)
const 103 return m_callback(server, connection, arguments);
107 CallbackFunction m_callback;
110 void registerHandler(
const agx::String& uri,
const RequestHandler& handler);
113 static agx::String get_var(
const char* buf,
size_t buf_len,
const char* name);
114 static agx::String get_qsvar(
const mg_connection* connection,
const char* name);
116 static void writeResponse(
const agxJson::Value& eResponse, mg_connection* connection);
119 static void writeDummyResponse(mg_connection *connection);
121 void log(
const char *format, ...);
124 RemoteCommandServer(
const agx::Name& name =
"RemoteCommandServer");
125 virtual ~RemoteCommandServer();
127 friend class RemoteCommandServerSingleton;
130 bool handleAutoComplete(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
131 bool handleCommand(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
132 bool handleScript(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
133 bool handleScriptAutoComplete(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
134 bool handleJournalNavigationTree(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
135 bool handleJournalConfigurationList(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
136 bool readComponent(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
137 bool writeComponent(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
143 void writeNodeDescription(
agx::Object*
object, agxJson::Value& eNode);
144 int handleHttpEvent(mg_connection* connection);
145 int handleHttpAuth(mg_connection* connection);
146 static int mgAuthCallback(mg_connection* connection,
void* server);
147 static int mgRequestCallback(mg_connection* connection,
void* server);
148 static bool handle_jsonp(mg_connection* connection,
const mg_connection* request_info);
149 void parseArguments(QueryArgumentTable& result,
const mg_connection* connection);
151 void writeTreeStructureJson(
const agx::Object* node, agxJson::Value& eNode);
156 mg_context *m_mongoose;
160 ScriptListenerContainer m_scriptListeners;
161 bool m_allowExternalRequests;
167 RequestHandlerTable m_requestHandlerTable;
170 StringSet m_allowedComponentFileTypes;
173 class RemoteCommandServer::QueryArgumentTable :
public agx::HashTable<agx::String, agx::String>
182 const_iterator it = find( key );
184 return it !=
end() ? it->second : emptyString;
Representation of a path, a list of name components.
Inheritance with partial specialization due to bug with ref_ptr containers.
The agxIO namespace contains classes for reading, writing and finding files.
A component is an object containing other objects, enabling hierarchical structuring.
#define AGX_DECLARE_POINTER_TYPES(type)
Representation of a name string.
Base class providing referencing counted objects.
Smart pointer for handling referenced counted objects.
Handles testing of ports in a range.
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
AGXCORE_EXPORT Component * root()
Inheritance with partial specialization due to bug with ref_ptr containers.
agx::Object is a refcounted object with a name.