aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/edje/src/lib/edje_message_queue.c
blob: 5628ccc477ef87b15105785e220ef0a9c0877a41 (plain)
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
#include "edje_private.h"

static void _edje_object_message_popornot_send(Evas_Object *obj, Edje_Message_Type type, int id, void *msg, Eina_Bool prop);

static int _injob = 0;
static Ecore_Job *_job = NULL;
static Ecore_Timer *_job_loss_timer = NULL;

static Eina_List *msgq = NULL;
static Eina_List *tmp_msgq = NULL;
static int tmp_msgq_processing = 0;
static int tmp_msgq_restart = 0;

/*============================================================================*
 *                                   API                                      *
 *============================================================================*/

static void
_edje_object_message_popornot_send(Evas_Object *obj, Edje_Message_Type type, int id, void *msg, Eina_Bool prop)
{
   Edje *ed;
   Eina_List *l;
   Evas_Object *o;

   ed = _edje_fetch(obj);
   if (!ed) return;
   _edje_message_propornot_send(ed, EDJE_QUEUE_SCRIPT, type, id, msg, prop);
   EINA_LIST_FOREACH(ed->subobjs, l, o)
     {
        _edje_object_message_popornot_send(o, type, id, msg, EINA_TRUE);
     }
}

EAPI void
edje_object_message_send(Evas_Object *obj, Edje_Message_Type type, int id, void *msg)
{
   _edje_object_message_popornot_send(obj, type, id, msg, EINA_FALSE);
}


EAPI void
edje_object_message_handler_set(Evas_Object *obj, Edje_Message_Handler_Cb func, void *data)
{
   Edje *ed;

   ed = _edje_fetch(obj);
   if (!ed) return;
   _edje_message_cb_set(ed, func, data);
}


EAPI void
edje_object_message_signal_process(Evas_Object *obj)
{
   Eina_List *l, *ln, *tmpq = NULL;
   Edje *ed;
   Edje_Message *em;
   int gotos = 0;

   ed = _edje_fetch(obj);
   if (!ed) return;

   for (l = msgq; l; )
     {
        ln = l->next;
        em = l->data;
        if (em->edje == ed)
          {
             tmpq = eina_list_append(tmpq, em);
             msgq = eina_list_remove_list(msgq, l);
          }
        l = ln;
     }
   /* a temporary message queue */
   if (tmp_msgq)
     {
	while (tmpq)
	  {
	     tmp_msgq = eina_list_append(tmp_msgq, tmpq->data);
	     tmpq = eina_list_remove_list(tmpq, tmpq);
	  }
     }
   else
     {
	tmp_msgq = tmpq;
	tmpq = NULL;
     }

   tmp_msgq_processing++;
again:
   EINA_LIST_FOREACH_SAFE(tmp_msgq, l, ln, em)
     {
        if (em->edje != ed) continue;
	tmp_msgq = eina_list_remove_list(tmp_msgq, l);
        if (!ed->delete_me)
          {
             ed->processing_messages++;
             _edje_message_process(em);
             _edje_message_free(em);
             ed->processing_messages--;
          }
        else
           _edje_message_free(em);
        if (ed->processing_messages == 0)
          {
             if (ed->delete_me) _edje_del(ed);
          }
        // if some child callback in _edje_message_process called
        // edje_object_message_signal_process() or
        // edje_message_signal_process() then those will mark the restart
        // flag when they finish - it mabsicammyt means tmp_msgq and
        // any item in it has potentially become invalid - so that means l
        // and ln could be rogue pointers, so start again from the beginning
        // and skip anything that is not this object and process only what is.
        // to avoid self-feeding loops allow a max of 1024 loops.
        if (tmp_msgq_restart)
          {
             tmp_msgq_restart = 0;
             gotos++;
             if (gotos < 1024) goto again;
             else
               {
                  WRN("Edje is in a self-feeding message loop (> 1024 gotos needed in a row)");
                  goto end;
               }
          }
     }
end:
   tmp_msgq_processing--;
   if (tmp_msgq_processing == 0)
      tmp_msgq_restart = 0;
   else
      tmp_msgq_restart = 1;
}


