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 <external/civetweb/civetweb.h> 53 virtual ~ScriptListener() {}
60 class QueryArgumentTable;
63 static RemoteCommandServer *instance();
64 static bool hasInstance();
67 RemoteCommandServer(
const agx::Name& name =
"RemoteCommandServer");
70 bool start(
agx::UInt16 port = 5656,
bool allowExternalRequests =
false);
77 bool isStarted()
const;
78 bool isUsingSSL()
const;
80 void setAuthenticationToken(
const agx::String& token);
83 bool add( agxIO::RemoteCommandServer::ScriptListener* scriptListener );
84 bool remove( agxIO::RemoteCommandServer::ScriptListener* scriptListener );
90 typedef std::function<bool (RemoteCommandServer *, mg_connection *, const QueryArgumentTable&)> CallbackFunction;
93 RequestHandler(
const CallbackFunction& func) : m_callback(func) {}
95 template<
class ClassT>
96 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)) {}
100 return m_callback ? true :
false;
103 bool operator() (RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments)
const 105 return m_callback(server, connection, arguments);
109 CallbackFunction m_callback;
112 void registerHandler(
const agx::String& uri,
const RequestHandler& handler);
115 static agx::String get_var(
const char* buf,
size_t buf_len,
const char* name);
116 static agx::String get_qsvar(
const mg_connection* connection,
const char* name);
118 static void writeResponse(
const agxJson::Value& eResponse, mg_connection* connection);
121 static void writeDummyResponse(mg_connection *connection);
123 void log(
const char *format, ...);
126 virtual ~RemoteCommandServer();
129 bool handleAutoComplete(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
130 bool handleCommand(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
131 bool handleScript(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
132 bool handleScriptAutoComplete(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
133 bool handleJournalNavigationTree(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
134 bool handleJournalConfigurationList(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
135 bool readComponent(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
136 bool writeComponent(RemoteCommandServer *server, mg_connection *connection,
const QueryArgumentTable& arguments);
142 void writeNodeDescription(
agx::Object*
object, agxJson::Value& eNode);
143 int handleHttpEvent(mg_connection* connection);
144 int handleHttpAuth(mg_connection* connection);
145 static int mgAuthCallback(mg_connection* connection,
void* server);
146 static int mgRequestCallback(mg_connection* connection,
void* server);
147 static bool handle_jsonp(mg_connection* connection,
const mg_connection* request_info);
148 void parseArguments(QueryArgumentTable& result,
const mg_connection* connection);
150 void writeTreeStructureJson(
const agx::Object* node, agxJson::Value& eNode);
155 mg_context *m_mongoose;
159 ScriptListenerContainer m_scriptListeners;
160 bool m_allowExternalRequests;
166 RequestHandlerTable m_requestHandlerTable;
169 StringSet m_allowedComponentFileTypes;
172 class RemoteCommandServer::QueryArgumentTable :
public agx::HashTable<agx::String, agx::String>
181 const_iterator it = find( key );
183 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.