MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
config.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #ifndef PACKAGE_VERSION
7 #define PACKAGE_VERSION "unknown"
8 #endif
9 
10 #include <string>
11 #include "json.h"
12 #include <signal.h>
13 
15 namespace Util {
16 
18  class Config {
19  private:
22  static void signal_handler(int signum, siginfo_t * sigInfo, void * ignore);
23  public:
24  //variables
25  static bool is_active;
26  static unsigned int printDebugLevel;
27  //functions
28  Config();
29  Config(std::string cmd);
30  void addOption(std::string optname, JSON::Value option);
31  void printHelp(std::ostream & output);
32  bool parseArgs(int & argc, char ** & argv);
33  JSON::Value & getOption(std::string optname, bool asArray = false);
34  std::string getString(std::string optname);
35  long long int getInteger(std::string optname);
36  bool getBool(std::string optname);
37  void activate();
38  int threadServer(Socket::Server & server_socket, int (*callback)(Socket::Connection & S));
39  int forkServer(Socket::Server & server_socket, int (*callback)(Socket::Connection & S));
40  int serveThreadedSocket(int (*callback)(Socket::Connection & S));
41  int serveForkedSocket(int (*callback)(Socket::Connection & S));
42  int servePlainSocket(int (*callback)(Socket::Connection & S));
45  };
46 
48  std::string getMyPath();
49 
51  void getMyExec(std::deque<std::string> & execs);
52 
54  void setUser(std::string user);
55 
57  void Daemonize(bool notClose = false);
58 
59 }
void printHelp(std::ostream &output)
Prints a usage message to the given output.
Definition: config.cpp:98
int long_count
Definition: config.h:21
void addBasicConnectorOptions(JSON::Value &capabilities)
Adds the default connector options. Also updates the capabilities structure with the default options...
Definition: config.cpp:526
void activate()
Activated the stored config.
Definition: config.cpp:436
JSON::Value & getOption(std::string optname, bool asArray=false)
Returns a reference to the current value of an option or default if none was set. ...
Definition: config.cpp:308
static void signal_handler(int signum, siginfo_t *sigInfo, void *ignore)
Basic signal handler.
Definition: config.cpp:469
bool parseArgs(int &argc, char **&argv)
Parses commandline arguments.
Definition: config.cpp:193
int forkServer(Socket::Server &server_socket, int(*callback)(Socket::Connection &S))
void addOption(std::string optname, JSON::Value option)
Adds an option to the configuration parser.
Definition: config.cpp:80
A JSON::Value is either a string or an integer, but may also be an object, array or null...
Definition: json.h:21
std::string getString(std::string optname)
Returns the current value of an option or default if none was set as a string.
Definition: config.cpp:326
void addConnectorOptions(int port, JSON::Value &capabilities)
Adds the default connector options.
Definition: config.cpp:495
JSON::Value capabilities
Global storage of capabilities.
Definition: controller_capabilities.cpp:12
void setUser(std::string user)
Will set the active user to the named username.
Definition: config.cpp:632
static bool is_active
Set to true by activate(), set to false by the signal handler.
Definition: config.h:25
std::string getMyPath()
Gets directory the current executable is stored in.
Definition: config.cpp:569
Contains utility code, not directly related to streaming media.
Definition: bitfields.h:3
This class is for easily setting up listening socket, either TCP or Unix.
Definition: socket.h:104
int servePlainSocket(int(*callback)(Socket::Connection &S))
void Daemonize(bool notClose=false)
Will turn the current process into a daemon.
Definition: config.cpp:652
Deals with parsing configuration from commandline options.
Definition: config.h:18
void getMyExec(std::deque< std::string > &execs)
Gets all executables in getMyPath that start with "Mist".
Definition: config.cpp:600
Config()
Definition: config.cpp:39
bool getBool(std::string optname)
Returns the current value of an option or default if none was set as a bool.
Definition: config.cpp:338
JSON::Value vals
Holds all current config values.
Definition: config.h:20
int threadServer(Socket::Server &server_socket, int(*callback)(Socket::Connection &S))
long long int getInteger(std::string optname)
Returns the current value of an option or default if none was set as a long long int.
Definition: config.cpp:332
static unsigned int printDebugLevel
Definition: config.h:26
This class is for easy communicating through sockets, either TCP or Unix.
Definition: socket.h:47
int serveThreadedSocket(int(*callback)(Socket::Connection &S))
int serveForkedSocket(int(*callback)(Socket::Connection &S))
Definition: config.cpp:414