EAPI void
edje_message_signal_process(void)
{
   _edje_message_queue_process();
}


static Eina_Bool
_edje_dummy_timer(void *data __UNUSED__)
{
   return ECORE_CALLBACK_CANCEL;
}

static void
_edje_job(void *data __UNUSED__)
{
   if (_job_loss_timer)
     {
	ecore_timer_del(_job_loss_timer);
	_job_loss_timer = NULL;
     }
   _job = NULL;
   _injob++;
   _edje_message_queue_process();
   _injob--;
}

static Eina_Bool
_edje_job_loss_timer(void *data __UNUSED__)
{
   _job_loss_timer = NULL;
   if (!_job)
     {
        _job = ecore_job_add(_edje_job, NULL);
     }
   return ECORE_CALLBACK_CANCEL;
}

void
_edje_message_init(void)
{
}

void
_edje_message_shutdown(void)
{
   _edje_message_queue_clear();
   if (_job_loss_timer)
     {
        ecore_timer_del(_job_loss_timer);
        _job_loss_timer = NULL;
     }
   if (_job)
     {
        ecore_job_del(_job);
        _job = NULL;
     }
}

void
_edje_message_cb_set(Edje *ed, void (*func) (void *data, Evas_Object *obj, Edje_Message_Type type, int id, void *msg), void *data)
{
   Eina_List *l;
   Evas_Object *o;

   ed->message.func = func;
   ed->message.data = data;
   EINA_LIST_FOREACH(ed->subobjs, l, o)
     {
        Edje *edj2 = _edje_fetch(o);
        if (!edj2) continue;
        _edje_message_cb_set(edj2, func, data);
     }
}

Edje_Message *
_edje_message_new(Edje *ed, Edje_Queue queue, Edje_Message_Type type, int id)
{
   Edje_Message *em;

   em = calloc(1, sizeof(Edje_Message));
   if (!em) return NULL;
   em->edje = ed;
   em->queue = queue;
   em->type = type;
   em->id = id;
   em->edje->message.num++;
   return em;
}

void
_edje_message_free(Edje_Message *em)
{
   if (em->msg)
     {
	int i;

	switch (em->type)
	  {
	   case EDJE_MESSAGE_STRING:
	       {
		  Edje_Message_String *emsg;

		  emsg = (Edje_Message_String *)em->msg;
		  free(emsg->str);
		  free(emsg);
	       }
	     break;
	   case EDJE_MESSAGE_INT:
	       {
		  Edje_Message_Int *emsg;

		  emsg = (Edje_Message_Int *)em->msg;
		  free(emsg);
	       }
	     break;
	   case EDJE_MESSAGE_FLOAT:
	       {
		  Edje_Message_Float *emsg;

		  emsg = (Edje_Message_Float *)em->msg;
		  free(emsg);
	       }
	     break;
	   case EDJE_MESSAGE_INT_SET:
	       {
		  Edje_Message_Int_Set *emsg;

		  emsg = (Edje_Message_Int_Set *)em->msg;
		  free(emsg);
	       }
	     break;
	   case EDJE_MESSAGE_FLOAT_SET:
	       {
		  Edje_Message_Float_Set *emsg;

		  emsg = (Edje_Message_Float_Set *)em->msg;
		  free(emsg);
	       }
	     break;
	   case EDJE_MESSAGE_STRING_FLOAT:
	       {
		  Edje_Message_String_Float *emsg;

		  emsg = (Edje_Message_String_Float *)em->msg;
		  free(emsg->str);
		  free(emsg);
	       }
	     break;
	   case EDJE_MESSAGE_STRING_INT:
	       {
		  Edje_Message_String_Int *emsg;

		  emsg = (Edje_Message_String_Int *)em->msg;
		  free(emsg->str);
		  free(emsg);
	       }
	     break;
	   case EDJE_MESSAGE_STRING_FLOAT_SET:
	       {
		  Edje_Message_String_Float_Set *emsg;

		  emsg = (Edje_Message_String_Float_Set *)em->msg;
		  free(emsg->str);
		  free(emsg);
	       }
	     break;
	   case EDJE_MESSAGE_STRING_INT_SET:
	       {
		  Edje_Message_String_Int_Set *emsg;

		  emsg = (Edje_Message_String_Int_Set *)em->msg;
		  free(emsg->str);
		  free(emsg);
	       }
	     break;
	   case EDJE_MESSAGE_SIGNAL:
	       {
		  Edje_Message_Signal *emsg;

		  emsg = (Edje_Message_Signal *)em->msg;
		  if (emsg->sig) eina_stringshare_del(emsg->sig);
		  if (emsg->src) eina_stringshare_del(emsg->src);
                  if (emsg->data && (--(emsg->data->ref) == 0))
                    {
                       if (emsg->data->free_func)
                         {
                            emsg->data->free_func(emsg->data->data);
                         }
                       free(emsg->data);
                    }
		  free(emsg);
	       }
	     break;
	   case EDJE_MESSAGE_STRING_SET:
	       {
		  Edje_Message_String_Set *emsg;

		  emsg = (Edje_Message_String_Set *)em->msg;
		  for (i = 0; i < emsg->count; i++)
		    free(emsg->str[i]);
		  free(emsg);
	       }
	     break;
	   case EDJE_MESSAGE_NONE:
	   default:
	     break;
	  }
     }
   free(em);
}

