MantisBase v0.3.4
Loading...
Searching...
No Matches
mb::MantisBase Class Reference

MantisBase entry point. More...

#include <mantisbase.h>

Public Member Functions

 ~MantisBase ()
 
 MantisBase (const MantisBase &)=delete
 
MantisBaseoperator= (const MantisBase &)=delete
 
 MantisBase (MantisBase &&)=delete
 
MantisBaseoperator= (MantisBase &&)=delete
 
int run ()
 Start the http server and start listening for requests.
 
void close ()
 Close the application and reset object instances that are dependent on the class.
 
int port () const
 Retrieve HTTP Listening port.
 
void setPort (const int &port)
 Set a new port value for HTTP server.
 
int poolSize () const
 Retrieve the database pool size value.
 
std::string host () const
 Retrieve HTTP Server host address. For instance, a host of 127.0.0.1, 0.0.0.0, etc.
 
void setHost (const std::string &host)
 Update HTTP Server host address.
 
std::string publicDir () const
 Retrieve the public static file directory.
 
void setPublicDir (const std::string &dir)
 Update HTTP server static file directory.
 
std::string dataDir () const
 Retrieves the data directory where SQLite db and files are stored.
 
void setDataDir (const std::string &dir)
 Update the data directory for MantisApp.
 
std::string scriptsDir () const
 Retrieves the scripts directory where JavaScript files are stored used for extending functionality in Mantis.
 
void setScriptsDir (const std::string &dir)
 Update the scripts directory for MantisApp.
 
std::string dbType () const
 Retrieves the active database type.
 
void setDbType (const std::string &dbType)
 
Databasedb () const
 Get the database unit object.
 
argparse::ArgumentParser & cmd () const
 Get the commandline parser object.
 
Routerrouter () const
 Get the router object instance.
 
KeyValStoresettings () const
 Get the KeyValue unit object.
 
Loggerlogs () const
 Get the logs unit object.
 
RealtimeDBrt () const
 Get the realtime unit (SQLite/PostgreSQL change detection for SSE /api/v1/realtime).
 
Entity entity (const std::string &entity_name) const
 Fetch a table schema encapsulated by an Entity object from given the table name. If table does not exist yet, return an emty object.
 
bool hasEntity (const std::string &entity_name) const
 Check if table schema encapsulated by an Entity object from given the table name exists. If table does not exist yet, return false.
 
duk_context * ctx () const
 Get the duktape context.
 
void openBrowserOnStart () const
 Launch browser with the admin dashboard page. If all goes well, the default OS browser should open (if not opened) with the admin dashboard URL.
 
std::chrono::time_point< std::chrono::steady_clock > startTime () const
 Get the server start time in std::chrono::
 
bool isDevMode () const
 

Static Public Member Functions

static MantisBaseinstance ()
 Retrieve existing application instance.
 
static MantisBasecreate (int argc, char **argv)
 Create class instance given cmd args passed in.
 
static MantisBasecreate (const json &config=json::object())
 Convenience function to allow creating class instance given the values needed to set up the app without any need for passing in cmd args.
 
static int quit (const int &exitCode=0, const std::string &reason="Something went wrong!")
 Quit the running application immediately.
 
static std::string jwtSecretKey ()
 Retrieve the JWT secret key.
 
static std::string appVersion ()
 
static int appMinorVersion ()
 Fetch the major version.
 
static int appMajorVersion ()
 Fetch the minor version.
 
static int appPatchVersion ()
 Fetch the patch version.
 

Detailed Description

MantisBase entry point.

This class handles the entrypoint to the Mantis world, where we can set/get application flags and variables, as well as access other application units. These units are:

  • DatabaseMgr: For all database handling,
    See also
    DatabaseMgr for more information.
  • HttpMgr: Low-level http server operation and routing.
    See also
    HttpMgr for low-level access or
    RouterMgr for a high level routing methods.
  • LogsMgr: For logging capabilities,
    See also
    LoggingMgr for more details.
  • RouterMgr: High level routing wrapper on top of
    See also
    HttpMgr,
    RouterMgr for more details.
  • ValidatorMgr: A validation store using regex,
    See also
    Validator for more details.

