default config

main
Steffen Pohle 2 years ago
parent 3e1e74a34a
commit b9f3b8e32c

@ -1,5 +1,64 @@
#include <stdio.h>
#include <string.h>
#include "configuration.h"
#include "miniwebcam.h"
Configuration config;
/*
* Setup default values for all configuration options
*/
Configuration::Configuration() {
http_port = DEFAULT_HTTP_PORT;
https_port = DEFAULT_HTTPS_PORT;
runasdaemon = 0;
initflags = 0;
};
Configuration::~Configuration() {
};
/*
* print current configuration
*/
int Configuration::Print() {
printf ("#\n# default ports for http and https\n");
if (http_port == DEFAULT_HTTP_PORT) printf ("# ");
printf ("http_port %d\n", http_port);
if (https_port == DEFAULT_HTTPS_PORT) printf ("# ");
printf ("https_port %d\n", https_port);
return 0;
}
int Configuration::LoadArgs(int argc, char **argv) {
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-F") == 0) runasdaemon = 0;
if (strcmp(argv[i], "-D") == 0) runasdaemon = 1;
if (strcmp(argv[i], "-dump_config") == 0) initflags |= CONF_INITFLAGS_PRINT;
if (strcmp(argv[i], "-h") == 0) initflags |= CONF_INITFLAGS_HELP;
if (strcmp(argv[i], "-http_port") == 0) {
if (++i < argc) {
}
else
ErrorExit("missing port parameter", -1);
}
}
return 0;
}
void Configuration::Help() {
printf ("Parameters:\n");
printf (" -F run in foreground\n");
printf (" -D run as daemon\n");
printf ("\n");
printf (" -dump_config print the config file\n");
printf ("\n");
printf (" -H print this help\n");
}

@ -2,13 +2,29 @@
#ifndef _CONFIGURATION_H_
#define _CONFIGURATION_H_
#define DEFAULT_HTTP_PORT 10080
#define DEFAULT_HTTPS_PORT 10081
#define CONF_INITFLAGS_PRINT 0x0001
#define CONF_INITFLAGS_HELP 0x0002
class Configuration {
private:
int http_port;
int https_port;
int runasdaemon;
int initflags;
public:
Configuration() {};
~Configuration() {};
Configuration();
~Configuration();
int LoadArgs(int argc, char **argv);
int Print(); // print current configuration
void Help(); // print Help
int GetInitFlags() { return initflags; };
};
extern Configuration config;

@ -1,11 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "configuration.h"
#include "miniwebcam.h"
void ErrorExit(std::string text, int errorcode) {
printf ("Error: %s\n", text.c_str());
exit (errorcode);
}
int main(int argc, char **argv) {
config.LoadArgs (argc, argv);
if (config.GetInitFlags() & CONF_INITFLAGS_PRINT) {
config.Print();
return 0;
}
if (config.GetInitFlags() & CONF_INITFLAGS_HELP) {
config.Help();
return 0;
}
printf ("MiniWebCam:\n");
return 0;
};

@ -10,7 +10,8 @@ miniwebcam_src = [
]
miniwebcam_headers = [
'configuration.h'
'configuration.h',
'miniwebcam.h'
]

@ -0,0 +1,10 @@
#ifndef _MINIWEBCAM_H_
#define _MINIWEBCAM_H_
#include <string>
void ErrorExit(std::string text, int errorcode);
#endif
Loading…
Cancel
Save