void
_edje_message_propornot_send(Edje *ed, Edje_Queue queue, Edje_Message_Type type, int id, void *emsg, Eina_Bool prop)
{
   /* FIXME: check all malloc & strdup fails and gracefully unroll and exit */
   Edje_Message *em;
   int i;
   unsigned char *msg = NULL;

   em = _edje_message_new(ed, queue, type, id);
   if (!em) return;
   em->propagated = prop;
   if (_job)
     {
        ecore_job_del(_job);
        _job = NULL;
     }
   if (_injob > 0)
     {
        if (!_job_loss_timer)
          _job_loss_timer = ecore_timer_add(0.001, _edje_job_loss_timer, NULL);
     }
   else
     {
        if (!_job)
          {
             _job = ecore_job_add(_edje_job, NULL);
          }
        if (_job_loss_timer)
          {
             ecore_timer_del(_job_loss_timer);
             _job_loss_timer = NULL;
          }
     }
   switch (em->type)
     {
      case EDJE_MESSAGE_NONE:
	break;
      case EDJE_MESSAGE_SIGNAL:
	  {
	     Edje_Message_Signal *emsg2, *emsg3;

	     emsg2 = (Edje_Message_Signal *)emsg;
	     emsg3 = calloc(1, sizeof(Edje_Message_Signal));
	     if (emsg2->sig) emsg3->sig = eina_stringshare_add(emsg2->sig);
	     if (emsg2->src) emsg3->src = eina_stringshare_add(emsg2->src);
	     if (emsg2->data)
               {
                  emsg3->data = emsg2->data;
                  emsg3->data->ref++;
               }
	     msg = (unsigned char *)emsg3;
	  }
	break;
      case EDJE_MESSAGE_STRING:
	  {
	     Edje_Message_String *emsg2, *emsg3;

	     emsg2 = (Edje_Message_String *)emsg;

	     emsg3 = malloc(sizeof(Edje_Message_String));
	     emsg3->str = strdup(emsg2->str);
	     msg = (unsigned char *)emsg3;
	  }
	break;
      case EDJE_MESSAGE_INT:
	  {
	     Edje_Message_Int *emsg2, *emsg3;

	     emsg2 = (Edje_Message_Int *)emsg;
	     emsg3 = malloc(sizeof(Edje_Message_Int));
	     emsg3->val = emsg2->val;
	     msg = (unsigned char *)emsg3;
	  }
	break;
      case EDJE_MESSAGE_FLOAT:
	  {
	     Edje_Message_Float *emsg2, *emsg3;

	     emsg2 = (Edje_Message_Float *)emsg;
	     emsg3 = malloc(sizeof(Edje_Message_Float));
	     emsg3->val = emsg2->val;
	     msg = (unsigned char *)emsg3;
	  }
	break;
      case EDJE_MESSAGE_STRING_SET:
	  {
	     Edje_Message_String_Set *emsg2, *emsg3;

	     emsg2 = (Edje_Message_String_Set *)emsg;
	     emsg3 = malloc(sizeof(Edje_Message_String_Set) + ((emsg2->count - 1) * sizeof(char *)));
	     emsg3->count = emsg2->count;
	     for (i = 0; i < emsg3->count; i++)
	       emsg3->str[i] = strdup(emsg2->str[i]);
	     msg = (unsigned char *)emsg3;
	  }
	break;
      case EDJE_MESSAGE_INT_SET:
	  {
	     Edje_Message_Int_Set *emsg2, *emsg3;

	     emsg2 = (Edje_Message_Int_Set *)emsg;
	     emsg3 = malloc(sizeof(Edje_Message_Int_Set) + ((emsg2->count - 1) * sizeof(int)));
	     emsg3->count = emsg2->count;
	     for (i = 0; i < emsg3->count; i++)
	       emsg3->val[i] = emsg2->val[i];
	     msg = (unsigned char *)emsg3;
	  }
	break;
      case EDJE_MESSAGE_FLOAT_SET:
	  {
	     Edje_Message_Float_Set *emsg2, *emsg3;

	     emsg2 = (Edje_Message_Float_Set *)emsg;
	     emsg3 = malloc(sizeof(Edje_Message_Float_Set) + ((emsg2->count - 1) * sizeof(double)));
	     emsg3->count = emsg2->count;
	     for (i = 0; i < emsg3->count; i++)
	       emsg3->val[i] = emsg2->val[i];
	     msg = (unsigned char *)emsg3;
	  }
	break;
      case EDJE_MESSAGE_STRING_INT:
	  {
	     Edje_Message_String_Int *emsg2, *emsg3;

	     emsg2 = (Edje_Message_String_Int *)emsg;
	     emsg3 = malloc(sizeof(Edje_Message_String_Int));
	     emsg3->str = strdup(emsg2->str);
	     emsg3->val = emsg2->val;
	     msg = (unsigned char *)emsg3;
	  }
	break;
      case EDJE_MESSAGE_STRING_FLOAT:
	  {
	     Edje_Message_String_Float *emsg2, *emsg3;

	     emsg2 = (Edje_Message_String_Float *)emsg;
	     emsg3 = malloc(sizeof(Edje_Message_String_Float));
	     emsg3->str = strdup(emsg2->str);
	     emsg3->val = emsg2->val;
	     msg = (unsigned char *)emsg3;
	  }
	break;
      case EDJE_MESSAGE_STRING_INT_SET:
	  {
	     Edje_Message_String_Int_Set *emsg2, *emsg3;

	     emsg2 = (Edje_Message_String_Int_Set *)emsg;
	     emsg3 = malloc(sizeof(Edje_Message_String_Int_Set) + ((emsg2->count - 1) * sizeof(int)));
	     emsg3->str = strdup(emsg2->str);
	     emsg3->count = emsg2->count;
	     for (i = 0; i < emsg3->count; i++)
	       emsg3->val[i] = emsg2->val[i];
	     msg = (unsigned char *)emsg3;
	  }
	break;
      case EDJE_MESSAGE_STRING_FLOAT_SET:
	  {
	     Edje_Message_String_Float_Set *emsg2, *emsg3;

	     emsg2 = (Edje_Message_String_Float_Set *)emsg;
	     emsg3 = malloc(sizeof(Edje_Message_String_Float_Set) + ((emsg2->count - 1) * sizeof(double)));
	     emsg3->str = strdup(emsg2->str);
	     emsg3->count = emsg2->count;
	     for (i = 0; i < emsg3->count; i++)
	       emsg3->val[i] = emsg2->val[i];
	     msg = (unsigned char *)emsg3;
	  }
	break;
      default:
	break;
     }

   em->msg = msg;
   msgq = eina_list_append(msgq, em);
}

