コード例 #1
0
/**
 * @brief Callback called from control thread.
 *
 * This function is a callback called from control thread to change some parameters of
 * compression.
 *
 * @param[in] receiver pointer to the compress module
 * @param[in] msg      message passed to callback
 * @returns            response to the message
 */
static struct response *compress_change_callback(struct module *receiver, struct message *msg)
{
    struct msg_change_compress_data *data =
        (struct msg_change_compress_data *) msg;
    compress_state_proxy *proxy = receiver->priv_data;

    /* In this case we are only changing some parameter of compression.
     * This means that we pass the parameter to compress driver. */
    if(data->what == CHANGE_PARAMS) {
        platform_spin_lock(&proxy->spin);
        struct response *resp = NULL;
        for(unsigned int i = 0; i < proxy->ptr->state_count; ++i) {
            if(resp) {
                resp->deleter(resp);
            }
            struct msg_change_compress_data *tmp_data =
                (struct msg_change_compress_data *)
                new_message(sizeof(struct msg_change_compress_data));
            tmp_data->what = data->what;
            strncpy(tmp_data->config_string, data->config_string,
                    sizeof(tmp_data->config_string) - 1);
            resp = send_message_to_receiver(proxy->ptr->state[i],
                                            (struct message *) tmp_data);
        }
        platform_spin_unlock(&proxy->spin);

        free_message(msg);

        return resp;
    } else {
        struct compress_state_real *new_state;
        char config[1024];
        strncpy(config, data->config_string, sizeof(config));

        int ret = compress_init_real(&proxy->mod, config, &new_state);
        if(ret == 0) {
            struct compress_state_real *old = proxy->ptr;
            platform_spin_lock(&proxy->spin);
            proxy->ptr = new_state;
            platform_spin_unlock(&proxy->spin);
            compress_done_real(old);

            return new_response(RESPONSE_OK, NULL);
        }

        return new_response(RESPONSE_INT_SERV_ERR, NULL);
    }
}
コード例 #2
0
ファイル: gearmand.c プロジェクト: pombredanne/gearwoman
void work_fail(Job *job)
{
    MemBlock *block = new_response(MSG_WORK_FAIL, strlen(job->handle), (unsigned char*)job->handle);
    incRef(block); // Make sure the first listener doesn't decRef to 0 causing the block to be returned
    g_ptr_array_foreach(job->listeners, (GFunc)client_send, block);
    decRef(block);
    remove_job(job);
}
コード例 #3
0
ファイル: client.c プロジェクト: cthulhuology/Jawas
void
write_request()
{
	if (send_request(client.request)) {
		add_req_socket(client.request->socket->fd);
		return;
	}
	client.response = new_response(client.request);
	add_resp_socket(client.response->socket->fd);
}
コード例 #4
0
HttpResponse::Ptr HttpResponse::clone()
{
    HttpResponse::Ptr new_response(new HttpResponse());

    new_response->m_protocol_and_version = m_protocol_and_version;
    new_response->m_status_code = m_status_code;
    new_response->m_reason_str = m_reason_str;
    new_response->m_header_fields_map = m_header_fields_map;
    new_response->m_headers = m_headers;
    new_response->m_header_body = m_header_body;
    new_response->m_is_valid = m_is_valid;

    return new_response;
}
コード例 #5
0
ファイル: client.c プロジェクト: cthulhuology/Jawas
void
read_request()
{
	if (process_request()) {
		retry_request();
		return;
	}
	client.request->retries = 0;
	if (!client.request->done) {
		add_read_socket(client.socket->fd);
		return;
	}
	client.socket->buf = NULL;
	client.response = new_response(client.request);
	parse_path(client.request);
	add_write_socket(client.response->socket->fd);
	return;
}
コード例 #6
0
ファイル: gearmand.c プロジェクト: pombredanne/gearwoman
/****************************************************************************
  Message Handler: grab_job() -> no_job(), job_assign(handle, func, arg)
 ****************************************************************************/
