| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #include "API/WebAPI.h"
- #include "DataInterface/GraphClient.h"
- #include <DataStorageClient.h>
- #include <HttpServer.h>
- #include <INIReader.h>
- #include <Logging.h>
- #include <MySQLClient.h>
- #include <sstream>
- int main(int argc, char** argv)
- {
- try
- {
- Logging::OpenLog();
- Logging::SetLogMask(Logging::Severity::Info);
- INIReader iniReader("DataStorageAPI.ini");
- if (iniReader.ParseError() != 0)
- throw std::runtime_error("Can't read DataLogger.ini.");
- Logging::Log(Logging::Severity::Info, "Starting DataStorageAPI");
- int port = iniReader.GetInteger("DataStorageAPI", "Port", 0);
- if (port == 0)
- throw std::runtime_error("Port directive missing in ini file.");
- std::string table = iniReader.Get("DataStorageAPI", "Table", "");
- if (table.empty())
- throw std::runtime_error("Table directive missing in ini file.");
- std::shared_ptr<MySQL::MySQLClient> pMySQLClient = std::make_shared<MySQL::MySQLClient>();
- {
- std::string hostname = iniReader.Get("MySQL", "Hostname", "");
- if (hostname.empty())
- throw std::runtime_error("MySQL Hostname directive missing in ini file.");
- std::string username = iniReader.Get("MySQL", "Username", "");
- if (username.empty())
- throw std::runtime_error("MySQL Username directive missing in ini file.");
- std::string password = iniReader.Get("MySQL", "Password", "");
- if (password.empty())
- throw std::runtime_error("MySQL Password directive missing in ini file.");
- std::string database = iniReader.Get("MySQL", "Database", "");
- if (database.empty())
- throw std::runtime_error("MySQL Database directive missing in ini file.");
- pMySQLClient->Connect(hostname, username, password, database);
- }
- DataStorage::DataStorageClient dataStorageClient(pMySQLClient, table);
- DataStorageInterface::DataInterface::GraphClient graphClient(pMySQLClient.get());
- Http::HttpServer::CallbackMethod callback = std::bind(&DataStorageInterface::API::WebAPI::ProcessQuery, &dataStorageClient, &graphClient, std::placeholders::_1, std::placeholders::_2);
- Http::HttpServer server(port, callback);
- Logging::Log(Logging::Severity::Info, "Startup Complete");
- server.Wait();
- Logging::Log(Logging::Severity::Info, "Stopping DataStorageAPI...");
- Logging::CloseLog();
- }
- catch (const std::exception& e)
- {
- std::stringstream ss;
- ss << "ERROR: " << e.what() << std::endl;
- Logging::Log(Logging::Severity::Error, ss.str());
- Logging::CloseLog();
- return -1;
- }
- return 0;
- }
|