void
_edje_message_send(Edje *ed, Edje_Queue queue, Edje_Message_Type type, int id, void *emsg)
{
   _edje_message_propornot_send(ed, queue, type, id, emsg, EINA_FALSE);
}

void
_edje_message_parameters_push(Edje_Message *em)
{
   int i;
   
   /* these params ALWAYS go on */
   /* first param is the message type - always */
   embryo_parameter_cell_push(em->edje->collection->script,
			      (Embryo_Cell)em->type);
   /* 2nd param is the integer of the event id - always there */
   embryo_parameter_cell_push(em->edje->collection->script,
			      (Embryo_Cell)em->id);
   /* the rest is varags of whatever is in the msg */
   switch (em->type)
     {
      case EDJE_MESSAGE_NONE:
	break;
      case EDJE_MESSAGE_STRING:
	embryo_parameter_string_push(em->edje->collection->script,
				     ((Edje_Message_String *)em->msg)->str);
	break;
      case EDJE_MESSAGE_INT:
	  {
	     Embryo_Cell v;

	     v = (Embryo_Cell)((Edje_Message_Int *)em->msg)->val;
	     embryo_parameter_cell_array_push(em->edje->collection->script, &v, 1);
	  }
	break;
      case EDJE_MESSAGE_FLOAT:
	  {
	     Embryo_Cell v;
	     float fv;

	     fv = ((Edje_Message_Float *)em->msg)->val;
	     v = EMBRYO_FLOAT_TO_CELL(fv);
	     embryo_parameter_cell_array_push(em->edje->collection->script, &v, 1);
	  }
	break;
      case EDJE_MESSAGE_STRING_SET:
	for (i = 0; i < ((Edje_Message_String_Set *)em->msg)->count; i++)
	  embryo_parameter_string_push(em->edje->collection->script,
				       ((Edje_Message_String_Set *)em->msg)->str[i]);
	break;
      case EDJE_MESSAGE_INT_SET:
	for (i = 0; i < ((Edje_Message_Int_Set *)em->msg)->count; i++)
	  {
	     Embryo_Cell v;

	     v = (Embryo_Cell)((Edje_Message_Int_Set *)em->msg)->val[i];
	     embryo_parameter_cell_array_push(em->edje->collection->script, &v, 1);
	  }
	break;
      case EDJE_MESSAGE_FLOAT_SET:
	for (i = 0; i < ((Edje_Message_Float_Set *)em->msg)->count; i++)
	  {
	     Embryo_Cell v;
	     float fv;

	     fv = ((Edje_Message_Float_Set *)em->msg)->val[i];
	     v = EMBRYO_FLOAT_TO_CELL(fv);
	     embryo_parameter_cell_array_push(em->edje->collection->script, &v, 1);
	  }
	break;
      case EDJE_MESSAGE_STRING_INT:
	embryo_parameter_string_push(em->edje->collection->script,
				     ((Edje_Message_String_Int *)em->msg)->str);
	  {
	     Embryo_Cell v;

	     v = (Embryo_Cell)((Edje_Message_String_Int *)em->msg)->val;
	     embryo_parameter_cell_array_push(em->edje->collection->script, &v, 1);
	  }
	break;
      case EDJE_MESSAGE_STRING_FLOAT:
	embryo_parameter_string_push(em->edje->collection->script,
				     ((Edje_Message_String_Float *)em->msg)->str);
	  {
	     Embryo_Cell v;
	     float fv;

	     fv = ((Edje_Message_String_Float *)em->msg)->val;
	     v = EMBRYO_FLOAT_TO_CELL(fv);
	     embryo_parameter_cell_array_push(em->edje->collection->script, &v, 1);
	  }
	break;
      case EDJE_MESSAGE_STRING_INT_SET:
	embryo_parameter_string_push(em->edje->collection->script,
				     ((Edje_Message_String_Int_Set *)em->msg)->str);
	for (i = 0; i < ((Edje_Message_String_Int_Set *)em->msg)->count; i++)
	  {
	     Embryo_Cell v;

	     v = (Embryo_Cell)((Edje_Message_String_Int_Set *)em->msg)->val[i];
	     embryo_parameter_cell_array_push(em->edje->collection->script, &v, 1);
	  }
	break;
      case EDJE_MESSAGE_STRING_FLOAT_SET:
	embryo_parameter_string_push(em->edje->collection->script,
				     ((Edje_Message_String_Float_Set *)em->msg)->str);
	for (i = 0; i < ((Edje_Message_String_Float_Set *)em->msg)->count; i++)
	  {
	     Embryo_Cell v;
	     float fv;

	     fv = ((Edje_Message_String_Float_Set *)em->msg)->val[i];
	     v = EMBRYO_FLOAT_TO_CELL(fv);
	     embryo_parameter_cell_array_push(em->edje->collection->script, &v, 1);
	  }
	break;
      default:
	break;
     }
}