int msg_grab_job(Client *cli, unsigned char *arg, int argsize)
{
    Job *job = NULL;
    Ability *ability = NULL;
    int nabilities = cli->abilities->len;
    int i;
    for(i = 0; i < nabilities && !job; i++) {
        cli->ability_iter = (cli->ability_iter + 1) % nabilities;
        ability = g_ptr_array_index(cli->abilities, cli->ability_iter);
        job = jobqueue_pop(g_jobqueue, ability->func);
    }

    if (!job) {
        #if DEBUG
        g_debug("[%s] grab_job - no job", cli->id);
        #endif
        MemBlock *block = simple_response(MSG_NO_JOB);
        client_send(cli, block);
    } else {
        #if DEBUG
        g_debug("[%s] grab_job - assigned %s %s", cli->id, ability->func, job->handle);
        #endif

        job->worker = cli;
        client_add_working(cli, job);

        int data_len = strlen(job->handle) + strlen(job->func) + job->arg_len + 2;
        MemBlock *block = new_response(MSG_JOB_ASSIGN, data_len, NULL);
        unsigned char *p = block->bytes + HEADER_SIZE;
        p += sprintf((char*)p, job->handle) + 1;
        p += sprintf((char*)p, job->func) + 1;
        memcpy(p, job->arg, job->arg_len);
        client_send(cli, block);

        if (ability->timeout > 0) {
            struct timeval tv = {ability->timeout, 0};
            job->timeout = ability->timeout;
            evtimer_set(&job->work_timer, (void*)_work_timeout, job);
            evtimer_add(&job->work_timer, &tv);
        }
    }

    return 0;
}
コード例 #7
0
ファイル: gearmand.c プロジェクト: pombredanne/gearwoman
/****************************************************************************
  Message Handler: get_status(handle) -> status_res(handle, known, running, numerator, denominator)
 ****************************************************************************/
int msg_get_status(Client *cli, unsigned char *arg, int arg_len)
{
    char *handle = (char*)arg;
    if (arg_len > MAX_HANDLE_LEN) {
        g_warning("[%s] Invalid handle length received: %d", cli->id, arg_len);
        return -1;
    }

    #if DEBUG
    g_debug("[%s] get_status(%s)", cli->id, handle);
    #endif

    char *known = "0";
    char *running = "0";
    int numerator = -1;
    int denominator = -1;

    Job *job = g_hash_table_lookup(g_jobs, handle);
    if (job) {
        known = "1";
        if (job->worker)
            running = "1";
        numerator = job->status[0];
        denominator = job->status[1];
    }

    MemBlock *block = new_response(MSG_STATUS_RES, 256, NULL);
    char *p = (char*)block->bytes + HEADER_SIZE;
    p += sprintf(p, handle) + 1;
    p += sprintf(p, known) + 1;
    p += sprintf(p, running) + 1;
    if (numerator >= 0) {
        p += sprintf(p, "%d", numerator) + 1;
        p += sprintf(p, "%d", denominator);
    } else {
        *(p++) = 0;
    }
    block->nbytes = (unsigned char*)p - block->bytes;
    set_message_size(block, block->nbytes - HEADER_SIZE);
    client_send(cli, block);

    return 0;
}
コード例 #8
0
ファイル: jpeg.c プロジェクト: ua-i2cat/media-streamer
static struct response *compress_change_callback(struct module *mod, struct message *msg)
{
        struct state_video_compress_jpeg *s = (struct state_video_compress_jpeg *) mod->priv_data;

        static struct response *ret;

        struct msg_change_compress_data *data =
                (struct msg_change_compress_data *) msg;

        platform_spin_lock(&s->spin);
        parse_fmt(s, data->config_string);
        ret = new_response(RESPONSE_OK, NULL);
        memset(&s->saved_desc, 0, sizeof(s->saved_desc));
        platform_spin_unlock(&s->spin);

