17 #ifndef AGXIO_REMOTE_COMMAND_SERVER_H
18 #define AGXIO_REMOTE_COMMAND_SERVER_H
22 #if AGX_USE_WEBSOCKETS()
25 #include <external/civetweb/civetweb.h>
64 static bool hasInstance();
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);
90 typedef std::function<bool (RemoteCommandServer *, mg_connection *, const QueryArgumentTable&)>
CallbackFunction;
95 template<
class ClassT>
100 return m_callback ?
true :
false;
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, ...);
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;
181 const_iterator it =
find( key );
183 return it !=
end() ? it->second : emptyString;
Representation of a path, a list of name components.
iterator find(const KeyT &key)
Find a key/value pair in the hash table given a key.
virtual bool autoComplete(const agx::String &, agx::StringVector &, agx::String &)
Fetch list of methods or similar used for auto complete.
const agx::String & operator[](const agx::String &key) const
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.
RequestHandler(bool(ClassT::*fun)(RemoteCommandServer *, mg_connection *, const QueryArgumentTable &), ClassT *obj)
std::function< bool(RemoteCommandServer *, mg_connection *, const QueryArgumentTable &)> CallbackFunction
virtual ~ScriptListener()
AGXLUA_EXPORT void error(lua_State *L)
RequestHandler(const CallbackFunction &func)
iterator end()
Iterator marking end of hash table.
Smart pointer for handling referenced counted objects.
Handles testing of ports in a range.
agx::Vector< ScriptListenerRef > ScriptListenerContainer
AGXCORE_EXPORT Component * root()
Inheritance with partial specialization due to bug with ref_ptr containers.
agx::ref_ptr< ScriptListener > ScriptListenerRef
agx::Object is a refcounted object with a name.