void
_edje_message_process(Edje_Message *em)
{
   Embryo_Function fn;
   void *pdata;
   int ret;
   
   /* signals are only handled one way */
   if (em->type == EDJE_MESSAGE_SIGNAL)
     {
	_edje_emit_handle(em->edje,
			  ((Edje_Message_Signal *)em->msg)->sig,
			  ((Edje_Message_Signal *)em->msg)->src,
			  ((Edje_Message_Signal *)em->msg)->data,
			  em->propagated);
	return;
     }
   /* if this has been queued up for the app then just call the callback */
   if (em->queue == EDJE_QUEUE_APP)
     {
	if (em->edje->message.func)
	  em->edje->message.func(em->edje->message.data, em->edje->obj,
				 em->type, em->id, em->msg);
	return;
     }
   /* now this message is destined for the script message handler fn */
   if (!(em->edje->collection)) return;
   if ((em->edje->collection->script) && _edje_script_only (em->edje))
     {
	_edje_script_only_message(em->edje, em);
	return;
     }
   if (em->edje->L)
     {
	_edje_lua_script_only_message(em->edje, em);
	return;
     }
   fn = embryo_program_function_find(em->edje->collection->script, "message");
   if (fn == EMBRYO_FUNCTION_NONE) return;
   /* reset the engine */
   _edje_embryo_script_reset(em->edje);
   
   _edje_message_parameters_push(em);
   
   embryo_program_vm_push(em->edje->collection->script);
   _edje_embryo_globals_init(em->edje);
   pdata = embryo_program_data_get(em->edje->collection->script);
   embryo_program_data_set(em->edje->collection->script, em->edje);
   embryo_program_max_cycle_run_set(em->edje->collection->script, 5000000);
   ret = embryo_program_run(em->edje->collection->script, fn);
   if (ret == EMBRYO_PROGRAM_FAIL)
     {
        ERR("ERROR with embryo script. "
            "OBJECT NAME: '%s', "
            "OBJECT FILE: '%s', "
            "ENTRY POINT: '%s', "
            "ERROR: '%s'",
            em->edje->collection->part,
            em->edje->file->path,
            "message",
            embryo_error_string_get(embryo_program_error_get(em->edje->collection->script)));
     }
   else if (ret == EMBRYO_PROGRAM_TOOLONG)
     {
        ERR("ERROR with embryo script. "
            "OBJECT NAME: '%s', "
            "OBJECT FILE: '%s', "
            "ENTRY POINT: '%s', "
            "ERROR: 'Script exceeded maximum allowed cycle count of %i'",
            em->edje->collection->part,
            em->edje->file->path,
            "message",
            embryo_program_max_cycle_run_get(em->edje->collection->script));
     }
   
   embryo_program_data_set(em->edje->collection->script, pdata);
   embryo_program_vm_pop(em->edje->collection->script);
}

