예제 #1
0
int main(int argc, char *argv[])
{
    FTB_client_t cinfo;
    FTB_client_handle_t handle;
    FTB_event_handle_t ehandle;
    int ret = 0, i = 0;
    FTB_event_info_t event_info[1] = { {"SIMPLE_EVENT", "INFO"} };

    if (argc > 1) {
        if (strcasecmp(argv[1], "usage") == 0) {
            printf("./ftb_simple_publisher\n");
            exit(0);
        }
    }

    printf("Begin\n");
    /* Specify the client information and call FTB_Connect */
    memset(&cinfo, 0, sizeof(cinfo));
    strcpy(cinfo.event_space, "FTB.FTB_EXAMPLES.SIMPLE");
    strcpy(cinfo.client_subscription_style, "FTB_SUBSCRIPTION_NONE");

    ret = FTB_Connect(&cinfo, &handle);
    if (ret != FTB_SUCCESS) {
        printf("FTB_Connect did not return a success\n");
        exit(-1);
    }

    /*
     * Declare the events that this client wants to publispublishh. The events and
     * their severity are defined in the event_info structure
     */
    ret = FTB_Declare_publishable_events(handle, 0, event_info, 1);
    if (ret != FTB_SUCCESS) {
        printf("FTB_Declare_publishable_events failed ret=%d!\n", ret);
        exit(-1);
    }

    /* Publish 10 events */
    for (i = 0; i < 10; i++) {
        printf("Publish an event\n");
        /* Publish an event. There are no event properties for this event */
        ret = FTB_Publish(handle, "SIMPLE_EVENT", NULL, &ehandle);
        if (ret != FTB_SUCCESS) {
            printf("FTB_Publish did not return a success\n");
            exit(-1);
        }
        printf("Sleeping for 10 seconds\n");
        sleep(10);
    }
    /* Disconnect from FTB */
    printf("FTB_Disconnect\n");
    FTB_Disconnect(handle);

    printf("End\n");
    return 0;
}
예제 #2
0
파일: ftb_pingpong.c 프로젝트: besserox/ftb
/* This is the callback handler called by the server side */
int pingpong_server(FTB_receive_event_t * evt, void *arg)
{
    count++;
    FTB_event_handle_t ehandle;
    FTB_client_handle_t *handle = (FTB_client_handle_t *) arg;

    printf("pingpong_server callback handler received event (%d)\n", count);
    /*
     * Server publishes its event in response to the recived client event,
     * that trigerred this callback
     */
    FTB_Publish(*handle, "PINGPONG_EVENT_SRV", NULL, &ehandle);
    return 0;
}
예제 #3
0
파일: ftb.c 프로젝트: NexMirror/MPICH
void MPIDU_Ftb_publish(const char *event_name, const char *event_payload)
{
    FTB_event_properties_t event_prop;
    FTB_event_handle_t event_handle;
    MPIR_FUNC_VERBOSE_STATE_DECL(MPID_STATE_MPIDU_FTB_PUBLISH);

    MPIR_FUNC_VERBOSE_ENTER(MPID_STATE_MPIDU_FTB_PUBLISH);

    event_prop.event_type = 1;
    MPL_strncpy(event_prop.event_payload, event_payload, sizeof(event_prop.event_payload));
    
    CHECK_FTB_ERROR(FTB_Publish(client_handle, event_name, &event_prop, &event_handle));

    MPIR_FUNC_VERBOSE_EXIT(MPID_STATE_MPIDU_FTB_PUBLISH);
    return;
}
예제 #4
0
파일: ftb_pingpong.c 프로젝트: besserox/ftb
/* This is the callback handler called by the client side */
int pingpong_client(FTB_receive_event_t * evt, void *arg)
{
    FTB_event_handle_t ehandle;

    count++;
    printf("pingpong_client callback handler received event (%d)\n", count);
    if (count >= iter) {
        gettimeofday(&end, NULL);
        done = 1;
        return 0;
    }
    FTB_client_handle_t *handle = (FTB_client_handle_t *) arg;

    /*
     * Client publishes its events in response to the received server-side event,
     * which trigerred this callback
     */
    FTB_Publish(*handle, "PINGPONG_EVENT_CLI", NULL, &ehandle);
    return 0;
}
예제 #5
0
HYD_status HYDT_ftb_publish(const char *event_name, const char *event_payload)
{
    FTB_event_properties_t event_prop;
    FTB_event_handle_t event_handle;
    int ret;
    HYD_status status = HYD_SUCCESS;

    event_prop.event_type = 1;
    MPL_strncpy(event_prop.event_payload, event_payload, sizeof(event_prop.event_payload));

    ret = FTB_Publish(ch, event_name, &event_prop, &event_handle);
    if (ret)
        HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, "ftb publish\n");

  fn_exit:
    HYDU_FUNC_EXIT();
    return status;

  fn_fail:
    goto fn_exit;
}
예제 #6
0
파일: ftb_pingpong.c 프로젝트: besserox/ftb
int main(int argc, char *argv[])
{
    FTB_client_handle_t handle;
    FTB_client_t cinfo;
    FTB_subscribe_handle_t shandle;
    FTB_event_handle_t ehandle;
    double event_latency;
    int ret = 0;

    if (argc >= 2) {
        if (strcasecmp(argv[1], "server") == 0) {
            if (argc > 2) {
                fprintf(stderr, "Starting pingpong server. Ignoring additional arguments.\n");
            }
            else {
                fprintf(stderr, "Starting pingpong server\n");
                is_server = 1;
            }
        }
        else if (strcasecmp(argv[1], "client") == 0) {
            if (argc >= 3) {
                is_server = 0;
                int i = 0;
                for (i = 0; i < strlen(argv[2]); i++) {
                    if ((argv[2][i] >= '0') && (argv[2][i] <= '9'))
                        continue;
                    else {
                        printf("Pingpong iterations not a valid number\n");
                        exit(0);
                    }
                }
                iter = atoi(argv[2]);
                if (iter < 1) {
                    printf("Pingpong iterations cannot be less than 1\n");
                    exit(0);
                }
                if (argc > 3) {
                    fprintf(stderr,
                            "Starting pingpong client with iterations %d. Ignoring additional arguments\n",
                            iter);
                }
                else {
                    fprintf(stderr, "Starting pingpong client with iterations %d\n", iter);
                }
            }
            else if (argc < 3) {
                fprintf(stderr, "Number of iterations missing from the client pingpong program\n");
                exit(0);
            }
        }
        else {
            printf
                ("For pingpong server: ./ftb_pingpong server\nFor pingpong client: ./ftb_pingpong client <number of iterations>\n");
            exit(0);
        }
    }
    else {
        printf
            ("For pingpong server: ./ftb_pingpong server\nFor pingpong client: ./ftb_pingpong client <number of iterations>\n");
        exit(0);
    }

    /*
     * Specify the client properties and call FTB_Connect.
     * Note that the pingpong component will subscribe to events using the
     * notification subscription mechanism
     */
    memset(&cinfo, 0, sizeof(cinfo));
    strcpy(cinfo.event_space, "FTB.FTB_EXAMPLES.Pingpong");
    strcpy(cinfo.client_subscription_style, "FTB_SUBSCRIPTION_NOTIFY");
    ret = FTB_Connect(&cinfo, &handle);
    if (ret != FTB_SUCCESS) {
        printf("FTB_Connect is not successful ret=%d\n", ret);
        exit(-1);
    }

    /*
     * This component will publish two events, as defined in the event_info
     * structure below
     */
    FTB_event_info_t event_info[2] = { {"PINGPONG_EVENT_SRV", "INFO"}
    , {"PINGPONG_EVENT_CLI", "INFO"}
    };
    ret = FTB_Declare_publishable_events(handle, 0, event_info, 2);
    if (ret != FTB_SUCCESS) {
        printf("FTB_Declare_publishable_events failed ret=%d!\n", ret);
        exit(-1);
    }

    if (is_server) {
        /*
         * The pingong server subscribes for all event of name
         * PINGPONG_EVENT_CLI and calls the pingpong_server function to
         * handle these events
         */
        ret =
            FTB_Subscribe(&shandle, handle, "event_name=PINGPONG_EVENT_CLI", pingpong_server,
                          (void *) &handle);
        if (ret != FTB_SUCCESS) {
            printf("FTB_Subscribe failed!\n");
            exit(-1);
        }
        signal(SIGINT, Sig_handler);
        signal(SIGTERM, Sig_handler);
    }
    else {
        /*
         * The pingpong client subscribes to all events of event name
         * PINGPONG_EVENT_SRV and calls a function pingpong_client callback
         * function to handle these events
         */
        ret =
            FTB_Subscribe(&shandle, handle, "event_name=PINGPONG_EVENT_SRV", pingpong_client,
                          (void *) &handle);
        if (ret != FTB_SUCCESS) {
            printf("FTB_Subscribe failed!\n");
            exit(-1);
        }
        gettimeofday(&begin, NULL);
        /*
         * After subscription, the client throws the first PINGPONG_EVENT_CLI
         * event. Subsequent events will be thrown by the client and server
         * callback function
         */
        FTB_Publish(handle, "PINGPONG_EVENT_CLI", NULL, &ehandle);
    }

    while (!done) {
        sleep(1);
    }

    /* Calculate the latency at the client side */
    if (!is_server) {
        event_latency = (end.tv_sec - begin.tv_sec) * 1000000 + (end.tv_usec - begin.tv_usec);
        event_latency /= iter;
        printf("Latency: %.3f microseconds\n", event_latency);
    }

    FTB_Disconnect(handle);

    return 0;
}