        free_message(msg);

        return ret;
}
コード例 #9
0
ファイル: decimate.c プロジェクト: nimanshr/antelope_contrib
int read_dec_files (Tbl *decdef, int *dec_fac, Tbl **decimators)

{
    int i, j, n;
    Response *rsp;
    char string[512];
    FILE *file;

    FIR_decimation *decptr;
    Response *resp;

    resp = (Response *) new_response ();

    if(*decimators == NULL) *decimators = newtbl(0);
    if (resp == NULL) {
        elog_die(0, "read_dec_files: Malloc error on decimation response structure.\n");
        return (0);
    }
    for (i=0,(*dec_fac)=1; i<maxtbl(decdef); i++) {
        int ok;
        char *decfile;
        decfile = gettbl(decdef,i);
        if(!strcmp(decfile,"none") )
        {
            *dec_fac = 1.0;
            decptr = (FIR_decimation *) malloc(sizeof(FIR_decimation));
            if(decptr == NULL)
            {
                elog_notify(0,"Cannot malloc decimation structure for stage %d\n",
                            i);
                return(0);
            }
            decptr->decfac = 1.0;
            decptr->ncoefs = 0;
            decptr->coefs=NULL;
            pushtbl(*decimators,decptr);
            return(2);
        }

        file = fopen(decfile, "r");
        if (file == NULL) {
            elog_notify(0, "read_dec_files: Unable to open response stage file '%s'.\n",
                        decfile);
            return (0);
        }
        if (read_response (file, &rsp)) {
            elog_clear_register(1);
            elog_notify(0, "read_dec_files: read_response() error on stage file '%s'.\n",
                        decfile);
            return (0);
        }
        fclose (file);
        get_response_nstages (rsp, &n);
        for (j=0,ok=0; j<n; j++) {
            int dec_factor, nnum, nden;
            double srate;

            get_response_stage_type (rsp, j, string);
            if (strcmp(string, "fir")) continue;
            get_response_stage_fir_ncoefs (rsp, j, &srate, &dec_factor, &nnum, &nden);
            if (nden > 1) {
                elog_notify(0, "read_dec_files: Dont know how to do IIR filters (%s).\n",
                            decfile);
                return (0);
            }
            if (nnum < 1) {
                elog_notify(0, "read_dec_files: No numerator terms (%s).\n",
                            decfile);
                return (0);
            }
            ok=1;
            (*dec_fac) *= dec_factor;
        }
        if (!ok) {
            elog_notify(0, "read_dec_files: no fir stage on file '%s'.\n",
                        decfile);
            return (0);
        }
        for (j=0; j<n; j++) {
            Response_group *gpi;

            get_response_stage_type (rsp, j, string);
            if (strcmp(string, "fir")) continue;
            gpi = rsp->groups + j;
            if (copy_response_group (gpi, (resp), -1) < 0) {
                elog_notify(0, "read_dec_files: copy_response_group() error.\n");
                return (0);
            }
        }
        free_response (rsp);
    }
    get_response_nstages ((resp), &n);

    for (i=0; i<n; i++) {
        Response_group *gpi;
        int dec_factor, nnum, nden;
        double srate;
        double *coefsi, *coefs_err;
        double *coefdi, *coefd_err;

        decptr = (FIR_decimation *) malloc(sizeof(FIR_decimation));
        if(decptr == NULL)
        {
            elog_notify(0,"Cannot malloc decimation structure for stage %d\n",
                        i);
            return(0);
        }

        gpi = (resp)->groups + i;
        get_response_stage_fir_ncoefs ((resp), i, &srate, &dec_factor, &nnum, &nden);
        get_response_stage_fir_coefs ((resp), i, &nnum, &coefsi, &coefs_err,
                                      &nden, &coefdi, &coefd_err);
        for (j=0; j<nnum/2; j++) if (coefsi[j] != coefsi[nnum-j-1]) break;
        if (j < nnum/2) {
            elog_notify(0, "read_dec_files: Can only do symetrical FIR filters.\n");
            return (0);
        }

        decptr->ncoefs = nnum;
        decptr->decfac = dec_factor;
        decptr->coefs = calloc(nnum,sizeof(float));
        if((decptr->coefs) == NULL)
            elog_die(0,"read_dec_files:  can't alloc filter coef array of length %d\n",nnum);
        for(j=0; j<nnum; j++) decptr->coefs[j] = coefsi[j];
        pushtbl(*decimators,decptr);
    }
    return (1);
}
コード例 #10
0
ファイル: gearmand.c プロジェクト: pombredanne/gearwoman
/****************************************************************************
  Message Handler: submit_job_*(func, uniq, arg)
 ****************************************************************************/