Constructor & Destructor Documentation

◆ ~MantisBase()

mb::MantisBase::~MantisBase ( )

◆ MantisBase() [1/2]

mb::MantisBase::MantisBase ( const MantisBase )
delete

◆ MantisBase() [2/2]

mb::MantisBase::MantisBase ( MantisBase &&  )
delete

Member Function Documentation

◆ appMajorVersion()

int mb::MantisBase::appMajorVersion ( )
static

Fetch the minor version.

◆ appMinorVersion()

int mb::MantisBase::appMinorVersion ( )
static

Fetch the major version.

◆ appPatchVersion()

int mb::MantisBase::appPatchVersion ( )
static

Fetch the patch version.

◆ appVersion()

std::string mb::MantisBase::appVersion ( )
static

Fetch the application version

Returns
Application version

◆ close()

void mb::MantisBase::close ( )

Close the application and reset object instances that are dependent on the class.

Internally, this stops running http server, disconnects from the database and does any required cleanup

◆ cmd()

argparse::ArgumentParser & mb::MantisBase::cmd ( ) const

Get the commandline parser object.

◆ create() [1/2]

MantisBase & mb::MantisBase::create ( const json config = json::object())
static

Convenience function to allow creating class instance given the values needed to set up the app without any need for passing in cmd args.

The expected values are: { "database": "<db type>", "connection": "<connection string>", "dataDir": "<path to dir>", "publicDir": "<path to dir>", "scriptsDir": "<path to dir>", "dev": true, "serve": { "port": <int>, "host": "<host IP/addr>", "poolSize": <int>, }, "admins": { "add": "<email to add>", "rm": "<email to remove>" } }

Note
All primary options above are optional, you can omit to use default values.
admins subcommand expects a subcommand with either the add or rm.
serve command can have an empty json object and the app will configure with defaults.
json arg1 = json::object();
auto& app1 = MantisApp::create(arg2);
json arg2;
arg2["database"] = "PSQL";
arg2["database"] = "dbname=mantis username=postgres password=12342532";
arg2["dev"] = true;
arg2["serve"] = json::object{};
auto& app2 = MantisApp::create(arg2);
nlohmann::json json
Shorten JSON namespace.
Definition context_store.h:18
Parameters
configJSON Object bearing the cmd args values to be used
Returns
A reference to the created class instance

◆ create() [2/2]

MantisBase & mb::MantisBase::create ( int  argc,
char **  argv 
)
static

Create class instance given cmd args passed in.

See also
parseArgs() for expected cmd args to be passed in.
Parameters
argcNumber of cmd args
argvChar array list
Returns
Reference to the created class instance

◆ ctx()

duk_context * mb::MantisBase::ctx ( ) const

Get the duktape context.

◆ dataDir()

std::string mb::MantisBase::dataDir ( ) const

Retrieves the data directory where SQLite db and files are stored.

Returns
MantisApp data directory.

◆ db()

Database & mb::MantisBase::db ( ) const

Get the database unit object.

◆ dbType()

std::string mb::MantisBase::dbType ( ) const

Retrieves the active database type.

Returns
Selected DatabaseType enum value.

◆ entity()

Entity mb::MantisBase::entity ( const std::string &  entity_name) const

Fetch a table schema encapsulated by an Entity object from given the table name. If table does not exist yet, return an emty object.

Parameters
entity_nameName of the table of interest
Returns
Entity object for the selected table

◆ hasEntity()

bool mb::MantisBase::hasEntity ( const std::string &  entity_name) const

Check if table schema encapsulated by an Entity object from given the table name exists. If table does not exist yet, return false.

