mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-27 08:25:53 -04:00
added resource_api and rs-nogui-webui (requires libmicrohttpd, Html files are not included)
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8047 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
97831d0667
commit
ad1bc7f3b8
38 changed files with 5547 additions and 2 deletions
86
libresapi/src/api/ApiServer.h
Normal file
86
libresapi/src/api/ApiServer.h
Normal file
|
@ -0,0 +1,86 @@
|
|||
#pragma once
|
||||
|
||||
#include <retroshare/rsplugin.h>
|
||||
|
||||
#include "ApiTypes.h"
|
||||
#include "PeersHandler.h"
|
||||
#include "IdentityHandler.h"
|
||||
#ifdef FIXME
|
||||
#include "WallHandler.h"
|
||||
#endif
|
||||
#include "ServiceControlHandler.h"
|
||||
#include "StateTokenServer.h"
|
||||
#include "FileSearchHandler.h"
|
||||
#include "TransfersHandler.h"
|
||||
|
||||
namespace resource_api{
|
||||
|
||||
class ApiServerMainModules;
|
||||
class ApiServerWallModule;
|
||||
|
||||
// main entry point for all resource api calls
|
||||
|
||||
// call chain is like this:
|
||||
// Wt -> ApiServerWt -> ApiServer -> different handlers
|
||||
// later i want to replace the parts with Wt with something else
|
||||
// (Wt is a too large framework, a simple http server would be enough)
|
||||
// maybe use libmicrohttpd
|
||||
// the other use case for this api is a qt webkit view
|
||||
// this works without html, the webkitview calls directly into our c++ code
|
||||
|
||||
// general part of the api server
|
||||
// should work with any http library or a different transport protocol
|
||||
class ApiServer
|
||||
{
|
||||
public:
|
||||
ApiServer();
|
||||
~ApiServer();
|
||||
|
||||
// it is currently hard to separate into http and non http stuff
|
||||
// mainly because the http path is used in the api
|
||||
// this has to change later
|
||||
// for now let the http part make the request object
|
||||
// and the general apiserver part makes the response
|
||||
std::string handleRequest(Request& request);
|
||||
|
||||
// load the main api modules
|
||||
void loadMainModules(const RsPlugInInterfaces& ifaces);
|
||||
|
||||
// only after rswall was started!
|
||||
#ifdef FIXME
|
||||
void loadWallModule(const RsPlugInInterfaces& ifaces, RsWall::RsWall* wall);
|
||||
#endif
|
||||
|
||||
// allows to add more handlers
|
||||
// make sure the livetime of the handlers is longer than the api server
|
||||
template <class T>
|
||||
void addResourceHandler(std::string name, T* instance, ResponseTask* (T::*callback)(Request& req, Response& resp));
|
||||
template <class T>
|
||||
void addResourceHandler(std::string name, T* instance, void (T::*callback)(Request& req, Response& resp));
|
||||
|
||||
StateTokenServer* getStateTokenServer(){ return &mStateTokenServer; }
|
||||
|
||||
private:
|
||||
StateTokenServer mStateTokenServer; // goes first, as others may depend on it
|
||||
// is always loaded, because it has no dependencies
|
||||
|
||||
// only pointers here, to load/unload modules at runtime
|
||||
ApiServerMainModules* mMainModules; // loaded when RS is started
|
||||
ApiServerWallModule* mWallModule; // only loaded in rssocialnet plugin
|
||||
|
||||
ResourceRouter mRouter;
|
||||
};
|
||||
|
||||
// implementations
|
||||
template <class T>
|
||||
void ApiServer::addResourceHandler(std::string name, T* instance, ResponseTask* (T::*callback)(Request& req, Response& resp))
|
||||
{
|
||||
mRouter.addResourceHandler(name, instance, callback);
|
||||
}
|
||||
template <class T>
|
||||
void ApiServer::addResourceHandler(std::string name, T* instance, void (T::*callback)(Request& req, Response& resp))
|
||||
{
|
||||
mRouter.addResourceHandler(name, instance, callback);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue