-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathramserver.c
More file actions
972 lines (789 loc) · 26.4 KB
/
ramserver.c
File metadata and controls
972 lines (789 loc) · 26.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
/*
* ramserver- A program that publishes the GIMP
* PDB on the DBUS while handling method calls
* to the GIMP from the DBUS.
*
* Copyright (c) 2012 Samuel Rebelsky, Hart Russell, and Prashanna Tiwaree
*/
// +---------+
// | Headers |
// +---------+
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
// +------------------------------------+
// | Support for Printf-Style Debugging |
// +------------------------------------+
/*
* When you want messages, use the first version of #define DEBUG. When you
* want to turn them off, use the second.
*/
#define DEBUG(...) do { fprintf (stderr, __VA_ARGS__); fprintf (stderr, "\n"); } while (0)
// #define DEBUG(...) do { } while (0)
// +-------+
// | Types |
// +-------+
/*
* gimpnames struct to help create GDBusMethodInfo
*/
struct gimpnames {
gchar **procnames;
gint nprocs;
};
// +---------+
// | Globals |
// +---------+
/*
* The GDBusNodeInfo to be published to the dbus.
*/
static GDBusNodeInfo *finalnode = NULL;
/**
* Information on the registration id for this process.
*/
static guint registration_id;
// +-----------------+------------------------------------------------
// | Predeclarations |
// +-----------------+
void rserver_handle_method_call (GDBusConnection *connection,
const gchar *method_name,
GVariant *parameters,
GDBusMethodInvocation *invocation);
// +-----------------+
// | DBUS/GIMP Stuff |
// +-----------------+
//handle_method_call - handles method calls from the dbus
static void
handle_method_call (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *method_name,
GVariant *parameters,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
rserver_handle_method_call (connection,
method_name,
parameters,
invocation);
}//handle_method_call
//handle_get_property
static GVariant *
handle_get_property (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *property_name,
GError **error,
gpointer user_data)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
"No property %s found in interface %s.",
property_name,
interface_name);
// NULL signals failure.
return NULL;
}//handle_get_property
//handle_set_property
static gboolean
handle_set_property (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *property_name,
GVariant *value,
GError **error,
gpointer user_data)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
"No property %s found in interface %s.",
property_name,
interface_name);
// false signals failure.
return FALSE;
}//handle_set_property
//query
static void query (void);
//run
static void run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
//interface_vtable
static const GDBusInterfaceVTable interface_vtable =
{
handle_method_call,
handle_get_property,
handle_set_property
};//interface_vtable
//on_bus_aquired
static void
on_bus_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
DEBUG("Bus acquired.");
registration_id = g_dbus_connection_register_object (connection,
"/edu/grinnell/cs/glimmer/HARTRULES",
finalnode->interfaces[0],
&interface_vtable,
NULL, /* user_data */
NULL, /* user_data_free_func */
NULL); /* GERROR */
DEBUG ("Object registered.");
} // on_bus_acquired
//on_name_acquired
static void
on_name_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
DEBUG ("Acquired name %s", name);
} // on_name_acquired
//on_name_lost
static void
on_name_lost (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
DEBUG ("Lost name %s", name);
exit (1);
} // on_name_lost
//PLUG_IN_INFO
GimpPlugInInfo PLUG_IN_INFO =
{
NULL,
NULL,
query,
run
};//PLUG_IN_INFO
//GIMP MAIN
MAIN()
//query
static void
query (void)
{
// saving in constant memory what the data I expect from Gimp
static GimpParamDef args[] =
{
{
GIMP_PDB_INT32, // determines the run-mode whether it is interactive or non-interactive
"run-mode",
"RM"
},
{
GIMP_PDB_IMAGE, // Input image
"image",
"Input image"
},
{
GIMP_PDB_DRAWABLE,// Input drawable
"drawable",
"Input drawable"
}
};
gimp_install_procedure (
"RamServer",
"Node Info Test",
"Publishes Node on the DBUS",
"Hart Russell & Prashanna Tiwaree",
"Copyright RAMS 2012",
"2012",
"<Toolbox>/Xtns/MediaScript/RamServer",
NULL, // was "RGB*, GRAY*",
GIMP_PLUGIN,
G_N_ELEMENTS (args), 0,
args, NULL);
} // query
// +----------------------------+
// | Handle Method Call Helpers |
// +----------------------------+
/**
* Replace one character by another.
*/
gchar *
strrep (gchar *str, gchar target, gchar replacement)
{
gchar *tmp = str;
while ((tmp = strchr (tmp, target)) != NULL)
*tmp = replacement;
return str;
} // strrep
//Convert a GimpParamDef to a GVariant signature
static const gchar *
rserver_pdb_type_to_signature (GimpPDBArgType type)
{
const gchar *result;
switch (type)
{
case GIMP_PDB_INT32:
result = (const gchar *) G_VARIANT_TYPE_INT32;
break;
case GIMP_PDB_INT16:
result = (const gchar *) G_VARIANT_TYPE_INT16;
break;
case GIMP_PDB_INT8:
result = (const gchar *) G_VARIANT_TYPE_BYTE;
break;
case GIMP_PDB_FLOAT:
result = (const gchar *) G_VARIANT_TYPE_DOUBLE;
break;
case GIMP_PDB_STRING:
result = (const gchar *) G_VARIANT_TYPE_STRING;
break;
case GIMP_PDB_STRINGARRAY:
result = (const gchar *) G_VARIANT_TYPE_STRING_ARRAY;
break;
case GIMP_PDB_INT32ARRAY:
result = (const gchar *) ((const GVariantType *) "ai");
break;
case GIMP_PDB_INT16ARRAY:
result = (const gchar *) ((const GVariantType *) "an");
break;
case GIMP_PDB_INT8ARRAY:
result = (const gchar *) ((const GVariantType *) "ai");
break;
case GIMP_PDB_FLOATARRAY:
result = (const gchar *) ((const GVariantType *) "ad");
break;
case GIMP_PDB_DISPLAY:
result = (const gchar *) G_VARIANT_TYPE_INT32;
break;
case GIMP_PDB_IMAGE:
result = (const gchar *) G_VARIANT_TYPE_INT32;
break;
case GIMP_PDB_LAYER:
result = (const gchar *) G_VARIANT_TYPE_INT32;
break;
default:
result = (const gchar *) G_VARIANT_TYPE_INT32;
break;
} // switch
return result;
} // gimpbus_pdb_param_to_signature
//gimpbus_g_variant_to_gimp_param- converts a single GVariant to a GimpParam, which gets stored
// in the already allocated param. Returns success/failure.
gboolean
rserver_g_variant_to_gimp_param (GVariant *parameter,
GimpPDBArgType type,
GimpParam *param)
{
unsigned long nchildren;
int arraycounter = 0;
char* tempc;
gint32 temp32;
gint8 temp8;
gdouble tempd;
gchar** sarray = NULL;
gint32* array32 = NULL;
gint8* array8 = NULL;
gdouble* arrayd = NULL;
// Make sure that types match
const gchar *paramtype = rserver_pdb_type_to_signature (type);
if (! g_variant_type_equal ((GVariantType *) paramtype,
g_variant_get_type (parameter)))
{
DEBUG("you're not converting types correctly");
return FALSE;
} // g_variant_type_equal
param->type = type;
switch (type)
{
case GIMP_PDB_INT32:
case GIMP_PDB_DISPLAY:
case GIMP_PDB_IMAGE:
case GIMP_PDB_LAYER:
case GIMP_PDB_CHANNEL:
case GIMP_PDB_DRAWABLE:
case GIMP_PDB_SELECTION:
case GIMP_PDB_BOUNDARY:
case GIMP_PDB_VECTORS:
param->data.d_int32 = g_variant_get_int32 (parameter);
return TRUE;
case GIMP_PDB_STRING:
param->data.d_string = g_variant_dup_string (parameter, NULL);
return TRUE;
case GIMP_PDB_STRINGARRAY:
nchildren = g_variant_n_children (parameter);
sarray = g_try_malloc ((nchildren) * sizeof (gchar *));
for (arraycounter = 0; arraycounter<nchildren; arraycounter++)
{
g_variant_get_child (parameter, arraycounter, "s", &tempc);
sarray[arraycounter] = tempc;
//fprintf(stderr, "%s\n", tempc);
}
sarray[nchildren] = NULL;
param->data.d_stringarray = sarray;
return TRUE;
case GIMP_PDB_INT32ARRAY:
nchildren = g_variant_n_children (parameter);
array32 = g_try_malloc ((nchildren) * sizeof (gint32));
for (arraycounter = 0; arraycounter<nchildren; arraycounter++)
{
g_variant_get_child (parameter, arraycounter, "i", &temp32);
array32[arraycounter] = temp32;
}
param->data.d_int32array = array32;
return TRUE;
case GIMP_PDB_INT8ARRAY:
nchildren = g_variant_n_children (parameter);
array8 = g_try_malloc ((nchildren) * sizeof (gint8));
for (arraycounter = 0; arraycounter<nchildren; arraycounter++)
{
g_variant_get_child (parameter, arraycounter, "i", &temp8);
array8[arraycounter] = temp8;
}
param->data.d_int8array = array8;
return TRUE;
case GIMP_PDB_FLOATARRAY:
nchildren = g_variant_n_children (parameter);
arrayd = g_try_malloc ((nchildren) * sizeof (gdouble));
for (arraycounter = 0; arraycounter<nchildren; arraycounter++)
{
g_variant_get_child (parameter, arraycounter, "d", &tempd);
arrayd[arraycounter] = tempd;
}
param->data.d_floatarray = arrayd;
return TRUE;
default:
return FALSE;
} // switch
} // gimpbus_g_variant_to_gimp_param
// Convert a GVariant to a a newly allocated array of GimpParams.
gboolean
rserver_g_variant_to_gimp_params (GVariant *parameters,
GimpParamDef *types,
GimpParam **actuals)
{
int nparams = g_variant_n_children (parameters);
GimpParam *result = g_new (GimpParam, nparams);
int i;
for (i = 0; i < nparams; i++)
{
GVariant *param = g_variant_get_child_value (parameters, i);
if (! rserver_g_variant_to_gimp_param (param,
types[i].type,
&(result[i])))
{
g_free (result);
return FALSE;
}
} // for each parameter
*actuals = result;
return TRUE;
} // gimpbus_g_variant_to_gimp_params
GVariant *
rserver_gimp_param_to_g_variant (GimpParam value, int * asize)
{
GVariantBuilder abuilder;
int arrcounter = 0;
switch (value.type)
{
case GIMP_PDB_INT32:
case GIMP_PDB_DISPLAY:
case GIMP_PDB_IMAGE:
case GIMP_PDB_LAYER:
case GIMP_PDB_CHANNEL:
case GIMP_PDB_DRAWABLE:
case GIMP_PDB_SELECTION:
case GIMP_PDB_BOUNDARY:
case GIMP_PDB_VECTORS:
return g_variant_new ("i", value.data.d_int32);
case GIMP_PDB_STRING:
return g_variant_new ("s", value.data.d_string);
//added a ton of value cases here
case GIMP_PDB_INT16:
return g_variant_new ("n", value.data.d_int16);
case GIMP_PDB_INT8:
return g_variant_new ("i", value.data.d_int8);
case GIMP_PDB_FLOAT:
return g_variant_new ("d", value.data.d_float);
//STRINGARRAY
case GIMP_PDB_STRINGARRAY:
g_variant_builder_init (&abuilder, G_VARIANT_TYPE_STRING_ARRAY);
for(arrcounter = 0; arrcounter< *asize; arrcounter++)
{
g_variant_builder_add_value (&abuilder, g_variant_new("s", value.data.d_stringarray[arrcounter]));
fprintf(stderr, "%s",value.data.d_stringarray[arrcounter] );
}
return g_variant_builder_end(&abuilder);
// g_variant_builder_clear (&abuilder);
//INT32ARRAY
case GIMP_PDB_INT32ARRAY:
g_variant_builder_init (&abuilder, ((const GVariantType *) "ai"));
for(arrcounter = 0; arrcounter< *asize; arrcounter++)
{
g_variant_builder_add_value (&abuilder, g_variant_new("i", value.data.d_int32array[arrcounter]));
}
return g_variant_builder_end(&abuilder);
//INT16ARRAY
case GIMP_PDB_INT16ARRAY:
g_variant_builder_init (&abuilder, G_VARIANT_TYPE_TUPLE);
for(arrcounter = 0; arrcounter< *asize; arrcounter++)
{
g_variant_builder_add_value (&abuilder, g_variant_new("n", value.data.d_int16array[arrcounter]));
}
return g_variant_builder_end(&abuilder);
//INT8ARRAY
case GIMP_PDB_INT8ARRAY:
//use uchar to get each bit from array
arrcounter = 0;
g_variant_builder_init (&abuilder, ((const GVariantType *) "ai"));
for(arrcounter = 0; arrcounter< *asize; arrcounter++)
{
g_variant_builder_add_value (&abuilder, g_variant_new("i", value.data.d_int8array[arrcounter]));
}
return g_variant_builder_end(&abuilder);
//FLOATARRAY
case GIMP_PDB_FLOATARRAY:
g_variant_builder_init (&abuilder, G_VARIANT_TYPE_TUPLE);
for(arrcounter = 0; arrcounter< *asize; arrcounter++)
{
g_variant_builder_add_value (&abuilder, g_variant_new("d", value.data.d_floatarray[arrcounter]));
}
return g_variant_builder_end(&abuilder);
default:
return NULL;
}
} // gimpbus_gimp_param_to_g_variant
//if arraytype, get the length in the gimpparam before it
GVariant *
rserver_gimp_params_to_g_variant (GimpParam *values, int nvalues)
{
GVariantBuilder builder;
int i, arrsize;
GVariant *val;
DEBUG("DO I GET HERE EVEN?");
g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
for (i = 0; i < nvalues; i++)
{
DEBUG ("building the list");
if(values[i].type == GIMP_PDB_STRINGARRAY || GIMP_PDB_INT8ARRAY || GIMP_PDB_INT32ARRAY || GIMP_PDB_INT16ARRAY || GIMP_PDB_FLOATARRAY)
arrsize = values[i-1].data.d_int32;
val = rserver_gimp_param_to_g_variant (values[i], &arrsize);
DEBUG ("it's going to fail here isn't it?");
if (val == NULL)
{
DEBUG ("failed to add GimpParam ");
return NULL;
} // if (val == NULL)
g_variant_builder_add_value (&builder, val);
DEBUG ("perhaps here if i'm unlucky?");
} // for each value
return g_variant_builder_end (&builder);
} // gimpbus_gimp_params_to_g_variant
void
rserver_handle_method_call (GDBusConnection *connection,
const gchar *method_name,
GVariant *parameters,
GDBusMethodInvocation *invocation)
{
gchar *proc_name;
gchar *proc_blurb;
gchar *proc_help;
gchar *proc_author;
gchar *proc_copyright;
gchar *proc_date;
GimpPDBProcType proc_type;
GimpParamDef *formals;
gint nparams;
GimpParamDef *return_types;
gint nreturn_vals;
GimpParam *actuals = NULL; // The arguments to the call.
GimpParam *values = NULL; // The return values from the call.
gint nvalues; // Number of return values.
GVariant *result;
fprintf (stderr, "Name of the method before %s \n", method_name);
proc_name = strrep (g_strdup (method_name), '_', '-');
fprintf (stderr, "Name of the method after %s \n", proc_name);
DEBUG("WE GET HERE!");
/*g_dbus_method_invocation_return_dbus_error (invocation,
"you dun goofed",
"try again");
*/
// Look up the information on the procedure in the PDB
if (! gimp_procedural_db_proc_info (proc_name,
&proc_blurb,
&proc_help,
&proc_author,
&proc_copyright,
&proc_date,
&proc_type,
&nparams, &nreturn_vals,
&formals, &return_types))
{
DEBUG("invalid procedure call");
return;
} // if we can't get the information
DEBUG("here is the best");
// Check the number of parameters
//nparams = g_variant_n_children (parameters);
// build the parameters
rserver_g_variant_to_gimp_params (parameters, formals, &actuals);
DEBUG("TESTING RIGHT MERE");
// Do the call
values = gimp_run_procedure2 (proc_name, &nvalues, nparams, actuals);
DEBUG("over here");
// Convert the values back to a GVariant
result = rserver_gimp_params_to_g_variant (values+1, nvalues-1);
DEBUG("gotta be this one");
// Return via DBus
g_dbus_method_invocation_return_value (invocation, result);
DEBUG("actually, it's this one");
// Cleanup: TODO
//g_variant_unref (result);
} // gimpbus_handle_pdb_method_call
// +------------------------+
// | GDBus helper functions |
// +------------------------+
//node_new - creates GDBusNodeInfo to register on DBUS
GDBusNodeInfo *
node_new (gchar *path,
GDBusInterfaceInfo **interfaces,
GDBusNodeInfo **nodes,
GDBusAnnotationInfo **annotations)
{
GDBusNodeInfo *node = g_try_malloc (sizeof (GDBusNodeInfo));
if (node == NULL)
return NULL;
node->ref_count = 1;
node->path = path;
node->interfaces = interfaces;
node->nodes = nodes;
node->annotations = annotations;
return node;
} // node_new
//arg_new - used to help build methodinfo
GDBusArgInfo *
arg_new (gchar *name,
const gchar *signature,
GDBusAnnotationInfo **annotations)
{
GDBusArgInfo *arg= g_try_malloc (sizeof (GDBusArgInfo));
if (arg == NULL)
return NULL;
arg->ref_count = 0;
arg->name = name;
arg->signature = (gchar *) signature;
arg->annotations = annotations;
return arg;
} // arg_new
//g_dbus_method_info_build - builds GDBusMethodInfo struct
GDBusMethodInfo *
g_dbus_method_info_build (gchar *name,
GDBusArgInfo **in_args,
GDBusArgInfo **out_args,
GDBusAnnotationInfo **annotations)
{
GDBusMethodInfo *method = g_try_malloc (sizeof (GDBusMethodInfo));
if (method == NULL)
return NULL;
method->name = name;
method->ref_count = 1;
method->in_args = in_args;
method->out_args = out_args;
method->annotations = annotations;
return method;
} // g_dbus_method_info_build
// rserver_pdb_param_to_arginfo - Converts a GimpParamDef to a GDBusArgInfo.
GDBusArgInfo *
rserver_pdb_param_to_arginfo (GimpParamDef param)
{
gchar *name = strrep (g_strdup (param.name), '-', '_');
//gchar *name = param.name;
const gchar *type = rserver_pdb_type_to_signature (param.type);
GDBusArgInfo *result = arg_new (name, type, NULL);
if (result == NULL)
{
fprintf (stderr, "Could not allocate argument.\n");
}
return result;
} // rserver_pdb_param_to_arginfo
//procnamesbuilder - makes a gimpnames struct with all GIMP proc names and # of proc names
struct gimpnames *
procnamesbuilder ()
{
struct gimpnames *gimpnamelist;
gimpnamelist = g_try_malloc (sizeof (struct gimpnames));
gimp_procedural_db_query (".*", ".*", ".*", ".*", ".*", ".*", ".*", &gimpnamelist->nprocs, &gimpnamelist->procnames);
return gimpnamelist;
}//gimpnames
// generate_pdb_method_info - given a PDB proc name, returns the method info
static GDBusMethodInfo *
generate_pdb_method_info (gchar *proc_name)
{
// Lots and lots and lots of fields for getting info.
gchar *proc_blurb;
gchar *proc_help;
gchar *proc_author;
gchar *proc_copyright;
gchar *proc_date;
GimpPDBProcType proc_type;
GimpParamDef *formals;
gint nparams;
GimpParamDef *return_types;
gint nreturn_vals;
// Parts of our return information
gint i; // Counter variable
GDBusArgInfo **args = NULL; // Argument info
GDBusArgInfo **returns = NULL; // Return value info
// Get the information
if (! gimp_procedural_db_proc_info (proc_name,
&proc_blurb,
&proc_help,
&proc_author,
&proc_copyright,
&proc_date,
&proc_type,
&nparams, &nreturn_vals,
&formals, &return_types))
{
fprintf (stderr, "ya messed up ya dingus\n");
return NULL;
}
// Process the parameters
if (nparams > 0)
{
args = g_new (GDBusArgInfo *, nparams+1);
for (i = 0; i < nparams; i++)
{
args[i] = rserver_pdb_param_to_arginfo (formals[i]);
g_assert (args[i] != NULL);
} // for
// Terminate the array
args[nparams] = NULL;
} // if (nparams > 0)
// Process the return values
if (nreturn_vals > 0)
{
returns = g_new (GDBusArgInfo *, nreturn_vals+1);
for (i = 0; i < nreturn_vals ; i++)
{
returns[i] = rserver_pdb_param_to_arginfo (return_types[i]);
g_assert (returns[i] != NULL);
} // for
// Terminate the array
returns[nreturn_vals] = NULL;
} // if (nreturn_vals > 0)
GDBusMethodInfo * result =
g_dbus_method_info_build (strrep (g_strdup (proc_name), '-', '_'),//used to be proc_name
args,
returns,
NULL);
return result;
} // rserver_pdb_method
// methmaker- returns GDBusMethodInfo with all proc info
GDBusMethodInfo **
methmaker (struct gimpnames *nms)
{
//DEBUG("does it get here?");
GDBusMethodInfo **nfo = g_new (GDBusMethodInfo *, nms->nprocs + 1);
if (nfo == NULL)
{
fprintf (stderr, "Could not allocate method information.\n");
return NULL;
}
int i;
// BUG
// At procedure 309 (at least on Hart's machine), generate_pdb_method_info
// fails and causes the program to crash. It's clearly a memory error.
//
// On Hart's machine, procedure 309 is script-fu-font-map.
//
// Use of GDB suggests that the error is in gimp_procedural_db_proc_info,
// which shouldn't cause a crash.
//
// Valgrind on a different machine did not reveal an error near
// script-fu-font-map. However, it did reveal an invalid write of
// size 8 for file-xjt-load. First, an invalid write of size 8.
// Ah hah! It looks like they did not allocate enough space for
// the return values.
/*
error: at procedure 309 (maybe 310) generate_pdb_method_info fails and causes the plugin to crash, specifically I think it crashes in
*/
fprintf (stderr, "Testing script-fu-font-map as first procedure.\n");
nfo[0] = generate_pdb_method_info ("script-fu-font-map");
fprintf (stderr, "Done testing.\n");
for (i = 0; i < nms->nprocs; i++)
{
fprintf (stderr, "%d: %s\n", i, nms->procnames[i]);
nfo[i] = generate_pdb_method_info (nms->procnames[i]);
}
//DEBUG("what about here?");
// nfo[308]=NULL;
nfo[nms->nprocs] = NULL;
//DEBUG("does it get here?");
return nfo;
}//methmaker
// +-----------+
// | GIMP MAIN |
// +-----------+
static void
run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[1];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
int pid; // Process ID; for debugging
pid = getpid ();
/* Setting mandatory output values */
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
guint owner_id;
GString *xml = g_string_new ("");
GDBusInterfaceInfo **interfaces = g_try_malloc (2 * sizeof (GDBusInterfaceInfo *));
GDBusInterfaceInfo *interface = g_try_malloc (sizeof (GDBusInterfaceInfo));
interface->ref_count = 1;
interface->name = "edu.grinnell.Glimmer.Test01";
struct gimpnames *gnames;
GDBusMethodInfo **info;
DEBUG ("About to create gnames");
gnames = procnamesbuilder();
DEBUG ("About to make methods");
info = methmaker(gnames);
DEBUG ("Done making methods");
interface->methods = info;
interface->signals = NULL;
interface->properties = NULL;
interface->annotations = NULL;
interfaces[0] = interface;
interfaces[1] = NULL;
g_dbus_interface_info_generate_xml (interface, 0, xml);
GMainLoop *loop;
g_type_init ();
DEBUG ("About to make node.");
finalnode = node_new(NULL, interfaces, NULL, NULL);
DEBUG ("Made node.");
/* g_dbus_node_info_generate_xml (finalnode, 0, xml);
fprintf (stderr, "%s\n", xml->str);
*/
DEBUG ("About to own name");
owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
"edu.grinnell.cs.glimmer.RAMStest",
G_BUS_NAME_OWNER_FLAGS_NONE,
on_bus_acquired,
on_name_acquired,
on_name_lost,
NULL,
NULL);
DEBUG ("Owned name");
fprintf (stderr, "ramserver process %d is pausing ...\n", pid);
//sleep (6);
// Event loop. Wait for functions to get called asyn h.
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
g_bus_unown_name (owner_id);
g_dbus_node_info_unref (finalnode);
gimp_displays_flush(); // update all the changes we have made to the user interface //
return;
}