void
_edje_message_queue_process(void)
{
   int i;

   if (!msgq) return;

   /* allow the message queue to feed itself up to 8 times before forcing */
   /* us to go back to normal processing and let a 0 timeout deal with it */
   for (i = 0; (i < 8) && (msgq); i++)
     {
	/* a temporary message queue */
	if (tmp_msgq)
	  {
	     while (msgq)
	       {
		  tmp_msgq = eina_list_append(tmp_msgq, msgq->data);
		  msgq = eina_list_remove_list(msgq, msgq);
	       }
	  }
	else
	  {
	     tmp_msgq = msgq;
	     msgq = NULL;
	  }

        tmp_msgq_processing++;
	while (tmp_msgq)
	  {
	     Edje_Message *em;
	     Edje *ed;

	     em = tmp_msgq->data;
	     ed = em->edje;
	     tmp_msgq = eina_list_remove_list(tmp_msgq, tmp_msgq);
	     em->edje->message.num--;
	     if (!ed->delete_me)
	       {
		  ed->processing_messages++;
		  _edje_message_process(em);
		  _edje_message_free(em);
		  ed->processing_messages--;
	       }
	     else
	       _edje_message_free(em);
	     if (ed->processing_messages == 0)
	       {
		  if (ed->delete_me) _edje_del(ed);
	       }
	  }
        tmp_msgq_processing--;
        if (tmp_msgq_processing == 0)
           tmp_msgq_restart = 0;
        else
           tmp_msgq_restart = 1;
     }

   /* if the message queue filled again set a timer to expire in 0.0 sec */
   /* to get the idle enterer to be run again */
   if (msgq)
     {
        static int self_feed_debug = -1;
        
        if (self_feed_debug == -1)
          {
             const char *s = getenv("EDJE_SELF_FEED_DEBUG");
             if (s) self_feed_debug = atoi(s);
             else self_feed_debug = 0;
          }
        if (self_feed_debug)
          {
             WRN("Edje is in a self-feeding message loop (> 8 loops needed)");
          }
	ecore_timer_add(0.0, _edje_dummy_timer, NULL);
     }
}