int msg_submit_job(Client *cli, unsigned char *arg, int argsize, gboolean background, gboolean high)
{
    unsigned char *args[3];
    int last_arg_len = parse_args(args, 3, arg, argsize);

    int is_uniq = args[1][0] != 0;

    const gchar *func = g_intern_string((char*)args[0]);
    // printf(">> [%s] = %.8x\n", args[0], func);

    /* look for a duplicate job - if one exists, add to listeners */
    if (is_uniq) {
        UniqJobKey uk;
        uk.func = func;
        if (args[1][0] == '-' && args[1][1] == 0) {
            uk.uniq = args[2];
            uk.uniq_len = last_arg_len;
        } else {
            uk.uniq = args[1];
            uk.uniq_len = strlen((char*)args[1]);
        }
        Job *job = g_hash_table_lookup(g_uniq_jobs, &uk);
        if (job) {
            #if DEBUG
            g_debug("[%s] submit_job - merging %s:%s -> %s", cli->id, job->func, job->uniq, job->handle);
            #endif
            if (!job->background) {
                g_ptr_array_add_uniq(job->listeners, cli);
                client_listen_to(cli, job);
            }
            MemBlock *block = new_response(MSG_JOB_CREATED, strlen(job->handle), (unsigned char *)job->handle);
            client_send(cli, block);
            return 0;
        }
    }

    Job *job = job_new();
    generate_job_handle(job->handle);
    job->func = func;
    if (last_arg_len == 0)
        job->arg = (unsigned char *)"";
    else {
        job->arg = malloc(last_arg_len);
        memcpy(job->arg, args[2], last_arg_len);
    }
    job->arg_len = last_arg_len;
    job->background = background;
    if (!background) {
        g_ptr_array_add(job->listeners, cli);
    }
    g_hash_table_insert(g_jobs, job->handle, job);

    #if DEBUG
    g_debug("[%s] submit_job: %s, %s -> %s", cli->id, args[0], args[1], job->handle);
    #endif

    jobqueue_push(g_jobqueue, job, high);
    if (!background) {
        client_listen_to(cli, job);
    }

    job->is_uniq = is_uniq;
    if (is_uniq) {
        job->uniq = strdup((char*)args[1]);
        job->uniq_key.func = func;
        if (job->uniq[0] == '-' && job->uniq[1] == 0) {
            job->uniq_key.uniq = job->arg;
            job->uniq_key.uniq_len = job->arg_len;
        } else {
            job->uniq_key.uniq = (unsigned char *)job->uniq;
            job->uniq_key.uniq_len = strlen(job->uniq);
        }
        g_hash_table_insert(g_uniq_jobs, &job->uniq_key, job);
        #if DEBUG
        g_debug("[%s] \tadded uniq job %s", cli->id, job->handle);
        #endif
    }

    MemBlock *block = new_response(MSG_JOB_CREATED, strlen(job->handle), (unsigned char *)job->handle);
    client_send(cli, block);
    wake_up_sleepers(job->func);

    return 0;
}