Parameters
entity_nameName of the table of interest
Returns
true if entity exists, false otherwise.

◆ host()

std::string mb::MantisBase::host ( ) const

Retrieve HTTP Server host address. For instance, a host of 127.0.0.1, 0.0.0.0, etc.

Returns
HTTP Server Host address.

◆ instance()

MantisBase & mb::MantisBase::instance ( )
static

Retrieve existing application instance.

Returns
A reference to the existing application instance.

◆ isDevMode()

bool mb::MantisBase::isDevMode ( ) const

◆ jwtSecretKey()

std::string mb::MantisBase::jwtSecretKey ( )
static

Retrieve the JWT secret key.

Returns
JWT Secret value.

◆ logs()

Logger & mb::MantisBase::logs ( ) const

Get the logs unit object.

◆ openBrowserOnStart()

void mb::MantisBase::openBrowserOnStart ( ) const

Launch browser with the admin dashboard page. If all goes well, the default OS browser should open (if not opened) with the admin dashboard URL.

‍Added in v0.1.6

◆ operator=() [1/2]

MantisBase & mb::MantisBase::operator= ( const MantisBase )
delete

◆ operator=() [2/2]

MantisBase & mb::MantisBase::operator= ( MantisBase &&  )
delete

◆ poolSize()

int mb::MantisBase::poolSize ( ) const

Retrieve the database pool size value.

Returns
SOCI's database pool size.

◆ port()

int mb::MantisBase::port ( ) const

Retrieve HTTP Listening port.

Returns
Http Listening Port.

◆ publicDir()

std::string mb::MantisBase::publicDir ( ) const

Retrieve the public static file directory.

Returns
MantisApp public directory.

◆ quit()

int mb::MantisBase::quit ( const int &  exitCode = 0,
const std::string &  reason = "Something went wrong!" 
)
static

Quit the running application immediately.

Parameters
exitCodeExit code value
reasonUser-friendly reason for the exit.
Returns
exitCode value.

◆ router()

Router & mb::MantisBase::router ( ) const

Get the router object instance.

◆ rt()

RealtimeDB & mb::MantisBase::rt ( ) const

Get the realtime unit (SQLite/PostgreSQL change detection for SSE /api/v1/realtime).

◆ run()

int mb::MantisBase::run ( )

Start the http server and start listening for requests.

Returns
0 if execution was okay, else a non-zero value.

◆ scriptsDir()

std::string mb::MantisBase::scriptsDir ( ) const

Retrieves the scripts directory where JavaScript files are stored used for extending functionality in Mantis.

Returns
MantisApp scripts directory.

◆ setDataDir()

void mb::MantisBase::setDataDir ( const std::string &  dir)

Update the data directory for MantisApp.

Parameters
dirNew data directory.

◆ setDbType()

void mb::MantisBase::setDbType ( const std::string &  dbType)

Update the active database type for Mantis.

Parameters
dbTypeNew database type enum value.

◆ setHost()

void mb::MantisBase::setHost ( const std::string &  host)

Update HTTP Server host address.

Parameters
hostNew HTTP Server host address.

◆ setPort()

void mb::MantisBase::setPort ( const int &  port)

Set a new port value for HTTP server.

Parameters
portNew HTTP port value.

◆ setPublicDir()

void mb::MantisBase::setPublicDir ( const std::string &  dir)

Update HTTP server static file directory.

Parameters
dirNew directory path.

◆ setScriptsDir()

void mb::MantisBase::setScriptsDir ( const std::string &  dir)

Update the scripts directory for MantisApp.

Parameters
dirNew scripts directory.

◆ settings()

KeyValStore & mb::MantisBase::settings ( ) const

Get the KeyValue unit object.

◆ startTime()

std::chrono::time_point< std::chrono::steady_clock > mb::MantisBase::startTime ( ) const

Get the server start time in std::chrono::

Returns
Server start time

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