diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-05-11 19:40:39 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-05-11 19:40:39 +0000 |
commit | 5882a0a99902e4555f78a05a3d68dc72f864437f (patch) | |
tree | c080e0c35c98a1548d7dd8c1f1df6c16ba93508a /src/arm | |
parent | f557d63b75c8b14922e4a308dfc486f7e4e9f6db (diff) | |
download | gnunet-5882a0a99902e4555f78a05a3d68dc72f864437f.tar.gz gnunet-5882a0a99902e4555f78a05a3d68dc72f864437f.zip |
die unstoppable multi api, die
Diffstat (limited to 'src/arm')
-rw-r--r-- | src/arm/arm_api.c | 167 |
1 files changed, 0 insertions, 167 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index cd4343dbd..45a38ea9b 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c | |||
@@ -706,171 +706,4 @@ GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h, | |||
706 | } | 706 | } |
707 | 707 | ||
708 | 708 | ||
709 | /** | ||
710 | * Function to call for each service. | ||
711 | * | ||
712 | * @param h handle to ARM | ||
713 | * @param service_name name of the service | ||
714 | * @param timeout how long to wait before failing for good | ||
715 | * @param cb callback to invoke when service is ready | ||
716 | * @param cb_cls closure for callback | ||
717 | */ | ||
718 | typedef void (*ServiceOperation) (struct GNUNET_ARM_Handle *h, | ||
719 | const char *service_name, | ||
720 | struct GNUNET_TIME_Relative timeout, | ||
721 | GNUNET_ARM_Callback cb, void *cb_cls); | ||
722 | |||
723 | |||
724 | /** | ||
725 | * Context for starting or stopping multiple services. | ||
726 | */ | ||
727 | struct MultiContext | ||
728 | { | ||
729 | /** | ||
730 | * NULL-terminated array of services to start or stop. | ||
731 | */ | ||
732 | char **services; | ||
733 | |||
734 | /** | ||
735 | * Our handle to ARM. | ||
736 | */ | ||
737 | struct GNUNET_ARM_Handle *h; | ||
738 | |||
739 | /** | ||
740 | * Identifies the operation (start or stop). | ||
741 | */ | ||
742 | ServiceOperation op; | ||
743 | |||
744 | /** | ||
745 | * Current position in "services". | ||
746 | */ | ||
747 | unsigned int pos; | ||
748 | }; | ||
749 | |||
750 | |||
751 | /** | ||
752 | * Run the operation for the next service in the multi-service | ||
753 | * request. | ||
754 | * | ||
755 | * @param cls the "struct MultiContext" that is being processed | ||
756 | * @param success status of the previous operation (ignored) | ||
757 | */ | ||
758 | static void | ||
759 | next_operation (void *cls, | ||
760 | int success) | ||
761 | { | ||
762 | struct MultiContext *mc = cls; | ||
763 | char *pos; | ||
764 | |||
765 | if (NULL == (pos = mc->services[mc->pos])) | ||
766 | { | ||
767 | GNUNET_free (mc->services); | ||
768 | GNUNET_ARM_disconnect (mc->h); | ||
769 | GNUNET_free (mc); | ||
770 | return; | ||
771 | } | ||
772 | mc->pos++; | ||
773 | mc->op (mc->h, pos, MULTI_TIMEOUT, &next_operation, mc); | ||
774 | GNUNET_free (pos); | ||
775 | } | ||
776 | |||
777 | |||
778 | /** | ||
779 | * Run a multi-service request. | ||
780 | * | ||
781 | * @param cfg configuration to use (needed to contact ARM; | ||
782 | * the ARM service may internally use a different | ||
783 | * configuration to determine how to start the service). | ||
784 | * @param sched scheduler to use | ||
785 | * @param op the operation to perform for each service | ||
786 | * @param va NULL-terminated list of services | ||
787 | */ | ||
788 | static void | ||
789 | run_multi_request (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
790 | struct GNUNET_SCHEDULER_Handle *sched, | ||
791 | ServiceOperation op, | ||
792 | va_list va) | ||
793 | { | ||
794 | va_list cp; | ||
795 | unsigned int total; | ||
796 | struct MultiContext *mc; | ||
797 | struct GNUNET_ARM_Handle *h; | ||
798 | const char *c; | ||
799 | |||
800 | h = GNUNET_ARM_connect (cfg, sched, NULL); | ||
801 | if (NULL == h) | ||
802 | { | ||
803 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
804 | _("Error while trying to transmit to ARM service\n")); | ||
805 | return; | ||
806 | } | ||
807 | total = 1; | ||
808 | va_copy (cp, va); | ||
809 | while (NULL != (va_arg (cp, const char*))) total++; | ||
810 | va_end (cp); | ||
811 | mc = GNUNET_malloc (sizeof(struct MultiContext)); | ||
812 | mc->services = GNUNET_malloc (total * sizeof (char*)); | ||
813 | mc->h = h; | ||
814 | mc->op = op; | ||
815 | total = 0; | ||
816 | va_copy (cp, va); | ||
817 | while (NULL != (c = va_arg (cp, const char*))) | ||
818 | mc->services[total++] = GNUNET_strdup (c); | ||
819 | va_end (cp); | ||
820 | next_operation (mc, GNUNET_YES); | ||
821 | } | ||
822 | |||
823 | |||
824 | /** | ||
825 | * Start multiple services in the specified order. Convenience | ||
826 | * function. Works asynchronously, failures are not reported. | ||
827 | * | ||
828 | * @param cfg configuration to use (needed to contact ARM; | ||
829 | * the ARM service may internally use a different | ||
830 | * configuration to determine how to start the service). | ||
831 | * @param sched scheduler to use | ||
832 | * @param ... NULL-terminated list of service names (const char*) | ||
833 | */ | ||
834 | void | ||
835 | GNUNET_ARM_start_services (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
836 | struct GNUNET_SCHEDULER_Handle *sched, | ||
837 | ...) | ||
838 | { | ||
839 | va_list ap; | ||
840 | |||
841 | va_start (ap, sched); | ||
842 | run_multi_request (cfg, sched, &GNUNET_ARM_start_service, ap); | ||
843 | va_end (ap); | ||
844 | } | ||
845 | |||
846 | |||
847 | /** | ||
848 | * Stop multiple services in the specified order. Convenience | ||
849 | * function. Works asynchronously, failures are not reported. | ||
850 | * Should normally only be called from gnunet-arm or testcases, | ||
851 | * stopping a service is generally otherwise a bad idea. | ||
852 | * | ||
853 | * @param cfg configuration to use (needed to contact ARM; | ||
854 | * the ARM service may internally use a different | ||
855 | * configuration to determine how to start the service). | ||
856 | * @param sched scheduler to use | ||
857 | * @param ... NULL-terminated list of service names (const char*) | ||
858 | */ | ||
859 | void | ||
860 | GNUNET_ARM_stop_services (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
861 | struct GNUNET_SCHEDULER_Handle *sched, | ||
862 | ...) | ||
863 | { | ||
864 | va_list ap; | ||
865 | |||
866 | va_start (ap, sched); | ||
867 | run_multi_request (cfg, sched, &GNUNET_ARM_stop_service, ap); | ||
868 | va_end (ap); | ||
869 | } | ||
870 | |||
871 | |||
872 | |||
873 | |||
874 | |||
875 | |||
876 | /* end of arm_api.c */ | 709 | /* end of arm_api.c */ |