EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
APIServer Class Reference

Handles queries from external clients for many kinds of returned xml structures according to CCP's API plus extensions for EVEmu. More...

#include "APIServer.h"

Inheritance diagram for APIServer:
Collaboration diagram for APIServer:

Classes

class  Lock
 

Public Member Functions

 APIServer ()
 
void Run ()
 
void Stop ()
 
void CreateServices (const PyServiceMgr &services)
 
std::string & url ()
 
std::tr1::shared_ptr
< std::vector< char > > 
GetXML (const APICommandCall *pAPICommandCall)
 
- Public Member Functions inherited from Singleton< APIServer >
 Singleton ()
 Primary constructor. More...
 

Static Public Attributes

static const char *const FallbackURL = "http://api.eveonline.com/"
 

Private Member Functions

void RunInternal ()
 

Private Attributes

std::unique_ptr
< boost::asio::detail::thread > 
_ioThread
 
std::unique_ptr
< boost::asio::io_context > 
_io
 
std::unique_ptr
< APIServerListener
_listener
 
std::string _url
 
std::string _basePath
 
boost::asio::detail::mutex _limboLock
 
bool runonce
 
std::tr1::shared_ptr< std::string > m_xmlString
 
std::map< std::string,
APIServiceManager * > 
m_APIServiceManagers
 

Additional Inherited Members

- Static Public Member Functions inherited from Singleton< APIServer >
static APIServerget ()
 
- Static Protected Attributes inherited from Singleton< APIServer >
static std::shared_ptr< APIServermInstance
 

Detailed Description

Handles queries from external clients for many kinds of returned xml structures according to CCP's API plus extensions for EVEmu.

A very limited HTTP server that can efficiently deliver many different xml structured documents to clients Uses asio for efficient asynchronous network communication

Author
Aknor Jaden
Date
July 2011

Definition at line 44 of file APIServer.h.

Constructor & Destructor Documentation

APIServer::APIServer ( )

Definition at line 41 of file APIServer.cpp.

References _url, runonce, and sConfig.

42 {
43  runonce = false;
44  std::stringstream urlBuilder;
45  urlBuilder << "http://" << sConfig.net.apiServer << ":" << (sConfig.net.apiServerPort) << "/";
46  _url = urlBuilder.str();
47 }
#define sConfig
A macro for easier access to the singleton.
bool runonce
Definition: APIServer.h:69
std::string _url
Definition: APIServer.h:66

Member Function Documentation

void APIServer::CreateServices ( const PyServiceMgr services)

Definition at line 49 of file APIServer.cpp.

References m_APIServiceManagers, and runonce.

50 {
51  if( !runonce )
52  {
53  m_APIServiceManagers.insert(std::make_pair("base", new APIServiceManager(services)));
54  m_APIServiceManagers.insert(std::make_pair("account", new APIAccountManager(services)));
55  m_APIServiceManagers.insert(std::make_pair("admin", new APIAdminManager(services)));
56  m_APIServiceManagers.insert(std::make_pair("char", new APICharacterManager(services)));
57  m_APIServiceManagers.insert(std::make_pair("corp", new APICorporationManager(services)));
58  m_APIServiceManagers.insert(std::make_pair("eve", new APIEveSystemManager(services)));
59  m_APIServiceManagers.insert(std::make_pair("map", new APIMapManager(services)));
60  m_APIServiceManagers.insert(std::make_pair("object", new APIActiveObjectManager(services)));
61  m_APIServiceManagers.insert(std::make_pair("server", new APIServerManager(services)));
62  }
63 
64  runonce = true;
65 }
std::map< std::string, APIServiceManager * > m_APIServiceManagers
Definition: APIServer.h:73
Generic Base Class used to derive classes for specific service handlers (character, corporation, etc)
bool runonce
Definition: APIServer.h:69
std::tr1::shared_ptr< std::vector< char > > APIServer::GetXML ( const APICommandCall pAPICommandCall)

Definition at line 67 of file APIServer.cpp.

References m_APIServiceManagers, m_xmlString, and sLog.

