Any interest in patch to simplify config reading?

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
mor
Posts: 45
Joined: Sat Apr 26, 2008 1:41 am

Any interest in patch to simplify config reading?

Post by mor »

Is there any interest in a patch like the one below (v 1.23.2 as I haven't rebased yet).

It is the start of an attempt to simplify the code that handles reading values in from the database. It basically changes it over to reference columns by name rather than by offset.

To my mind it's easier to read and easier to change the code, but that's just me.

Pros:
+ Maybe easier to read and understand.
+ Maybe easier to change (has many fewer temp variables).
+ better error checking (current code may crash if there's a SQL NULL in the table).

Cons:
- Definitely slower! (but code runs v rarely so hopefully not an issue).



Comments?

NOTE: Utterly untested. I'm just tossing the idea out there to check interest before I go to the effort of polishing it.

Code: Select all

diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp
index 0bd260d..fd80dce 100644
--- a/src/zm_monitor.cpp
+++ b/src/zm_monitor.cpp
@@ -1557,16 +1557,63 @@ void Monitor::ReloadLinkedMonitors( const char *p_linked_monitors )
 	}
 }
 
+//
+// Get the field named 'field' from a MySQL result.
+// May return NULL is field contains an SQL NULL.
+//
+static char * get_field(MYSQL_ROW *row, MYSQL_FIELD *fields, int num_fields, char * field)
+{
+	int i;
+	for (i = 0; i < num_fields; ++i)
+	{
+		if ( strcasecmp(field, fields[i].name) )
+			continue;
+		return row[i];
+	}
+}
+
+// Get the integer field name 'field' from a MySQL result.
+static int get_int_field(MYSQL_ROW *row, MYSQL_FIELD *fields, int num_fields, char * field)
+{
+	char * p = get_field(row,fields,num_fields,field);
+	if ( p == NULL )
+		return 0;
+
+	return atoi(p);
+}
+
+// Get the string field name 'field' from a MySQL result.
+//  NB: string is only valid in the scope of the MySQL result. Should be strdup()'ed if needed
+//  for a longer time.
+static int get_str_field(MYSQL_ROW *row, MYSQL_FIELD *fields, int num_fields, char * field)
+{
+	char *p = get_field(row,fields,num_fields,field);
+	if ( p == NULL )
+		return "";
+	return p;
+}
+
+// Shorthand accessor functions to return an integer or string field named 'a'
+#define INT_F(a) get_int_field(dbrow,fields,num_fields, (a) )
+#define STR_F(a) get_str_field(dbrow,fields,num_fields, (a) )
+
 int Monitor::LoadLocalMonitors( const char *device, Monitor **&monitors, Purpose purpose )
 {
+	static char sql_cmd[] = ""select Id, Name, Function+0 as Function, Enabled, LinkedMonitors, "
+		"Device, Channel, Format, Width, Height, Palette, Orientation+0 as Orientation, "
+		"Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, "
+		"LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, "
+		"PostEventCount, StreamReplayBuffer, AlarmFrameCount, SectionLength, "
+		"FrameSkip, MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, "
+		"TrackMotion, SignalCheckColour from Monitors where Function != 'None'";
 	static char sql[BUFSIZ];
 	if ( !device[0] )
 	{
-		strncpy( sql, "select Id, Name, Function+0, Enabled, LinkedMonitors, Device, Channel, Format, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion, SignalCheckColour from Monitors where Function != 'None' and Type = 'Local' order by Device, Channel", sizeof(sql) );
+		snprintf( sql, sizeof(sql), "%s and Type = 'Local' order by Device, Channel", sql_cmd );
 	}
 	else
 	{
-		snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Enabled, LinkedMonitors, Device, Channel, Format, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion, SignalCheckColour from Monitors where Function != 'None' and Type = 'Local' and Device = '%s' order by Channel", device );
+		snprintf( sql, sizeof(sql), "%s and Type = 'Local' and Device = '%s' order by Channel", sql_cmd, device );
 	}
 	if ( mysql_query( &dbconn, sql ) )
 	{
@@ -1580,100 +1627,72 @@ int Monitor::LoadLocalMonitors( const char *device, Monitor **&monitors, Purpose
 		Error(( "Can't use query result: %s", mysql_error( &dbconn ) ));
 		exit( mysql_errno( &dbconn ) );
 	}
+	MYSQL_FIELD *fields = mysql_fetch_fields(result);
+	int num_fields = mysql_num_fields(result);
+
 	int n_monitors = mysql_num_rows( result );
 	Debug( 1, ( "Got %d monitors", n_monitors ));
 	delete[] monitors;
 	monitors = new Monitor *[n_monitors];
-	for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ )
-	{
-		int col = 0;
-
-		int id = atoi(dbrow[col]); col++;
-		const char *name = dbrow[col]; col++;
-		int function = atoi(dbrow[col]); col++;
-		int enabled = atoi(dbrow[col]); col++;
-		const char *linked_monitors = dbrow[col]; col++;
 
-		const char *device = dbrow[col]; col++;
-		int channel = atoi(dbrow[col]); col++;
-		int format = atoi(dbrow[col]); col++;
-
-		int width = atoi(dbrow[col]); col++;
-		int height = atoi(dbrow[col]); col++;
-		int palette = atoi(dbrow[col]); col++;
-		Orientation orientation = (Orientation)atoi(dbrow[col]); col++;
-		int brightness = atoi(dbrow[col]); col++;
-		int contrast = atoi(dbrow[col]); col++;
-		int hue = atoi(dbrow[col]); col++;
-		int colour = atoi(dbrow[col]); col++;
 
-		const char *event_prefix = dbrow[col]; col++;
-		const char *label_format = dbrow[col]; col++;
+	for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ )
+	{
+		int width = INT_F("Width");
+		int height = INT_F("Height");
+		Orientation orientation = (Orientation)INT_F("Orientation");
 
-		int label_x = atoi(dbrow[col]); col++;
-		int label_y = atoi(dbrow[col]); col++;
+		int capture_delay = (dbrow[col]&&atof(STR_F("CaptureDelay"))>0.0)?int(DT_PREC_3/atof(STR_F("CaptureDelay")):0; col++;
+		int alarm_capture_delay = (dbrow[col]&&atof(STR_F("AlarmCaptureDelay"))>0.0)?int(DT_PREC_3/atof(STR_F("AlarmCaptureDelay")):0; col++;
 
-		int image_buffer_count = atoi(dbrow[col]); col++;
-		int warmup_count = atoi(dbrow[col]); col++;
-		int pre_event_count = atoi(dbrow[col]); col++;
-		int post_event_count = atoi(dbrow[col]); col++;
-		int stream_replay_buffer = atoi(dbrow[col]); col++;
-		int alarm_frame_count = atoi(dbrow[col]); col++;
-		int section_length = atoi(dbrow[col]); col++;
-		int frame_skip = atoi(dbrow[col]); col++;
-		int capture_delay = (dbrow[col]&&atof(dbrow[col])>0.0)?int(DT_PREC_3/atof(dbrow[col])):0; col++;
-		int alarm_capture_delay = (dbrow[col]&&atof(dbrow[col])>0.0)?int(DT_PREC_3/atof(dbrow[col])):0; col++;
-		int fps_report_interval = atoi(dbrow[col]); col++;
-		int ref_blend_perc = atoi(dbrow[col]); col++;
-		int track_motion = atoi(dbrow[col]); col++;
-        int signal_check_colour;
-        if ( dbrow[col][0] == '#' )
-		    signal_check_colour = strtol(dbrow[col]+1,0,16);
-        else
-		    signal_check_colour = strtol(dbrow[col],0,16);
-        col++;
+		int signal_check_colour;
+		if ( STR_F("SignalCheckColour")[0] == '#' )
+			signal_check_colour = strtol(STR_F("SignalCheckColour")+1,0,16);
+		else
+			signal_check_colour = strtol(STR_F("SignalCheckColour"),0,16);
+		col++;
 
 		int cam_width = ((orientation==ROTATE_90||orientation==ROTATE_270)?height:width);
 		int cam_height = ((orientation==ROTATE_90||orientation==ROTATE_270)?width:height);
 
 		Camera *camera = new LocalCamera(
-			device, // Device
-			channel, // Channel
-			format, // Format
+			STR_F("Device"),
+			STR_F("Channel"),
+			STR_F("Format"),
 			cam_width,
 			cam_height,
-			palette,
-			brightness,
-			contrast,
-			hue,
-			colour,
+			INT_F("Palette"),
+			INT_F("Brightness"),
+			INT_F("Contrast"),
+			INT_F("Hue"),
+			INT_F("Colour"),
 			purpose==CAPTURE
 		);
 
 		monitors[i] = new Monitor(
-			id,
-			name,
-			function,
-			enabled,
-			linked_monitors,
+			INT_F("Id"),
+			STR_F("Name"),
+			INT_F("Function"),
+			INT_F("Enabled"),
+			STR_F("linked_monitors"),
 			camera,
 			orientation,
-			event_prefix,
-			label_format,
-			Coord( label_x, label_y ),
-			image_buffer_count,
-			warmup_count,
-			pre_event_count,
-			post_event_count,
-			stream_replay_buffer,
-			alarm_frame_count,
-			section_length,
-			frame_skip,
+			STR_F("EventPrefix"),
+			STR_F("LabelFormat"),
+			Coord( INT_F("LabelX"), INT_F("LabelY") ),
+			INT_F("ImageBufferCount"),
+			INT_F("WarmupCount"),
+			INT_F("PreEventCount"),
+			INT_F("PostEventCount"),
+			INT_F("StreamReplayBuffer"),
+			INT_F("AlarmFrameCount"),
+			INT_F("SectionLength"),
+			INT_F("FrameSkip"),
 			capture_delay,
 			alarm_capture_delay,
-			fps_report_interval,
-			ref_blend_perc,
-			track_motion,
+			INT_F("FpsReportInterval"),
+			INT_F("RefBlendPerc"),
+			INT_F("TrackMotion"),
 			signal_check_colour,
 			purpose
 		);
@@ -1695,14 +1714,22 @@ int Monitor::LoadLocalMonitors( const char *device, Monitor **&monitors, Purpose
 
 int Monitor::LoadRemoteMonitors( const char *host, const char*port, const char *path, Monitor **&monitors, Purpose purpose )
 {
+	static char sql_cmd[] = "select Id, Name, Function+0 as Function, Enabled, "
+		"LinkedMonitors, Host, Port, Path, Width, Height, Palette, "
+		"Orientation+0 as Orientation, Brightness, Contrast, Hue, Colour, EventPrefix, "
+		"LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, "
+		"PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, "
+		"SectionLength, FrameSkip, MaxFPS, AlarmMaxFPS, FPSReportInterval, "
+		"RefBlendPerc, TrackMotion from Monitors where Function != 'None' "
+		"and Type = 'Remote'";
 	static char sql[BUFSIZ];
 	if ( !host )
 	{
-		strncpy( sql, "select Id, Name, Function+0, Enabled, LinkedMonitors, Host, Port, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'Remote'", sizeof(sql) );
+		snprintf( sql, sizeof(sql), "%s", sql_cmd);
 	}
 	else
 	{
-		snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Enabled, LinkedMonitors, Host, Port, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'Remote' and Host = '%s' and Port = '%s' and Path = '%s'", host, port, path );
+		snprintf( sql, sizeof(sql), "%s and Type = 'Remote' and Host = '%s' and Port = '%s' and Path = '%s'", sql_cmd, host, port, path );
 	}
 	if ( mysql_query( &dbconn, sql ) )
 	{
@@ -1716,95 +1743,65 @@ int Monitor::LoadRemoteMonitors( const char *host, const char*port, const char *
 		Error(( "Can't use query result: %s", mysql_error( &dbconn ) ));
 		exit( mysql_errno( &dbconn ) );
 	}
+	MYSQL_FIELD *fields = mysql_fetch_fields(result);
+	int num_fields = mysql_num_fields(result);
+
 	int n_monitors = mysql_num_rows( result );
 	Debug( 1, ( "Got %d monitors", n_monitors ));
 	delete[] monitors;
 	monitors = new Monitor *[n_monitors];
 	for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ )
 	{
-		int col = 0;
-
-		int id = atoi(dbrow[col]); col++;
-		const char *name = dbrow[col]; col++;
-		int function = atoi(dbrow[col]); col++;
-		int enabled = atoi(dbrow[col]); col++;
-		const char *linked_monitors = dbrow[col]; col++;
-
-		const char *host = dbrow[col]; col++;
-		const char *port = dbrow[col]; col++;
-		const char *path = dbrow[col]; col++;
-
-		int width = atoi(dbrow[col]); col++;
-		int height = atoi(dbrow[col]); col++;
-		int palette = atoi(dbrow[col]); col++;
-		Orientation orientation = (Orientation)atoi(dbrow[col]); col++;
-		int brightness = atoi(dbrow[col]); col++;
-		int contrast = atoi(dbrow[col]); col++;
-		int hue = atoi(dbrow[col]); col++;
-		int colour = atoi(dbrow[col]); col++;
+		int width = INT_F("Width");
+		int height = INT_F("Height");
+		Orientation orientation = (Orientation)INT_F("Orientation");
 
-		const char *event_prefix = dbrow[col]; col++;
-		const char *label_format = dbrow[col]; col++;
-
-		int label_x = atoi(dbrow[col]); col++;
-		int label_y = atoi(dbrow[col]); col++;
-
-		int image_buffer_count = atoi(dbrow[col]); col++;
-		int warmup_count = atoi(dbrow[col]); col++;
-		int pre_event_count = atoi(dbrow[col]); col++;
-		int post_event_count = atoi(dbrow[col]); col++;
-		int stream_replay_buffer = atoi(dbrow[col]); col++;
-		int alarm_frame_count = atoi(dbrow[col]); col++;
-		int section_length = atoi(dbrow[col]); col++;
-		int frame_skip = atoi(dbrow[col]); col++;
-		int capture_delay = (dbrow[col]&&atof(dbrow[col])>0.0)?int(DT_PREC_3/atof(dbrow[col])):0; col++;
-		int alarm_capture_delay = (dbrow[col]&&atof(dbrow[col])>0.0)?int(DT_PREC_3/atof(dbrow[col])):0; col++;
-		int fps_report_interval = atoi(dbrow[col]); col++;
-		int ref_blend_perc = atoi(dbrow[col]); col++;
-		int track_motion = atoi(dbrow[col]); col++;
+		int capture_delay = (dbrow[col]&&atof(STR_F("CaptureDelay"))>0.0)?int(DT_PREC_3/atof(STR_F("CaptureDelay")):0; col++;
+		int alarm_capture_delay = (dbrow[col]&&atof(STR_F("AlarmCaptureDelay"))>0.0)?int(DT_PREC_3/atof(STR_F("AlarmCaptureDelay")):0; col++;
 
 		int cam_width = ((orientation==ROTATE_90||orientation==ROTATE_270)?height:width);
 		int cam_height = ((orientation==ROTATE_90||orientation==ROTATE_270)?width:height);
 
+
 		Camera *camera = new RemoteCamera(
-			host, // Host
-			port, // Port
-			path, // Path
+			STR_F("Host"),
+			STR_F("Port"),
+			STR_F("Path"),
 			cam_width,
 			cam_height,
-			palette,
-			brightness,
-			contrast,
-			hue,
-			colour,
+			INT_F("Palette"),
+			INT_F("Brightness"),
+			INT_F("Contrast"),
+			INT_F("Hue"),
+			INT_F("Colour"),
 			purpose==CAPTURE
 		);
 
 		monitors[i] = new Monitor(
-			id,
-			name,
-			function,
-			enabled,
-			linked_monitors,
+			INT_F("Id"),
+			STR_F("Name"),
+			INT_F("Function"),
+			INT_F("Enabled"),
+			STR_F("linked_monitors"),
 			camera,
 			orientation,
-			event_prefix,
-			label_format,
-			Coord( label_x, label_y ),
-			image_buffer_count,
-			warmup_count,
-			pre_event_count,
-			post_event_count,
-			stream_replay_buffer,
-			alarm_frame_count,
-			section_length,
-			frame_skip,
+			STR_F("EventPrefix"),
+			STR_F("LabelFormat"),
+			Coord( INT_F("LabelX"), INT_F("LabelY") ),
+			INT_F("ImageBufferCount"),
+			INT_F("WarmupCount"),
+			INT_F("PreEventCount"),
+			INT_F("PostEventCount"),
+			INT_F("StreamReplayBuffer"),
+			INT_F("AlarmFrameCount"),
+			INT_F("SectionLength"),
+			INT_F("FrameSkip"),
 			capture_delay,
 			alarm_capture_delay,
-			fps_report_interval,
-			ref_blend_perc,
-			track_motion,
-            RGB_WHITE,
+			INT_F("FpsReportInterval"),
+			INT_F("RefBlendPerc"),
+			INT_F("TrackMotion"),
+			RGB_WHITE,
 			purpose
 		);
 		Zone **zones = 0;
@@ -1825,14 +1822,22 @@ int Monitor::LoadRemoteMonitors( const char *host, const char*port, const char *
 
 int Monitor::LoadFileMonitors( const char *file, Monitor **&monitors, Purpose purpose )
 {
+	static char sql_cmd[] = "select Id, Name, Function+0, Enabled, "
+		"LinkedMonitors, Path, Width, Height, Palette, "
+		"Orientation+0 as Orientation, Brightness, Contrast, "
+		"Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, "
+		"ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, "
+		"StreamReplayBuffer, AlarmFrameCount, SectionLength, FrameSkip, "
+		"MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, "
+		"TrackMotion from Monitors where Function != 'None' and Type = 'File'"
 	static char sql[BUFSIZ];
 	if ( !file[0] )
 	{
-		strncpy( sql, "select Id, Name, Function+0, Enabled, LinkedMonitors, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'File'", sizeof(sql) );
+		snprintf( sql, sizeof(sql), "%s", sql_cmd );
 	}
 	else
 	{
-		snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Enabled, LinkedMonitors, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'File' and Path = '%s'", file );
+		snprintf( sql, sizeof(sql), "%s and Path = '%s'", file );
 	}
 	if ( mysql_query( &dbconn, sql ) )
 	{
@@ -1846,91 +1851,61 @@ int Monitor::LoadFileMonitors( const char *file, Monitor **&monitors, Purpose pu
 		Error(( "Can't use query result: %s", mysql_error( &dbconn ) ));
 		exit( mysql_errno( &dbconn ) );
 	}
+	MYSQL_FIELD *fields = mysql_fetch_fields(result);
+	int num_fields = mysql_num_fields(result);
+
 	int n_monitors = mysql_num_rows( result );
 	Debug( 1, ( "Got %d monitors", n_monitors ));
 	delete[] monitors;
 	monitors = new Monitor *[n_monitors];
 	for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ )
 	{
-		int col = 0;
-
-		int id = atoi(dbrow[col]); col++;
-		const char *name = dbrow[col]; col++;
-		int function = atoi(dbrow[col]); col++;
-		int enabled = atoi(dbrow[col]); col++;
-		const char *linked_monitors = dbrow[col]; col++;
+		int width = INT_F("Width");
+		int height = INT_F("Height");
+		Orientation orientation = (Orientation)INT_F("Orientation");
 
-		const char *path = dbrow[col]; col++;
-
-		int width = atoi(dbrow[col]); col++;
-		int height = atoi(dbrow[col]); col++;
-		int palette = atoi(dbrow[col]); col++;
-		Orientation orientation = (Orientation)atoi(dbrow[col]); col++;
-		int brightness = atoi(dbrow[col]); col++;
-		int contrast = atoi(dbrow[col]); col++;
-		int hue = atoi(dbrow[col]); col++;
-		int colour = atoi(dbrow[col]); col++;
-
-		const char *event_prefix = dbrow[col]; col++;
-		const char *label_format = dbrow[col]; col++;
-
-		int label_x = atoi(dbrow[col]); col++;
-		int label_y = atoi(dbrow[col]); col++;
-
-		int image_buffer_count = atoi(dbrow[col]); col++;
-		int warmup_count = atoi(dbrow[col]); col++;
-		int pre_event_count = atoi(dbrow[col]); col++;
-		int post_event_count = atoi(dbrow[col]); col++;
-		int stream_replay_buffer = atoi(dbrow[col]); col++;
-		int alarm_frame_count = atoi(dbrow[col]); col++;
-		int section_length = atoi(dbrow[col]); col++;
-		int frame_skip = atoi(dbrow[col]); col++;
-		int capture_delay = (dbrow[col]&&atof(dbrow[col])>0.0)?int(DT_PREC_3/atof(dbrow[col])):0; col++;
-		int alarm_capture_delay = (dbrow[col]&&atof(dbrow[col])>0.0)?int(DT_PREC_3/atof(dbrow[col])):0; col++;
-		int fps_report_interval = atoi(dbrow[col]); col++;
-		int ref_blend_perc = atoi(dbrow[col]); col++;
-		int track_motion = atoi(dbrow[col]); col++;
+		int capture_delay = (dbrow[col]&&atof(STR_F("CaptureDelay"))>0.0)?int(DT_PREC_3/atof(STR_F("CaptureDelay")):0; col++;
+		int alarm_capture_delay = (dbrow[col]&&atof(STR_F("AlarmCaptureDelay"))>0.0)?int(DT_PREC_3/atof(STR_F("AlarmCaptureDelay")):0; col++;
 
 		int cam_width = ((orientation==ROTATE_90||orientation==ROTATE_270)?height:width);
 		int cam_height = ((orientation==ROTATE_90||orientation==ROTATE_270)?width:height);
 
 		Camera *camera = new FileCamera(
-			path, // File
+			STR_F("Path"),
 			cam_width,
 			cam_height,
-			palette,
-			brightness,
-			contrast,
-			hue,
-			colour,
-			purpose==CAPTURE
+			INT_F("Palette"),
+			INT_F("Brightness"),
+			INT_F("Contrast"),
+			INT_F("Hue"),
+			INT_F("Colour"),
 		);
 
 		monitors[i] = new Monitor(
-			id,
-			name,
-			function,
-			enabled,
-			linked_monitors,
+			INT_F("Id"),
+			STR_F("Name"),
+			INT_F("Function"),
+			INT_F("Enabled"),
+			STR_F("linked_monitors"),
 			camera,
 			orientation,
-			event_prefix,
-			label_format,
-			Coord( label_x, label_y ),
-			image_buffer_count,
-			warmup_count,
-			pre_event_count,
-			post_event_count,
-			stream_replay_buffer,
-			alarm_frame_count,
-			section_length,
-			frame_skip,
+			STR_F("EventPrefix"),
+			STR_F("LabelFormat"),
+			Coord( INT_F("LabelX"), INT_F("LabelY") ),
+			INT_F("ImageBufferCount"),
+			INT_F("WarmupCount"),
+			INT_F("PreEventCount"),
+			INT_F("PostEventCount"),
+			INT_F("StreamReplayBuffer"),
+			INT_F("AlarmFrameCount"),
+			INT_F("SectionLength"),
+			INT_F("FrameSkip"),
 			capture_delay,
 			alarm_capture_delay,
-			fps_report_interval,
-			ref_blend_perc,
-			track_motion,
-            RGB_WHITE,
+			INT_F("FpsReportInterval"),
+			INT_F("RefBlendPerc"),
+			INT_F("TrackMotion"),
+			RGB_WHITE,
 			purpose
 		);
 		Zone **zones = 0;
User avatar
iconnor
Posts: 2880
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: Any interest in patch to simplify config reading?

Post by iconnor »

Short answer yes, long answer is that I'd like to see us switch to a db abstraction library so that we can talk to many different database types.

I realise it has been 8 years since you posted this, but are you still interested in contributing?
Post Reply