Fixed warning
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
class RestHttpDevice : public osgGA::Device, OpenThreads::Thread {
|
||||
|
||||
public:
|
||||
|
||||
|
||||
class RequestHandler : public osg::Referenced {
|
||||
public:
|
||||
typedef std::map<std::string, std::string> Arguments;
|
||||
@@ -32,27 +32,27 @@ public:
|
||||
, _device(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual bool operator()(const std::string& request_path, const std::string& full_request_path, const Arguments& arguments, http::server::reply& reply) = 0;
|
||||
|
||||
|
||||
const std::string& getRequestPath() const { return _requestPath; }
|
||||
|
||||
|
||||
virtual void describeTo(std::ostream& out) const
|
||||
{
|
||||
out << getRequestPath() << ": no description available";
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
void setDevice(RestHttpDevice* device) { _device = device; }
|
||||
RestHttpDevice* getDevice() { return _device; }
|
||||
|
||||
|
||||
void reportMissingArgument(const std::string& argument, http::server::reply& reply) const
|
||||
{
|
||||
OSG_WARN << "RequestHandler :: missing argument '" << argument << "' for " << getRequestPath() << std::endl;
|
||||
reply.content = "{ \"result\": 0, \"error\": \"missing argument '"+argument+"'\"}";
|
||||
reply.status = http::server::reply::ok;
|
||||
}
|
||||
|
||||
|
||||
bool sendOkReply(http::server::reply& reply)
|
||||
{
|
||||
if (reply.content.empty())
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool getStringArgument(const Arguments& arguments, const std::string& argument, http::server::reply& reply, std::string& result) const
|
||||
{
|
||||
Arguments::const_iterator itr = arguments.find(argument);
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
result = itr->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool getHexArgument(const Arguments& arguments, const std::string& argument, http::server::reply& reply, int& value) const
|
||||
{
|
||||
std::string hex_str;
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
value = strtoul(hex_str.c_str(), NULL, 16);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool getIntArgument(const Arguments& arguments, const std::string& argument, http::server::reply& reply, int& value) const
|
||||
{
|
||||
std::string str;
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
value = strtol(str.c_str(), NULL, 10);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool getDoubleArgument(const Arguments& arguments, const std::string& argument, http::server::reply& reply, double& value) const
|
||||
{
|
||||
std::string str;
|
||||
@@ -99,54 +99,54 @@ public:
|
||||
value = strtod(str.c_str(), NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// set the request-path, works only from the constructor
|
||||
void setRequestPath(const std::string& request_path) { _requestPath = request_path; }
|
||||
protected:
|
||||
|
||||
|
||||
double getTimeStamp(const Arguments& arguments, http::server::reply& reply)
|
||||
{
|
||||
double time_stamp(0.0);
|
||||
getDoubleArgument(arguments, "time", reply, time_stamp);
|
||||
return time_stamp;
|
||||
}
|
||||
|
||||
|
||||
double getLocalTime(const Arguments& arguments, http::server::reply& reply)
|
||||
{
|
||||
return getLocalTime(getTimeStamp(arguments, reply));
|
||||
}
|
||||
|
||||
|
||||
double getLocalTime(double time_stamp)
|
||||
{
|
||||
return getDevice()->getLocalTime(time_stamp);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
std::string _requestPath;
|
||||
RestHttpDevice* _device;
|
||||
friend class RestHttpDevice;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
typedef std::multimap<std::string, osg::ref_ptr<RequestHandler> > RequestHandlerMap;
|
||||
|
||||
|
||||
RestHttpDevice(const std::string& listening_address, const std::string& listening_port, const std::string& doc_path);
|
||||
~RestHttpDevice();
|
||||
|
||||
|
||||
void addRequestHandler(RequestHandler* handler);
|
||||
|
||||
|
||||
bool handleRequest(const std::string& request_path, http::server::reply& reply);
|
||||
|
||||
|
||||
virtual void run();
|
||||
|
||||
|
||||
void describeTo(std::ostream& out) const;
|
||||
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, const RestHttpDevice& device)
|
||||
{
|
||||
device.describeTo(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
double getLocalTime(double time_stamp)
|
||||
{
|
||||
if (_firstEventRemoteTimeStamp < 0)
|
||||
@@ -158,7 +158,7 @@ public:
|
||||
// std::cout << "ts: "<< time_stamp << " -> " << local_time << std::endl;
|
||||
return local_time;
|
||||
}
|
||||
|
||||
|
||||
bool isNewer(double time_stamp)
|
||||
{
|
||||
bool is_newer(time_stamp > _lastEventRemoteTimeStamp);
|
||||
@@ -166,12 +166,12 @@ public:
|
||||
_lastEventRemoteTimeStamp = time_stamp;
|
||||
return is_newer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
virtual bool checkEvents()
|
||||
{
|
||||
if (_targetMouseChanged && (fabs(_currentMouseX - _targetMouseY) > 0.1f) || (fabs(_currentMouseY - _targetMouseY) > 0.1))
|
||||
if (_targetMouseChanged && ((fabs(_currentMouseX - _targetMouseY) > 0.1f) || (fabs(_currentMouseY - _targetMouseY) > 0.1y)))
|
||||
{
|
||||
static const float scalar = 0.2f;
|
||||
_currentMouseX = (1.0f - scalar) * _currentMouseX + scalar * _targetMouseX;
|
||||
@@ -180,7 +180,7 @@ public:
|
||||
}
|
||||
return !(getEventQueue()->empty());
|
||||
}
|
||||
|
||||
|
||||
void setTargetMousePosition(float x, float y, bool force = false)
|
||||
{
|
||||
_targetMouseChanged = true;
|
||||
@@ -189,9 +189,9 @@ public:
|
||||
_currentMouseX = x; _currentMouseY = y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
void parseArguments(const std::string request_path, RequestHandler::Arguments& arguments);
|
||||
http::server::server _server;
|
||||
@@ -202,7 +202,7 @@ private:
|
||||
double _lastEventRemoteTimeStamp;
|
||||
float _currentMouseX, _currentMouseY, _targetMouseX, _targetMouseY;
|
||||
bool _targetMouseChanged;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -210,17 +210,17 @@ private:
|
||||
class SendKeystrokeRequestHandler : public RestHttpDevice::RequestHandler {
|
||||
public:
|
||||
SendKeystrokeRequestHandler(const std::string& request_path, int key) : RestHttpDevice::RequestHandler(request_path), _key(key) {}
|
||||
|
||||
|
||||
virtual bool operator()(const std::string& request_path, const std::string& full_request_path, const Arguments& arguments, http::server::reply& reply)
|
||||
{
|
||||
double local_time = getLocalTime(arguments, reply);
|
||||
|
||||
|
||||
getDevice()->getEventQueue()->keyPress(_key, local_time);
|
||||
getDevice()->getEventQueue()->keyRelease(_key, local_time);
|
||||
|
||||
|
||||
return sendOkReply(reply);
|
||||
}
|
||||
|
||||
|
||||
virtual void describeTo(std::ostream& out) const
|
||||
{
|
||||
out << getRequestPath() << ": send KEY_DOWN + KEY_UP, code: 0x" << std::hex << _key << std::dec;
|
||||
|
||||
Reference in New Issue
Block a user