68 {
69  //if( m_APIServiceManagers.find(pAPICommandCall->at(0).first) != m_APIServiceManagers.end() )
70  if( pAPICommandCall->find( "service" ) == pAPICommandCall->end() )
71  {
72  sLog.Error( "APIserver::GetXML()", "Cannot find 'service' specifier in pAPICommandCall packet" );
73  return std::tr1::shared_ptr<std::vector<char> >(new std::vector<char>() );
74  //return std::tr1::shared_ptr<std::string>(new std::string(""));
75  }
76 
77  if( m_APIServiceManagers.find(pAPICommandCall->find( "service" )->second) != m_APIServiceManagers.end() )
78  {
79  // Get reference to service manager object and call ProcessCall() with the pAPICommandCall packet
80  //m_xmlString = m_APIServiceManagers.find("base")->second->ProcessCall(pAPICommandCall);
81  m_xmlString = m_APIServiceManagers.find( pAPICommandCall->find( "service" )->second )->second->ProcessCall( pAPICommandCall );
82 
83  // Convert the std::string to the std::vector<char>:
84  std::tr1::shared_ptr<std::vector<char> > ret = std::tr1::shared_ptr<std::vector<char> >(new std::vector<char>());
85  unsigned long len = m_xmlString->length();
86  for(size_t i=0; i<m_xmlString->length(); i++)
87  ret->push_back(m_xmlString->at(i));
88 
89  return ret;
90  }
91  else
92  {
93  // Service call not found, so return NULL:
94  return std::tr1::shared_ptr<std::vector<char> >(new std::vector<char>() );
95  //return NULL;
96  //m_xmlString = m_APIServiceManagers.find("base")->second->ProcessCall(pAPICommandCall);
97  }
98 }
std::map< std::string, APIServiceManager * > m_APIServiceManagers
Definition: APIServer.h:73
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
std::tr1::shared_ptr< std::string > m_xmlString
Definition: APIServer.h:71
void APIServer::Run ( )

Definition at line 105 of file APIServer.cpp.

References _ioThread, and RunInternal().

106 {
107  _ioThread = std::unique_ptr<boost::asio::detail::thread>(new boost::asio::detail::thread(std::bind(&APIServer::RunInternal, this)));
108 }
std::unique_ptr< boost::asio::detail::thread > _ioThread
Definition: APIServer.h:63
void RunInternal()
Definition: APIServer.cpp:116

Here is the call graph for this function:

void APIServer::RunInternal ( )
private

Definition at line 116 of file APIServer.cpp.

References _io, and _listener.

Referenced by Run().

117 {
118  _io = std::unique_ptr<boost::asio::io_context>(new boost::asio::io_context());
119  _listener = std::unique_ptr<APIServerListener>(new APIServerListener(*_io));
120  _io->run();
121 }
Handles listening for new clients.
std::unique_ptr< boost::asio::io_context > _io
Definition: APIServer.h:64
std::unique_ptr< APIServerListener > _listener
Definition: APIServer.h:65

Here is the caller graph for this function:

void APIServer::Stop ( )

Definition at line 110 of file APIServer.cpp.

References _io, and _ioThread.

111 {
112  _io->stop();
113  _ioThread->join();
114 }
std::unique_ptr< boost::asio::detail::thread > _ioThread
Definition: APIServer.h:63
std::unique_ptr< boost::asio::io_context > _io
Definition: APIServer.h:64
std::string & APIServer::url ( )

Definition at line 100 of file APIServer.cpp.

References _url.

101 {
102  return _url;
103 }
std::string _url
Definition: APIServer.h:66

Member Data Documentation

std::string APIServer::_basePath
private

Definition at line 67 of file APIServer.h.

std::unique_ptr<boost::asio::io_context> APIServer::_io
private

Definition at line 64 of file APIServer.h.

Referenced by RunInternal(), and Stop().

std::unique_ptr<boost::asio::detail::thread> APIServer::_ioThread
private

Definition at line 63 of file APIServer.h.

Referenced by Run(), and Stop().

boost::asio::detail::mutex APIServer::_limboLock
private

Definition at line 68 of file APIServer.h.

std::unique_ptr<APIServerListener> APIServer::_listener
private

Definition at line 65 of file APIServer.h.

Referenced by RunInternal().

std::string APIServer::_url
private

Definition at line 66 of file APIServer.h.

Referenced by APIServer(), and url().

const char *const APIServer::FallbackURL = "http://api.eveonline.com/"
static

Definition at line 58 of file APIServer.h.

Referenced by APIServerConnection::RedirectLocation().

std::map<std::string, APIServiceManager *> APIServer::m_APIServiceManagers
private

Definition at line 73 of file APIServer.h.

Referenced by CreateServices(), and GetXML().

std::tr1::shared_ptr<std::string> APIServer::m_xmlString
private

Definition at line 71 of file APIServer.h.

Referenced by GetXML().

bool APIServer::runonce
private

Definition at line 69 of file APIServer.h.

Referenced by APIServer(), and CreateServices().


The documentation for this class was generated from the following files: