Sirikata
libcore/plugins/http/HttpCommander.hpp
Go to the documentation of this file.
00001 // Copyright (c) 2012 Sirikata Authors. All rights reserved.
00002 // Use of this source code is governed by a BSD-style license that can
00003 // be found in the LICENSE file.
00004 
00005 #ifndef _SIRIKATA_LIBCORE_HTTP_COMMANDER_HPP_
00006 #define _SIRIKATA_LIBCORE_HTTP_COMMANDER_HPP_
00007 
00008 #include <sirikata/core/command/Commander.hpp>
00009 #include "HttpServer.hpp"
00010 
00011 namespace Sirikata {
00012 namespace Command {
00013 
00014 class HttpCommander :
00015         public Commander,
00016         HttpRequestListener
00017 {
00018 public:
00019     HttpCommander(Context* ctx, const String& host, uint16 port);
00020     virtual ~HttpCommander();
00021 
00022     // HttpRequestListener Interface
00023     virtual void onHttpRequest(HttpServer* server, HttpRequestID id, String& path, String& query, String& fragment, Headers& headers, String& body);
00024 
00025     // Commander Interface
00026     virtual void result(CommandID id, const Result& result);
00027 
00028 private:
00029     // Encode and send a response. If something goes wrong with encoding, sends
00030     // an error code instead.
00031     void sendResponse(HttpRequestID id, HttpStatus status, const Result& result);
00032 
00033 
00034     Context* mContext;
00035     HttpServer mServer;
00036 }; // class HttpCommander
00037 
00038 } // namespace Command
00039 } // namespace Sirikata
00040 
00041 
00042 #endif //_SIRIKATA_LIBCORE_HTTP_COMMANDER_HPP_