Skip to content

Commit

Permalink
Change app variable to be part of cls_config
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Dave committed Aug 19, 2024
1 parent 778d29f commit c8d6a66
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 63 deletions.
89 changes: 47 additions & 42 deletions src/conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,13 +626,17 @@ void cls_config::edit_device_id(std::string &parm, enum PARM_ACT pact)
if (pact == PARM_ACT_DFLT) {
device_id = 0;
} else if (pact == PARM_ACT_SET) {
parm_in = atoi(parm.c_str());
if (parm_in < 1) {
MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid device_id %d"),parm_in);
} else if (parm_in > 32000) {
MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid device_id %d"),parm_in);
if ((this == app->cfg) || (this == app->conf_src)) {
device_id = 0;
} else {
device_id = parm_in;
parm_in = atoi(parm.c_str());
if (parm_in < 1) {
MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid device_id %d"),parm_in);
} else if (parm_in > 32000) {
MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid device_id %d"),parm_in);
} else {
device_id = parm_in;
}
}
} else if (pact == PARM_ACT_GET) {
parm = std::to_string(device_id);
Expand Down Expand Up @@ -3554,7 +3558,7 @@ void cls_config::usage(void)
printf("\n");
}

void cls_config::cmdline(cls_motapp *app)
void cls_config::cmdline()
{
int c;

Expand Down Expand Up @@ -3594,7 +3598,7 @@ void cls_config::cmdline(cls_motapp *app)
optind = 1;
}

void cls_config::camera_filenm(cls_motapp *app)
void cls_config::camera_filenm()
{
int indx_cam, indx;
std::string dirnm, fullnm;
Expand Down Expand Up @@ -3629,7 +3633,7 @@ void cls_config::camera_filenm(cls_motapp *app)
conf_filename = fullnm;
}

int cls_config::get_next_devid(cls_motapp *app)
int cls_config::get_next_devid()
{
int indx, dev_id;
bool chkid;
Expand Down Expand Up @@ -3657,15 +3661,15 @@ int cls_config::get_next_devid(cls_motapp *app)

}

void cls_config::camera_add(cls_motapp *app, std::string fname, bool srcdir)
void cls_config::camera_add(std::string fname, bool srcdir)
{
struct stat statbuf;
int indx;
std::string parm_val, parm_nm;
cls_camera *cam_cls;

cam_cls = new cls_camera(app);
cam_cls->conf_src = new cls_config;
cam_cls->conf_src = new cls_config(app);

indx = 0;
while (config_parms[indx].parm_name != "") {
Expand All @@ -3679,27 +3683,27 @@ void cls_config::camera_add(cls_motapp *app, std::string fname, bool srcdir)

cam_cls->conf_src->from_conf_dir = srcdir;
cam_cls->conf_src->conf_filename = fname;
cam_cls->conf_src->device_id = get_next_devid(app);
cam_cls->conf_src->device_id = get_next_devid();
cam_cls->device_id = cam_cls->conf_src->device_id;

if (fname == "") {
cam_cls->conf_src->camera_filenm(app);
cam_cls->conf_src->camera_filenm();
} else if (stat(fname.c_str(), &statbuf) != 0) {
MOTPLS_LOG(ALR, TYPE_ALL, SHOW_ERRNO
,_("Camera config file %s not found"), fname.c_str());
} else {
cam_cls->conf_src->process(app);
cam_cls->conf_src->process();
}

cam_cls->cfg = new cls_config;
cam_cls->cfg = new cls_config(app);
cam_cls->cfg->parms_copy(cam_cls->conf_src);

app->cam_list.push_back(cam_cls);
app->cam_cnt = (int)app->cam_list.size();
}

/* Create default configuration file name*/
void cls_config::sound_filenm(cls_motapp *app)
void cls_config::sound_filenm()
{
int indx_snd, indx;
std::string dirnm, fullnm;
Expand Down Expand Up @@ -3734,15 +3738,15 @@ void cls_config::sound_filenm(cls_motapp *app)
conf_filename = fullnm;
}

void cls_config::sound_add(cls_motapp *app, std::string fname, bool srcdir)
void cls_config::sound_add(std::string fname, bool srcdir)
{
struct stat statbuf;
int indx;
std::string parm_val, parm_nm;
cls_sound *snd_cls;

snd_cls = new cls_sound(app);
snd_cls->conf_src = new cls_config;
snd_cls->conf_src = new cls_config(app);

indx = 0;
while (config_parms[indx].parm_name != "") {
Expand All @@ -3756,26 +3760,26 @@ void cls_config::sound_add(cls_motapp *app, std::string fname, bool srcdir)

snd_cls->conf_src->from_conf_dir = srcdir;
snd_cls->conf_src->conf_filename = fname;
snd_cls->conf_src->device_id = get_next_devid(app);
snd_cls->conf_src->device_id = get_next_devid();
snd_cls->device_id = snd_cls->conf_src->device_id;

if (fname == "") {
snd_cls->conf_src->sound_filenm(app);
snd_cls->conf_src->sound_filenm();
} else if (stat(fname.c_str(), &statbuf) != 0) {
MOTPLS_LOG(ALR, TYPE_ALL, SHOW_ERRNO
,_("Sound config file %s not found"), fname.c_str());
} else {
snd_cls->conf_src->process(app);
snd_cls->conf_src->process();
}

snd_cls->cfg = new cls_config;
snd_cls->cfg = new cls_config(app);
snd_cls->cfg->parms_copy(snd_cls->conf_src);

app->snd_list.push_back(snd_cls);
app->snd_cnt = (int)app->snd_list.size();
}

void cls_config::config_dir_parm(cls_motapp *app, std::string confdir)
void cls_config::config_dir_parm(std::string confdir)
{
DIR *dp;
dirent *ep;
Expand All @@ -3792,13 +3796,13 @@ void cls_config::config_dir_parm(cls_motapp *app, std::string confdir)
MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO
,_("Processing as camera config file %s")
, file.c_str() );
camera_add(app, file, true);
camera_add(file, true);
} else {
file = confdir + "/" + file;
MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO
,_("Processing as sound config file %s")
, file.c_str() );
sound_add(app, file, true);
sound_add(file, true);
}
}
}
Expand All @@ -3810,7 +3814,7 @@ void cls_config::config_dir_parm(cls_motapp *app, std::string confdir)

}