void
_edje_message_queue_clear(void)
{
   while (msgq)
     {
	Edje_Message *em;

	em = msgq->data;
	msgq = eina_list_remove_list(msgq, msgq);
	em->edje->message.num--;
	_edje_message_free(em);
     }
   while (tmp_msgq)
     {
	Edje_Message *em;

	em = tmp_msgq->data;
	tmp_msgq = eina_list_remove_list(tmp_msgq, tmp_msgq);
	em->edje->message.num--;
	_edje_message_free(em);
     }
}

void
_edje_message_del(Edje *ed)
{
   Eina_List *l;

   if (ed->message.num <= 0) return;
   /* delete any messages on the main queue for this edje object */
   for (l = msgq; l; )
     {
	Edje_Message *em;
	Eina_List *lp;

	em = eina_list_data_get(l);
	lp = l;
	l = eina_list_next(l);
	if (em->edje == ed)
	  {
	     msgq = eina_list_remove_list(msgq, lp);
	     em->edje->message.num--;
	     _edje_message_free(em);
	  }
	if (ed->message.num <= 0) return;
     }
   /* delete any on the processing queue */
   for (l = tmp_msgq; l; )
     {
	Edje_Message *em;
	Eina_List *lp;

	em = eina_list_data_get(l);
	lp = l;
	l = eina_list_next(l);
	if (em->edje == ed)
	  {
	     tmp_msgq = eina_list_remove_list(tmp_msgq, lp);
	     em->edje->message.num--;
	     _edje_message_free(em);
	  }
	if (ed->message.num <= 0) return;
     }
}