#pragma once
/************************************************************************
MeOS - Orienteering Software
Copyright (C) 2009-2017 Melin Software HB
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Melin Software HB - software@melin.nu - www.melin.nu
Eksoppsvägen 16, SE-75646 UPPSALA, Sweden
************************************************************************/
/** Class for providing a MeOS REST service */
#include
#include
#include
#include
#include
#include
namespace restbed {
class Service;
class Session;
};
class RestServer {
private:
struct EventRequest {
EventRequest() : state(false) {}
multimap parameters;
string answer;
atomic_bool state; //false - asked, true - answerd
bool isCompleted() {
return state;
}
};
mutex lock;
atomic_bool hasAnyRequest;
shared_ptr service;
shared_ptr restService;
condition_variable waitForCompletion;
deque> requests;
void getData(oEvent &ref, const string &what, const multimap ¶m, string &answer);
void compute(oEvent &ref);
void startThread(int port);
static void getSelection(const string ¶m, set &sel);
void handleRequest(const shared_ptr &session);
friend void method_handler(const shared_ptr< restbed::Session > session);
shared_ptr addRequest(multimap ¶m);
shared_ptr getRequest();
vector responseTimes;
RestServer();
static vector< shared_ptr > startedServers;
RestServer(const RestServer &);
RestServer & operator=(const RestServer &) const;
public:
~RestServer();
void startService(int port);
void stop();
static shared_ptr construct();
static void remove(shared_ptr server);
static void computeRequested(oEvent &ref);
struct Statistics {
int numRequests;
int averageResponseTime;
int maxResponseTime;
};
void getStatistics(Statistics &s);
};