void cls_config::process(cls_motapp *app)
void cls_config::process()
{
size_t stpos;
std::string line, parm_nm, parm_vl;
Expand Down Expand Up @@ -3849,11 +3853,11 @@ void cls_config::process(cls_motapp *app)
myunquote(parm_nm);
myunquote(parm_vl);
if ((parm_nm == "camera") && (app->conf_src == this)) {
camera_add(app, parm_vl, false);
camera_add(parm_vl, false);
} else if ((parm_nm == "sound") && (app->conf_src == this)) {
sound_add(app, parm_vl, false);
sound_add(parm_vl, false);
} else if ((parm_nm == "config_dir") && (app->conf_src == this)){
config_dir_parm(app, parm_vl);
config_dir_parm(parm_vl);
} else if ((parm_nm != "camera") && (parm_nm != "sound") &&
(parm_nm != "config_dir")) {
edit_set(parm_nm, parm_vl);
Expand Down Expand Up @@ -3896,7 +3900,7 @@ void cls_config::parms_log_parm(std::string parm_nm, std::string parm_vl)

}

void cls_config::parms_log(cls_motapp *app)
void cls_config::parms_log()
{
int i, indx;
std::string parm_vl, parm_main, parm_nm;
Expand Down Expand Up @@ -4011,7 +4015,7 @@ void cls_config::parms_write_parms(FILE *conffile, std::string parm_nm
}
}

void cls_config::parms_write_app(cls_motapp *app)
void cls_config::parms_write_app()
{
int i, indx;
std::string parm_vl, parm_main, parm_nm;
Expand Down Expand Up @@ -4090,7 +4094,7 @@ void cls_config::parms_write_app(cls_motapp *app)

}

void cls_config::parms_write_cam(cls_motapp *app)
void cls_config::parms_write_cam()
{
int i, indx;
std::string parm_vl, parm_main, parm_nm;
Expand Down Expand Up @@ -4150,7 +4154,7 @@ void cls_config::parms_write_cam(cls_motapp *app)

}

void cls_config::parms_write_snd(cls_motapp *app)
void cls_config::parms_write_snd()
{
int i, indx;
std::string parm_vl, parm_main, parm_nm;
Expand Down Expand Up @@ -4210,11 +4214,11 @@ void cls_config::parms_write_snd(cls_motapp *app)
}


void cls_config::parms_write(cls_motapp *app)
void cls_config::parms_write()
{
parms_write_app(app);
parms_write_cam(app);
parms_write_snd(app);
parms_write_app();
parms_write_cam();
parms_write_snd();
}

void cls_config::parms_copy(cls_config *src)
Expand Down Expand Up @@ -4249,7 +4253,7 @@ void cls_config::parms_copy(cls_config *src, PARM_CAT p_cat)

}

