... | ... |
@@ -707,6 +707,57 @@ static const char *dlgs_rpc_stats_doc[2] = { |
707 | 707 |
*/ |
708 | 708 |
static void dlgs_rpc_stats(rpc_t *rpc, void *ctx) |
709 | 709 |
{ |
710 |
+ void *th; |
|
711 |
+ void *ti; |
|
712 |
+ dlgs_stats_t *sti; |
|
713 |
+ dlgs_stats_t sta; |
|
714 |
+ int i; |
|
715 |
+ |
|
716 |
+ if(_dlgs_htb == NULL) { |
|
717 |
+ return; |
|
718 |
+ } |
|
719 |
+ |
|
720 |
+ if (rpc->add(ctx, "{", &th) < 0) { |
|
721 |
+ rpc->fault(ctx, 500, "Internal error creating rpc"); |
|
722 |
+ return; |
|
723 |
+ } |
|
724 |
+ i = 0; |
|
725 |
+ do { |
|
726 |
+ if(i==0) { |
|
727 |
+ sti = &_dlgs_htb->fstats; |
|
728 |
+ if(rpc->struct_add(th, "{", "final", &ti)<0) { |
|
729 |
+ rpc->fault(ctx, 500, "Internal error creating final stats"); |
|
730 |
+ return; |
|
731 |
+ } |
|
732 |
+ } else { |
|
733 |
+ memset(&sta, 0, sizeof(dlgs_stats_t)); |
|
734 |
+ for(i=0; i<_dlgs_htb->htsize; i++) { |
|
735 |
+ sta.c_init += _dlgs_htb->slots[i].astats.c_init; |
|
736 |
+ sta.c_progress += _dlgs_htb->slots[i].astats.c_progress; |
|
737 |
+ sta.c_answered += _dlgs_htb->slots[i].astats.c_answered; |
|
738 |
+ sta.c_confirmed += _dlgs_htb->slots[i].astats.c_confirmed; |
|
739 |
+ sta.c_terminted += _dlgs_htb->slots[i].astats.c_terminted; |
|
740 |
+ sta.c_notanswered += _dlgs_htb->slots[i].astats.c_notanswered; |
|
741 |
+ } |
|
742 |
+ sti = &sta; |
|
743 |
+ if(rpc->struct_add(th, "{", "active", &ti)<0) { |
|
744 |
+ rpc->fault(ctx, 500, "Internal error creating final stats"); |
|
745 |
+ return; |
|
746 |
+ } |
|
747 |
+ i = 1; |
|
748 |
+ } |
|
749 |
+ if(rpc->struct_add(ti, "uuuuuu", |
|
750 |
+ "init", sti->c_init, |
|
751 |
+ "progress", sti->c_progress, |
|
752 |
+ "answered", sti->c_answered, |
|
753 |
+ "confirmed", sti->c_confirmed, |
|
754 |
+ "terminted", sti->c_terminted, |
|
755 |
+ "notanswered", sti->c_notanswered)<0) { |
|
756 |
+ rpc->fault(ctx, 500, "Internal error creating values"); |
|
757 |
+ return; |
|
758 |
+ } |
|
759 |
+ i++; |
|
760 |
+ } while(i<2); |
|
710 | 761 |
} |
711 | 762 |
|
712 | 763 |
static const char *dlgs_rpc_list_doc[2] = { |