Example #1
0
File: cs.c Project: Eltechs/wine
void wined3d_cs_destroy(struct wined3d_cs *cs)
{
    state_cleanup(&cs->state);
    HeapFree(GetProcessHeap(), 0, cs->fb.render_targets);
    HeapFree(GetProcessHeap(), 0, cs->data);
    HeapFree(GetProcessHeap(), 0, cs);
}
Example #2
0
void mainLoop()
{
    char status[1000];
    int a = 0;
    while (ros::ok()) {
        if (timeOut < timer.getTime() && state != STATE_IDLE ) state = STATE_TIMEOUT;
        if (state != STATE_IDLE) robot->moveHead();
        ros::spinOnce();
        if (positionUpdate && robot->poseSet == false) robot->injectPosition();
        usleep(30000);
        if (state!=lastState) {
            sprintf(status,"Charging service is %s",stateStr[state]);
            feedback.Progress = (int)robot->progress;
            feedback.Message = stateStr[state];
            if (server->isActive()) server->publishFeedback(feedback);
        }
        if (server->isActive()||undockingServer->isActive()||dockingServer->isActive()) {
            feedback.Message = stateStr[state];
            feedback.Progress = (int)robot->progress;
            if (robot->actionStuck()) feedback.Level = 1;
            else feedback.Level = 0;
        }
        if ((server->isPreemptRequested() || undockingServer->isPreemptRequested())|| dockingServer->isPreemptRequested()&& state != STATE_IDLE) {
            state = STATE_PREEMPTED;
            robot->halt();
            ros::spinOnce();
            if (server->isActive()||undockingServer->isActive()||dockingServer->isActive()) result.Message = "Current action preempted by external request.";
        }
        state_cleanup();
        lastState = state;
    }
}
Example #3
0
File: cs.c Project: Eltechs/wine
static void wined3d_cs_exec_reset_state(struct wined3d_cs *cs, const void *data)
{
    struct wined3d_adapter *adapter = cs->device->adapter;
    HRESULT hr;

    state_cleanup(&cs->state);
    memset(&cs->state, 0, sizeof(cs->state));
    if (FAILED(hr = state_init(&cs->state, &cs->fb, &adapter->gl_info, &adapter->d3d_info,
            WINED3D_STATE_NO_REF | WINED3D_STATE_INIT_DEFAULT)))
        ERR("Failed to initialize CS state, hr %#x.\n", hr);
}
Example #4
0
void
evaluator_offline(char *dir, int num_eval_inputs, int nchains,
                  ChainingType chainingType)
{
    /* Does the offline stage for the evaluator.
     * This includes receiving pre-exchanged garbled circuits,
     * performing the offline phase of OT-preprocessing, and
     * saving relevant information to disk.
     *
     * @param dir the directory to save information
     * @param num_eval_inputs the number of evaluator inputs
     * @param nchains the number of garbled circuits to be pre-exchanged
     * @param chainingType indicates whether we are using SIMD or standard chaining.
     *        WARNING: SIMD-style chaining is now deprecated.
     */
    int sockfd;
    struct state state;
    ChainedGarbledCircuit cgc;
    uint64_t start, end;
    
    state_init(&state);

    if ((sockfd = net_init_client(HOST, PORT)) == FAILURE) {
        perror("net_init_client");
        exit(EXIT_FAILURE);
    }

    start = current_time_();

    for (int i = 0; i < nchains; i++) {
        chained_gc_comm_recv(sockfd, &cgc, chainingType);
        saveChainedGC(&cgc, dir, false, chainingType);
        freeChainedGarbledCircuit(&cgc, false, chainingType);
    }

    /* pre-processing OT using random selection bits */
    if (num_eval_inputs > 0) {
        int *selections;
        block *evalLabels;
        char *fname;
        size_t size;

        selections = malloc(sizeof(int) * num_eval_inputs);

        size = strlen(dir) + strlen("/sel") + 1;
        fname = malloc(size);

        for (int i = 0; i < num_eval_inputs; ++i) {
            selections[i] = rand() % 2;
        }
        evalLabels = garble_allocate_blocks(num_eval_inputs);
        ot_np_recv(&state, sockfd, selections, num_eval_inputs, sizeof(block),
                   2, evalLabels, new_choice_reader, new_msg_writer);
        (void) snprintf(fname, size, "%s/%s", dir, "sel");
        saveOTSelections(fname, selections, num_eval_inputs);
        (void) snprintf(fname, size, "%s/%s", dir, "lbl");
        saveOTLabels(fname, evalLabels, num_eval_inputs, false);

        free(selections);
        free(evalLabels);
        free(fname);
    }

    end = current_time_();
    fprintf(stderr, "evaluator offline: %llu\n", (end - start));

    close(sockfd);
    state_cleanup(&state);
}
Example #5
0
void
evaluator_classic_2pc(const int *input, bool *output,
                      int num_garb_inputs, int num_eval_inputs,
                      uint64_t *tot_time)
{
    /* Does the "full" garbled circuit protocol, wherein there is no online phase.
     * The garbled circuit and all input labels are communicated during the 
     * online phase, although we do use OT-processing
     */

    int sockfd;
    int *selections = NULL;
    garble_circuit gc;
    OldInputMapping map;
    block *garb_labels = NULL, *eval_labels = NULL;
    block *labels, *output_map;
    uint64_t start, end, _start, _end;
    size_t tmp;

    gc.type = GARBLE_TYPE_STANDARD;

    if ((sockfd = net_init_client(HOST, PORT)) == FAILURE) {
        perror("net_init_client");
        exit(EXIT_FAILURE);
    }

    /* pre-process OT */
    if (num_eval_inputs > 0) {
        struct state state;
        state_init(&state);
        selections = calloc(num_eval_inputs, sizeof(int));
        eval_labels = garble_allocate_blocks(num_eval_inputs);
        for (int i = 0; i < num_eval_inputs; ++i) {
            selections[i] = rand() % 2;
        }
        ot_np_recv(&state, sockfd, selections, num_eval_inputs, sizeof(block),
                   2, eval_labels, new_choice_reader, new_msg_writer);
        state_cleanup(&state);
    }



    /* Start timing after pre-processing of OT as we only want to record online
     * time */
    start = current_time_();

    _start = current_time_();
    {
        tmp = g_bytes_received;
        gc_comm_recv(sockfd, &gc);
    }
    _end = current_time_();
    fprintf(stderr, "Receive GC: %llu\n", _end - _start);
    fprintf(stderr, "\tBytes: %lu\n", g_bytes_received - tmp);

    _start = current_time_();
    tmp = g_bytes_received;
    if (num_eval_inputs > 0) {
        block *recvLabels;
        for (int i = 0; i < num_eval_inputs; ++i) {
            selections[i] ^= input[i];
        }
        recvLabels = garble_allocate_blocks(2 * num_eval_inputs);
        net_send(sockfd, selections, sizeof(int) * num_eval_inputs, 0);
        net_recv(sockfd, recvLabels, sizeof(block) * 2 * num_eval_inputs, 0);
        for (int i = 0; i < num_eval_inputs; ++i) {
            eval_labels[i] = garble_xor(eval_labels[i],
                                        recvLabels[2 * i + input[i]]);
        }
        free(recvLabels);
        free(selections);
    }
    _end = current_time_();
    fprintf(stderr, "OT correction: %llu\n", _end - _start);
    fprintf(stderr, "\tBytes: %lu\n", g_bytes_received - tmp);

    _start = current_time_();
    tmp = g_bytes_received;
    if (num_garb_inputs > 0) {
        garb_labels = garble_allocate_blocks(num_garb_inputs);
        net_recv(sockfd, garb_labels, sizeof(block) * num_garb_inputs, 0);
    }
    _end = current_time_();
    fprintf(stderr, "Receive garbler labels: %llu\n", _end - _start);
    fprintf(stderr, "\tBytes: %lu\n", g_bytes_received - tmp);

    _start = current_time_();
    {
        tmp = g_bytes_received;
        output_map = garble_allocate_blocks(2 * gc.m);
        net_recv(sockfd, output_map, sizeof(block) * 2 * gc.m, 0);
    }
    _end = current_time_();
    fprintf(stderr, "Receive output map: %llu\n", _end - _start);
    fprintf(stderr, "\tBytes: %lu\n", g_bytes_received - tmp);

    _start = current_time_();
    tmp = g_bytes_received;
    {
        size_t size;
        char *buffer;

        net_recv(sockfd, &size, sizeof size, 0);
        buffer = malloc(size);
        net_recv(sockfd, buffer, size, 0);
        readBufferIntoInputMapping(&map, buffer);
        free(buffer);
    }
    _end = current_time_();
    fprintf(stderr, "Receive garbler labels: %llu\n", _end - _start);
    fprintf(stderr, "\tBytes: %lu\n", g_bytes_received - tmp);

    close(sockfd);
    
    /* Plug labels in correctly based on input_mapping */
    {
        labels = garble_allocate_blocks(gc.n);
        int garb_p = 0, eval_p = 0;
        for (int i = 0; i < map.size; i++) {
            if (map.inputter[i] == PERSON_GARBLER) {
                labels[map.wire_id[i]] = garb_labels[garb_p]; 
                garb_p++;
            } else if (map.inputter[i] == PERSON_EVALUATOR) {
                labels[map.wire_id[i]] = eval_labels[eval_p]; 
                eval_p++;
            }
        }
    }

    _start = current_time_();
    {
        bool *outputs = calloc(gc.m, sizeof(bool));
        garble_eval(&gc, labels, NULL, outputs);
        free(outputs);
    }
    _end = current_time_();
    fprintf(stderr, "Evaluate: %llu\n", _end - _start);

    garble_delete(&gc);
    deleteOldInputMapping(&map);
    free(output_map);
    free(eval_labels);
    free(garb_labels);
    free(labels);

    end = current_time_();
    *tot_time = end - start;
}
Example #6
0
int main (int argc, char **argv)
{
    state_t * self = (state_t*) calloc (1, sizeof (state_t));
    self->use_gui = 1;

    char *optstring = "hc:p:";
    int c;
    struct option long_opts[] = { 
        { "help", no_argument, 0, 'h' },
        { "chain", required_argument, 0, 'c' },
        { "plugin-path", required_argument, 0, 'p' },
        { "no-gui", no_argument, 0, 'u' },
        { 0, 0, 0, 0 }
    };

    while ((c = getopt_long (argc, argv, optstring, long_opts, 0)) >= 0)
    {
        switch (c) {
            case 'c':
                self->xml_fname = strdup (optarg);
                break;
            case 'u':
                self->use_gui = 0;
                break;
            case 'p':
                self->extra_plugin_path = strdup (optarg);
                break;
            case 'h':
            default:
                usage ();
                break;
        };
    }

    if (!self->use_gui && !self->xml_fname) usage();

    if (self->use_gui) {
        gtk_init (&argc, &argv);
    } else {
        g_type_init ();
    }

    if (!g_thread_supported()) {
        g_thread_init (NULL);
    }

    if (0 != state_setup (self)) {
        state_cleanup(self);
        return 1;
    }

    if (self->use_gui) {
        camview_gtk_quit_on_interrupt ();
        gtk_main ();
        state_cleanup (self);
    } else {
        // did everything start up correctly?
        CamUnit *faulty = cam_unit_chain_all_units_stream_init(self->chain);
        if (faulty) {
            int faulty_index = 0;
            for(GList *uiter = cam_unit_chain_get_units(self->chain);
                    uiter && uiter->data != faulty; uiter = uiter->next)
                faulty_index ++;

            fprintf(stderr, "Unit %d [%s] is not streaming, aborting...\n",
                    faulty_index, cam_unit_get_name (faulty));
            return -1;
        }

        GMainLoop *mainloop = g_main_loop_new (NULL, FALSE);
        camview_g_quit_on_interrupt (mainloop);
        g_main_loop_run (mainloop);
        g_main_loop_unref (mainloop);
        state_cleanup (self);
    }

    return 0;
}