void cls_config::init(cls_motapp *app)
void cls_config::init()
{
std::string filename;
char path[PATH_MAX];
Expand All @@ -4258,7 +4262,7 @@ void cls_config::init(cls_motapp *app)

defaults();

cmdline(app);
cmdline();

filename = "";
if (app->conf_src->conf_filename != "") {
Expand Down Expand Up @@ -4301,9 +4305,9 @@ void cls_config::init(cls_motapp *app)

edit_set("conf_filename", filename);

app->conf_src->process(app);
app->conf_src->process();

cmdline(app);
cmdline();

for (indx=0; indx<app->cam_cnt; indx++) {
app->cam_list[indx]->threadnr = indx;
Expand All @@ -4315,8 +4319,9 @@ void cls_config::init(cls_motapp *app)

}

cls_config::cls_config()
cls_config::cls_config(cls_motapp *p_app)
{
app = p_app;
defaults();
}

Expand Down
31 changes: 16 additions & 15 deletions src/conf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

class cls_config {
public:
cls_config();
cls_config(cls_motapp *p_app);
~cls_config();

/* Overall system configuration parameters */
Expand Down Expand Up @@ -281,11 +281,11 @@
std::string snd_window;
bool snd_show;

void camera_add(cls_motapp *app, std::string fname, bool srcdir);
void sound_add(cls_motapp *app, std::string fname, bool srcdir);
void camera_filenm(cls_motapp *app);
void sound_filenm(cls_motapp *app);
void process(cls_motapp *app);
void camera_add(std::string fname, bool srcdir);
void sound_add(std::string fname, bool srcdir);
void camera_filenm();
void sound_filenm();
void process();

void edit_set(std::string parm_nm, std::string parm_val);
void edit_get(std::string parm_nm, std::string &parm_val, enum PARM_CAT parm_cat);
Expand All @@ -295,23 +295,24 @@
std::string type_desc(enum PARM_TYP ptype);
std::string cat_desc(enum PARM_CAT pcat, bool shrt);
void usage();
void init(cls_motapp *app);
void parms_log(cls_motapp *app);
void parms_write(cls_motapp *app);
void init();
void parms_log();
void parms_write();
void parms_copy(cls_config *src);
void parms_copy(cls_config *src, PARM_CAT p_cat);

private:
void cmdline(cls_motapp *app);
cls_motapp *app;
void cmdline();
void defaults();
int get_next_devid(cls_motapp *app);
void config_dir_parm(cls_motapp *app, std::string confdir);
int get_next_devid();
void config_dir_parm(std::string confdir);

void parms_log_parm(std::string parm_nm, std::string parm_vl);
void parms_write_app(cls_motapp *app);
void parms_write_cam(cls_motapp *app);
void parms_write_app();
void parms_write_cam();
void parms_write_parms(FILE *conffile, std::string parm_nm, std::string parm_vl, enum PARM_CAT parm_ct, bool reset);
void parms_write_snd(cls_motapp *app);
void parms_write_snd();

int edit_set_active(std::string parm_nm, std::string parm_val);
int edit_set_depr(std::string &parm_nm, std::string &parm_val);
Expand Down
10 changes: 5 additions & 5 deletions src/motionplus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,10 @@ void cls_motapp::init(int p_argc, char *p_argv[])
pthread_mutex_init(&mutex_camlst, NULL);
pthread_mutex_init(&mutex_post, NULL);

conf_src = new cls_config;
conf_src->init(this);
conf_src = new cls_config(this);
conf_src->init();

cfg = new cls_config;
cfg = new cls_config(this);
cfg->parms_copy(conf_src);

motlog->startup();
Expand All @@ -717,7 +717,7 @@ void cls_motapp::init(int p_argc, char *p_argv[])
MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO, _("MotionPlus running as daemon process"));
}

cfg->parms_log(this);
cfg->parms_log();

pid_write();

Expand Down Expand Up @@ -783,7 +783,7 @@ void cls_motapp::camera_add()
}

pthread_mutex_lock(&mutex_camlst);
cfg->camera_add(this, "", false);
cfg->camera_add("", false);
pthread_mutex_unlock(&mutex_camlst);

cam_add = false;
Expand Down
2 changes: 1 addition & 1 deletion src/webu_post.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ void cls_webu_post::write_config()
}
}

app->conf_src->parms_write(app);
app->conf_src->parms_write();

}

Expand Down

0 comments on commit c8d6a66

Please sign in to comment.