@@ -8,18 +8,6 @@ namespace My {
8
8
9
9
extern void init_gstreamer (); // from pfft-shim.c
10
10
11
- // Types {{{1
12
-
13
- /**
14
- * Map from friendly names to GTypes.
15
- *
16
- * Used to store and sort readers and writers.
17
- * This is a typedef.
18
- */
19
- private class ClassMap : Gee .TreeMap<string, GLib .Type > { }
20
-
21
- // }}}1
22
-
23
11
/**
24
12
* Main application class for pfft
25
13
*/
@@ -134,7 +122,7 @@ namespace My {
134
122
{
135
123
Intl . setlocale (LocaleCategory . ALL , " " ); // init locale from environment
136
124
init_gstreamer();
137
- linit();
125
+ Log . linit();
138
126
}
139
127
140
128
/**
@@ -212,8 +200,8 @@ namespace My {
212
200
Reader reader;
213
201
var reader_name = opt_reader_name ?? reader_default_;
214
202
try {
215
- reader = create_instance(
216
- readers_, reader_name , opt_reader_options) as Reader ;
203
+ reader = readers_ . create_instance(
204
+ reader_name, template_ , opt_reader_options) as Reader ;
217
205
} catch (KeyFileError e) {
218
206
printerr (" Could not create reader: %s\n " , e. message);
219
207
return 1 ;
@@ -222,8 +210,8 @@ namespace My {
222
210
Writer writer;
223
211
var writer_name = opt_writer_name ?? writer_default_;
224
212
try {
225
- writer = create_instance(
226
- writers_, writer_name , opt_writer_options) as Writer ;
213
+ writer = writers_ . create_instance(
214
+ writer_name, template_ , opt_writer_options) as Writer ;
227
215
} catch (KeyFileError e) {
228
216
printerr (" Could not create writer: %s\n " , e. message);
229
217
return 1 ;
@@ -417,92 +405,6 @@ namespace My {
417
405
return sb. str;
418
406
} // get_classmap_help
419
407
420
- /**
421
- * Create an instance and set its properties.
422
- *
423
- * Sets properties from template_ first, then from @options.
424
- */
425
- private Object create_instance (ClassMap m , string class_name ,
426
- string []? options ) throws KeyFileError
427
- {
428
- if (! m. has_key(class_name)) {
429
- throw new KeyFileError .KEY_NOT_FOUND (
430
- " %s : Class not registered" . printf(class_name));
431
- }
432
-
433
- var type = m. get (class_name);
434
- Object retval = Object . new (type);
435
- set_props_from_template(type, retval, template_);
436
-
437
- if (options == null ) {
438
- return retval; // *** EXIT POINT ***
439
- }
440
-
441
- // property accessor for the instance we are creating
442
- ObjectClass ocl = (ObjectClass ) type. class_ref ();
443
-
444
- // Assign the properties
445
- var num_opts = (options == null ) ? 0 : strv_length(options);
446
- for (int i= 0 ; i< num_opts; ++ i) {
447
- var optspec = options[i];
448
- var nv = optspec. split(" =" , 2 );
449
- if (nv. length != 2 ) {
450
- throw new KeyFileError .INVALID_VALUE (
451
- " %s : Invalid option %s " . printf(class_name, optspec));
452
- }
453
-
454
- // print("Trying %p->%s := %s\n", retval, nv[0], nv[1]);
455
- var prop = ocl. find_property(nv[0 ]);
456
- if (prop == null || prop. get_name()[0 ] == ' P' ) { // skip unknown, private
457
- throw new KeyFileError .KEY_NOT_FOUND (
458
- " %s : %s is not an option I understand" . printf(
459
- class_name, nv[0 ]));
460
- }
461
-
462
- var val = GLib . Value (prop. value_type);
463
- if (! deserialize_value(ref val, nv[1 ])) {
464
- throw new KeyFileError .INVALID_VALUE (
465
- " %s : Invalid value %s for option %s " . printf(
466
- class_name, nv[1 ], nv[0 ]));
467
- }
468
-
469
- retval. set_property(nv[0 ], val);
470
- linfoo(retval, " Set property %s from command line to %s " ,
471
- nv[0 ], val. type() == typeof (string ) ? @" '$(val.get_string())'" :
472
- Gst . Value . serialize(val));
473
-
474
- } // foreach option
475
-
476
- return retval;
477
- } // create_instance()
478
-
479
- private void set_props_from_template (GLib .Type instance_type ,
480
- Object instance , Template tmpl )
481
- {
482
- // property accessor for the instance we are creating
483
- ObjectClass ocl = (ObjectClass ) instance_type. class_ref ();
484
-
485
- // property accessor for the template
486
- ObjectClass tocl = (ObjectClass ) tmpl. get_type(). class_ref ();
487
-
488
- // Set properties from the template
489
- foreach (var tprop in tocl. list_properties()) {
490
- string propname = tprop. get_name();
491
- ldebugo(instance, " Trying template property %s " , propname);
492
- var prop = ocl. find_property(propname);
493
- if (prop == null || propname[0 ] == ' P' || prop. value_type != tprop. value_type) {
494
- ldebugo(instance, " --- skipping" );
495
- continue ;
496
- }
497
-
498
- Value v = Value (prop. value_type);
499
- tmpl. get_property(propname, ref v);
500
- instance. set_property(propname, v);
501
- linfoo(instance, " Set property %s from template to %s " ,
502
- propname, Gst . Value . serialize(v));
503
- }
504
- } // set_props_from_template()
505
-
506
408
// }}}1
507
409
} // class App
508
410
} // My
0 commit comments