Пример #1
0
void timecoder_init(struct timecoder *tc, struct timecode_def *def,
                    double speed, unsigned int sample_rate)
{
    assert(def != NULL);

    /* A definition contains a lookup table which can be shared
     * across multiple timecoders */

    assert(def->lookup);
    tc->def = def;
    tc->speed = speed;

    tc->dt = 1.0 / sample_rate;
    tc->zero_alpha = tc->dt / (ZERO_RC + tc->dt);

    tc->forwards = 1;
    init_channel(&tc->primary);
    init_channel(&tc->secondary);
    pitch_init(&tc->pitch, tc->dt);

    tc->ref_level = 32768.0;
    tc->bitstream = 0;
    tc->timecode = 0;
    tc->valid_counter = 0;
    tc->timecode_ticker = 0;

    tc->mon = NULL;
}
Пример #2
0
int timecoder_init(struct timecoder_t *tc, const char *def_name,
		   unsigned int sample_rate)
{
    /* A definition contains a lookup table which can be shared
     * across multiple timecoders */

    tc->def = find_definition(def_name);
    if (tc->def == NULL) {
        fprintf(stderr, "Timecode definition '%s' is not known.\n", def_name);
        return -1;
    }
    if (build_lookup(tc->def) == -1)
        return -1;

    tc->dt = 1.0 / sample_rate;
    tc->zero_alpha = tc->dt / (ZERO_RC + tc->dt);

    tc->forwards = 1;
    init_channel(&tc->primary);
    init_channel(&tc->secondary);
    pitch_init(&tc->pitch, tc->dt);

    tc->ref_level = 32768.0;
    tc->bitstream = 0;
    tc->timecode = 0;
    tc->valid_counter = 0;
    tc->timecode_ticker = 0;

    tc->mon = NULL;

    return 0;
}
Пример #3
0
int main(int argc, char **argv)
{
  struct thread_arg arg_grabber = { NULL, &ch_g2p }, arg_preprocessor = { &ch_g2p, &ch_p2c }, arg_compressor = { &ch_p2c, &ch_c2s }, arg_server = { &ch_c2s, NULL };
  pthread_t grabber_thread, preprocessor_thread, compressor_thread, server_thread;
  struct timeval tv;
  
  // Set up inter-thread communications "channels"
  // Compressor to Server makes the assumption that a JPEG compressed image will never be bigger than the source bitmap
  ch_g2p = init_channel(SETUP_BUFFER_LENGTH_G2P, \
			(SETUP_STREAMS & SETUP_STREAM_RGB) ? SETUP_IMAGE_SIZE_RAW_RGB : 0, \
			(SETUP_STREAMS & SETUP_STREAM_IR) ? SETUP_IMAGE_SIZE_RAW_IR : 0);     // Grabber      to Preprocessor

  ch_p2c = init_channel(SETUP_BUFFER_LENGTH_P2C, \
			(SETUP_STREAMS & SETUP_STREAM_RGB) ? SETUP_IMAGE_SIZE_RGB : 0, \
			(SETUP_STREAMS & SETUP_STREAM_IR) ? SETUP_IMAGE_SIZE_IR : 0);         // Preprocessor to Compressor

  ch_c2s = init_channel(SETUP_BUFFER_LENGTH_C2S, \
			(SETUP_STREAMS & SETUP_STREAM_RGB) ? SETUP_IMAGE_SIZE_RGB : 0, \
			(SETUP_STREAMS & SETUP_STREAM_IR) ? SETUP_IMAGE_SIZE_IR : 0);         // Compressor   to Server
  
  // Start the "subsystems"
  pthread_create(&grabber_thread, NULL, &grabber, &arg_grabber);
  pthread_create(&preprocessor_thread, NULL, &preprocessor, &arg_preprocessor);
  pthread_create(&compressor_thread, NULL, &compressor, &arg_compressor);
  pthread_create(&server_thread, NULL, &server, &arg_server);
  
  // Do nothing; use select(2) here because sleep/usleep etc. rely on SIGALRM (as we do, see above)
  while(1) {
    tv.tv_sec = 10;
    tv.tv_usec = 0;
    select(0, NULL, NULL, NULL, &tv);
  }
  
  return 0;
}
Пример #4
0
int main(int argc, char **argv)
{
    initialize(70*RING_SIZE+24);

    // get the starting time
    t0 = Now();

    //  initialize the channels
    int i;
    for (i = 0; i < RING_SIZE; i++) {
        init_channel(&channel[i]);
    }

    // connect the elements of the ring
    Element element[RING_SIZE];  
    Channel *left, *right;
    for (i = 0, left = &channel[0]; i < RING_SIZE-1; i++) {
        right = &channel[(i + 1) % RING_SIZE];
        element[i].input = in(left);
        element[i].output = out(right);
        element[i].start = false;
        left = right;
    }
    element[i].input = in(left);    
    element[i].output = out(&channel[0]);    
    element[i].start = true;

    // start the elements of the ring
    for (i = 0; i < RING_SIZE; i++) {
        START(Element, &element[i], 1);
    }

    run();
}
Пример #5
0
int main(int argc, char **argv)
{
    printf("ring1arg-mp: send token around a ring (1 process arg)\n");
    printf("with processes on alternating processors\n");
    initialize(0x40000000, 8192);    // 1 GB total allocatable memory

    // initialize the channels
    int i;
    for (i = 0; i < RING_SIZE; i++) {
        init_channel(&chan[i]);
    }

    code_p children[RING_SIZE];
    uint stacksize[RING_SIZE];
    void *args[RING_SIZE];
    uint place[RING_SIZE];
    for (i = 0; i < RING_SIZE; i++) {
        children[i] = child;
        args[i] = (void *)i;
        stacksize[i] = 3000;
        place[i] = i % 2; 
    }

    placed_par(children, args, stacksize, place, RING_SIZE);
    printf("After par\n");

    return 0;
}
Пример #6
0
int main(int argc, char **argv)
{
    printf("ring1arg: pass token around ring (1 process arg)\n");
    initialize(0x40000000, 8192);    // 1 GB total allocatable memory

    // initialize the channels
    int i;
    for (i = 0; i < RING_SIZE; i++) {
        init_channel(&chan[i]);
    }

    code_p children[RING_SIZE];
    uint stacksize[RING_SIZE];
    void *args[RING_SIZE];
    for (i = 0; i < RING_SIZE; i++) {
        children[i] = child;
        args[i] = (void *)i;
        stacksize[i] = 2000;
    }

    par(children, args, stacksize, RING_SIZE);
    printf("After par\n");

    return 0;
}
Пример #7
0
static void
cyg_hal_plf_serial_init(void)
{
    hal_virtual_comm_table_t* comm;
    int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
    int i;

    // Init channels
#define NUMOF(x) (sizeof(x)/sizeof(x[0]))
    for (i = 0;  i < NUMOF(ser_channels);  i++) {
        init_channel(&ser_channels[i]);
        CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
        comm = CYGACC_CALL_IF_CONSOLE_PROCS();
        CYGACC_COMM_IF_CH_DATA_SET(*comm, &ser_channels[i]);
        CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
        CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
        CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
        CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
        CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
        CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
        CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
    }
     
    // Restore original console
    CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
}
Пример #8
0
struct ssh_channel *
make_server_session(UINT32 initial_window,
		    struct alist *request_types)
{
  NEW(server_session, self);

  init_channel(&self->super);

  self->initial_window = initial_window;

  /* We don't want to receive any data before we have forked some
   * process to receive it. */
  self->super.rec_window_size = 0;

  /* FIXME: Make maximum packet size configurable. */
  self->super.rec_max_packet = SSH_MAX_PACKET - SSH_CHANNEL_MAX_PACKET_FUZZ;
  self->super.request_types = request_types;

  /* Note: We don't need a close handler; the channels resource list
   * is taken care of automatically. */
  
  self->process = NULL;
  
  self->in = NULL;
  self->out = NULL;
  self->err = NULL;
  
  return &self->super;
}
Пример #9
0
static int init_network(lua_State *L, struct event_base *ev_base)
{
    const char *char_name = config_optstring(L, "char_name", NULL);
    if (!char_name)
        ERR_EXIT("config error : not found char name\n");
    if (init_channel(L) == -1)
        ERR_EXIT("init client failed\n");

    const char *srv_addr = config_optstring(L, char_name, NULL);
    if (srv_addr) {
        char ip[MAX_IP_LEN];
        int port;
        if (parse_addr(srv_addr, ip, &port) != 0)
            ERR_EXIT("server addr error\n");
        int fd = start_tcp_listen(ip, port);
        if (fd == -1)
            ERR_EXIT("start server failed : %s\n", strerror(errno));
       struct event *lsn_ev = event_new(ev_base, fd, EV_READ | EV_PERSIST, new_client, ev_base);
        event_add(lsn_ev, NULL);
    }

    const char *remote_svrs = config_optstring(L, "remote_servers", NULL);
    lua_newtable(L);
    lua_pushvalue(L, -1);
    lua_setglobal(L, "remote_servers");
    if (remote_svrs) {
        size_t sz = strlen(remote_svrs);
        char tmp[sz+1];
        strcpy(tmp, remote_svrs);
        char *p = strtok(tmp, ";");
        while (p) {
            const char *rsvr_addr = config_optstring(L, p, NULL);
            if (!rsvr_addr)
                ERR_EXIT("remote server %s addr not found\n", p);
            char ip[MAX_IP_LEN];
            int port;
            if (parse_addr(rsvr_addr, ip, &port) != 0)
                ERR_EXIT("remote server %s addr  error\n", p);
            int fd = connect_tcp_server(ip, port);
            if (fd == -1)
                ERR_EXIT("connect to remote server %s failed : %s\n", p, strerror(errno));
            int id = alloc_server();
            if (id == -1)
                ERR_EXIT("remote server is full\n");
            strcpy(AllChannels[id]._peer_ip, ip);
            lua_pushnumber(L, id);
            lua_setfield(L, -2, p);

            evutil_make_socket_nonblocking(fd);
            AllChannels[id]._bev = bufferevent_socket_new(ev_base, fd, BEV_OPT_CLOSE_ON_FREE);
            bufferevent_setcb(AllChannels[id]._bev, readcb, NULL, errorcb, (void *)(intptr_t)id);
            bufferevent_enable(AllChannels[id]._bev, EV_READ|EV_WRITE);

            p = strtok(NULL, ";");
        }
    }
    lua_pop(L, 1);
    return 0;
}
Пример #10
0
int main(int argc, char **argv)
{
    printf("ring0arg2: two process ping pong, no process args\n");
    initialize(0x40000000, 8192);    // 1 GB total allocatable memory

    init_channel(&chan1);
    init_channel(&chan2);

    code_p children[] = { child1, child2 };
    void *args[] = { NULL, NULL };
    uint stacksize[] = { 2000, 2000 };

    par(children, args, stacksize, 2);
    printf("After par\n");

    return 0;
}
Пример #11
0
int main(int argc, char **argv)
{
    printf("alttime: alternation alternately receives and times out\n");
    printf("with producer and consumer on different processors\n");
    initialize(0x40000000, 8192);    // 1 GB total allocatable memory

    init_channel(&chan1);
    init_channel(&chan2);

    code_p children[] = { child1, child2 };
    void *args[] = { NULL, NULL };
    uint stacksize[] = { 2000, 2000 };
    uint place[] = { 0, 1 };

    placed_par(children, args, stacksize, place, 2);
    printf("After par\n");

    return 0;
}
Пример #12
0
static int
cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
{
    static int irq_state = 0;
    channel_data_t* chan = (channel_data_t*)__ch_data;
    int ret = -1;
    cyg_uint8 ier;
	va_list ap;

    CYGARC_HAL_SAVE_GP();
    va_start(ap, __func);

    switch (__func) {
    case __COMMCTL_GETBAUD:
        ret = chan->baud_rate;
        break;
    case __COMMCTL_SETBAUD:
        chan->baud_rate = va_arg(ap, cyg_int32);
        // Should we verify this value here?
        init_channel(chan);
        ret = 0;
        break;
    case __COMMCTL_IRQ_ENABLE:
        HAL_INTERRUPT_UNMASK(chan->isr_vector);
        HAL_INTERRUPT_SET_LEVEL(chan->isr_vector, 1);
        HAL_READ_UINT8(chan->base+PXA2X0_UART_IER, ier);
        ier |= PXA2X0_UART_IER_RAVIE;
        HAL_WRITE_UINT8(chan->base+PXA2X0_UART_IER, ier);
        irq_state = 1;
        break;
    case __COMMCTL_IRQ_DISABLE:
        ret = irq_state;
        irq_state = 0;
        HAL_INTERRUPT_MASK(chan->isr_vector);
        HAL_READ_UINT8(chan->base+PXA2X0_UART_IER, ier);
        ier &= ~PXA2X0_UART_IER_RAVIE;
        HAL_WRITE_UINT8(chan->base+PXA2X0_UART_IER, ier);
        break;
    case __COMMCTL_DBG_ISR_VECTOR:
        ret = chan->isr_vector;
        break;
    case __COMMCTL_SET_TIMEOUT:
        ret = chan->msec_timeout;
        chan->msec_timeout = va_arg(ap, cyg_uint32);
        break;
    default:
        break;
    }
    va_end(ap);
    CYGARC_HAL_RESTORE_GP();
    return ret;
}
Пример #13
0
int main(int argc, char **argv) {
    int listenfd, connfd;
    socklen_t clientlen = sizeof(struct sockaddr_in);
    struct sockaddr_in clientaddr;
    user* u;

    /* Init node and set port accoriding to configue file */
    init_node(argc, argv);

    /* Init the linked list of channel and the table of user */
    init_channel();
    init_user();
    
    /* Init server socket and set it as unblocked */
    listenfd = init_unblocking_server_socket(curr_node_config_entry->irc_port);

    /* connect to local daemon */
    local_client_fd = socket_connect(curr_node_config_entry->ipaddr,curr_node_config_entry->local_port);

    /* Init struct pool */
    init_pool();

    add_listen_fd(listenfd);

    while (1) {
        /* Wait for listening/connected descriptor(s) to become ready */
        p.ready_set = p.read_set;
        p.nready = Select(p.maxfd+1, &p.ready_set, NULL, NULL, NULL);

        /* If listening descriptor ready, add new client to pool */
        if (FD_ISSET(listenfd, &p.ready_set)) {
            connfd = Accept(listenfd, (SA *)&clientaddr, &clientlen);

            /* create a user struct for the connect fd */
            u = (user*) Calloc(1,sizeof(user));
            user_table[connfd] = u;

            /*set server_name and host_name for user */
            u->host_name = strdup(Gethostbyaddr((const char*)&clientaddr.sin_addr,sizeof(clientaddr.sin_addr),AF_INET)->h_name);
            u->server_name = strdup(Gethostbyname("localhost")->h_name);

            add_client(connfd);
        }

        /* Echo a text line from each ready connected descriptor */
        check_clients();
    }
}
Пример #14
0
// python function init_channel(int channel, int subcycle_time_us)
static PyObject*
py_init_channel(PyObject *self, PyObject *args)
{
    int channel, subcycle_time_us=-1;

    if (!PyArg_ParseTuple(args, "i|i", &channel, &subcycle_time_us))
        return NULL;

    if (subcycle_time_us == -1)
        subcycle_time_us = SUBCYCLE_TIME_US_DEFAULT;

    if (init_channel(channel, subcycle_time_us) == EXIT_FAILURE)
        return raise_error();

    Py_INCREF(Py_None);
    return Py_None;
}
Пример #15
0
int main(int argc, char **argv)
{
    printf("commun-mp: simple send/receive,\n");
    printf("sender and receiver on different processors\n");
    initialize(0x40000000, 8192);    // 1 GB total allocatable memory

    Channel chan;
    init_channel(&chan);

    code_p children[] = { child1, child2 };
    void *args[] = { &chan, &chan };
    uint stacksize[] = { 2000, 2000 };
    uint place[] = { 1, 0 };

    placed_par(children, args, stacksize, place, 2);
    printf("After par\n");

    return 0;
}
Пример #16
0
/* Clear out channel data from memory.
 */
static void clear_channel(struct chanset_t *chan, int reset)
{
  memberlist *m, *m1;

  if (chan->channel.topic)
    free(chan->channel.topic);
  for (m = chan->channel.member; m; m = m1) {
    m1 = m->next;
    free(m);
  }

  clear_masklist(chan->channel.ban);
  chan->channel.ban = NULL;
  clear_masklist(chan->channel.exempt);
  chan->channel.exempt = NULL;
  clear_masklist(chan->channel.invite);
  chan->channel.invite = NULL;

  if (reset)
    init_channel(chan, 1);
}
Пример #17
0
/* NOTE: Adds the socket to the channel's resource list */
void
init_channel_forward(struct channel_forward *self,
		     struct lsh_fd *socket, UINT32 initial_window)
{
  assert(socket);
  
  init_channel(&self->super);

  /* The rest of the callbacks are not set up until tcpip_start_io. */

  /* NOTE: We don't need a close handler, as the channel's resource
   * list is taken care of automatically. */
  
  self->super.rec_window_size = initial_window;

  /* FIXME: Make maximum packet size configurable. */
  self->super.rec_max_packet = SSH_MAX_PACKET - SSH_CHANNEL_MAX_PACKET_FUZZ;
  
  self->socket = socket;

  REMEMBER_RESOURCE(self->super.resources, &socket->super);
}
Пример #18
0
/* Create new channel and parse commands.
 */
static int tcl_channel_add(Tcl_Interp *irp, char *newname, char *options)
{
  struct chanset_t *chan;
  int items;
  int ret = TCL_OK;
  int join = 0;
  char **item;
  char buf[2048], buf2[256];

  if (!newname || !newname[0] || (strchr(CHANMETA, newname[0]) == NULL)) {
    if (irp)
      Tcl_AppendResult(irp, "invalid channel prefix", NULL);
    return TCL_ERROR;
  }

  if (strchr(newname, ',') != NULL) {
    if (irp)
      Tcl_AppendResult(irp, "invalid channel name", NULL);
     return TCL_ERROR;
   }

  convert_element(glob_chanmode, buf2);
  simple_sprintf(buf, "chanmode %s ", buf2);
  strlcat(buf, glob_chanset, sizeof buf);
  strlcat(buf, options, sizeof buf);

  if (Tcl_SplitList(NULL, buf, &items, &item) != TCL_OK)
    return TCL_ERROR;
  if ((chan = findchan_by_dname(newname))) {
    /* Already existing channel, maybe a reload of the channel file */
    chan->status &= ~CHAN_FLAGGED;	/* don't delete me! :) */
  } else {
    chan = calloc(1, sizeof(struct chanset_t));
    chan->limit_prot = 0;
    chan->limit = 0;

    chan->ban_time = global_ban_time;
    chan->exempt_time = global_exempt_time;
    chan->invite_time = global_invite_time;
    chan->aop_min = global_aop_min;
    chan->aop_max = global_aop_max;

    /* We _only_ put the dname (display name) in here so as not to confuse
     * any code later on. chan->name gets updated with the channel name as
     * the server knows it, when we join the channel. <cybah>
     */
    strlcpy(chan->dname, newname, sizeof chan->dname);

    /* Initialize chan->channel info */
    init_channel(chan, 0);
    list_append((struct list_type **) &chanset, (struct list_type *) chan);
    join = 1;
  }
  if (setstatic)
    chan->status |= CHAN_STATIC;
  /* If chan_hack is set, we're loading the userfile. Ignore errors while
   * reading userfile and just return TCL_OK. This is for compatability
   * if a user goes back to an eggdrop that no-longer supports certain
   * (channel) options.
   */
  if ((tcl_channel_modify(irp, chan, items, item) != TCL_OK) && !chan_hack) {
    ret = TCL_ERROR;
  }
  Tcl_Free((char *) item);
  if (join && !channel_inactive(chan) && module_find("irc", 0, 0))
    dprintf(DP_SERVER, "JOIN %s %s\n", chan->dname, chan->key_prot);
  return ret;
}
Пример #19
0
Файл: main.c Проект: caomw/grass
static void read_png(void)
{
    unsigned char sig_buf[8];
    png_bytep png_buffer;
    png_bytep *png_rows;
    int linesize;
    struct Cell_head cellhd;
    unsigned int y, c;
    png_color_8p sig_bit;
    int sbit, interlace;
    FILE *ifp;

    /* initialize input stream and PNG library */

    ifp = fopen(input, "rb");
    if (!ifp)
	G_fatal_error(_("Unable to open PNG file '%s'"), input);

    if (fread(sig_buf, sizeof(sig_buf), 1, ifp) != 1)
	G_fatal_error(_("Input file empty or too short"));

    if (png_sig_cmp(sig_buf, 0, sizeof(sig_buf)) != 0)
	G_fatal_error(_("Input file not a PNG file"));

    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    if (!png_ptr)
	G_fatal_error(_("Unable to allocate PNG structure"));

    info_ptr = png_create_info_struct(png_ptr);
    if (!info_ptr)
	G_fatal_error(_("Unable to allocate PNG structure"));

    if (setjmp(png_jmpbuf(png_ptr)))
	G_fatal_error(_("PNG error"));

    png_init_io(png_ptr, ifp);
    png_set_sig_bytes(png_ptr, sizeof(sig_buf));

    png_read_info(png_ptr, info_ptr);

    png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
		 &color_type, &interlace_type, &compression_type, &filter_type);

    if (Header || G_verbose() == G_verbose_max())
	print_header();

    if (Header)
    {
	fclose(ifp);    
	exit(0);
    }

    /* read image parameters and set up data conversions */

    if (png_get_bit_depth(png_ptr, info_ptr) < 8)
	png_set_packing(png_ptr);

    sbit = png_get_sBIT(png_ptr, info_ptr, &sig_bit);
    if (sbit)
        png_set_shift(png_ptr, sig_bit);

    if (!png_get_gAMA(png_ptr, info_ptr, &f_gamma))
	f_gamma = 0.0;

    if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
	png_set_tRNS_to_alpha(png_ptr);

    if (Float && color_type == PNG_COLOR_TYPE_PALETTE)
        png_set_palette_to_rgb(png_ptr);

    png_read_update_info(png_ptr, info_ptr);

    interlace = (interlace_type != PNG_INTERLACE_NONE);

    ialpha = (int) (alpha * channels[C_A].maxval);

    t_gamma = (f_gamma != 0.0 && d_gamma != 0.0)
	? f_gamma * d_gamma
	: 1.0;

    /* allocate input buffer */

    linesize = png_get_rowbytes(png_ptr, info_ptr);

    png_buffer = G_malloc(interlace
			  ? height * linesize
			  : linesize);

    if (interlace)
    {
	png_rows = G_malloc(height * sizeof(png_bytep));
	for (y = 0; y < height; y++)
	    png_rows[y] = png_buffer + y * linesize;
    }

    /* initialize cell header */

    Rast_get_window(&cellhd);

    cellhd.rows = height;
    cellhd.cols = width;
    cellhd.north = cellhd.rows;
    cellhd.south = 0.0;
    cellhd.east = cellhd.cols;
    cellhd.west = 0.0;
    cellhd.ns_res = 1;
    cellhd.ew_res = 1;

    Rast_set_window(&cellhd);

    /* initialize channel information */

    switch (color_type)
    {
    case PNG_COLOR_TYPE_GRAY:
	init_channel(&channels[C_Y]);
	break;

    case PNG_COLOR_TYPE_GRAY_ALPHA:
	init_channel(&channels[C_Y]);
	init_channel(&channels[C_A]);
	break;

    case PNG_COLOR_TYPE_PALETTE:
	init_channel(&channels[C_P]);
	break;

    case PNG_COLOR_TYPE_RGB:
	init_channel(&channels[C_R]);
	init_channel(&channels[C_G]);
	init_channel(&channels[C_B]);
	break;

    case PNG_COLOR_TYPE_RGB_ALPHA:
	init_channel(&channels[C_R]);
	init_channel(&channels[C_G]);
	init_channel(&channels[C_B]);
	init_channel(&channels[C_A]);
	break;
    }

    if (sbit)
    {
	channels[C_R].maxval = (1 << sig_bit->red  ) - 1;
	channels[C_G].maxval = (1 << sig_bit->green) - 1;
	channels[C_B].maxval = (1 << sig_bit->blue ) - 1;
	channels[C_Y].maxval = (1 << sig_bit->gray ) - 1;
	channels[C_A].maxval = (1 << sig_bit->alpha) - 1;
    }
    else
    {
	channels[C_R].maxval = (1 << bit_depth) - 1;
	channels[C_G].maxval = (1 << bit_depth) - 1;
	channels[C_B].maxval = (1 << bit_depth) - 1;
	channels[C_Y].maxval = (1 << bit_depth) - 1;
	channels[C_A].maxval = (1 << bit_depth) - 1;
    }

    /* read image and write raster layers */

    if (interlace)
	png_read_image(png_ptr, png_rows);

    for (y = 0; y < height; y++)
    {
	png_bytep p;

	if (interlace)
	    p = png_rows[y];
	else
	{
	    png_read_row(png_ptr, png_buffer, NULL);
	    p = png_buffer;
	}

	if (Float)
	    write_row_float(p);
	else
	    write_row_int(p);
    }

    png_read_end(png_ptr, NULL);

    fclose(ifp);

    /* close output files */

    for (c = 0; c < 6; c++)
    {
	channel *ch = &channels[c];

	if (!ch->active)
	    continue;

	Rast_close(ch->fd);

	if (Float)
	    G_free(ch->fbuf);
	else
	    G_free(ch->buf);
    }

    /* write title and color table */

    G_verbose_message(_("Creating support files for <%s>..."), output);

    for (c = 0; c < 6; c++)
    {
	channel *ch = &channels[c];

	if (!ch->active)
	    continue;

	if (title && *title)
	    Rast_put_cell_title(ch->name, title);

	if (Float)
	    write_colors_float(c);
	else
	    write_colors_int(c);
    }

    G_free(png_buffer);
    if (interlace)
	G_free(png_rows);

    png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
}
Пример #20
0
int main(int argc, char *argv[])
{
#ifndef _WIN32
  if (geteuid() == 0)
  {
    fprintf(stderr, "Running IRC services is root is not recommended.");
    return 1;
  }
  setup_corefile();
#endif
  memset(&ServicesInfo, 0, sizeof(ServicesInfo));
  memset(&ServicesState, 0, sizeof(ServicesState));

  ServicesState.configfile = CPATH; 
  ServicesState.logfile    = LPATH;
  ServicesState.pidfile    = PPATH;
  ServicesState.fully_connected = 0;

  parseargs(&argc, &argv, myopts);

  if(ServicesState.printversion)
  {
    printf("oftc-ircservices: version: %s\n", VERSION);
    exit(EXIT_SUCCESS);
  }

  if(chdir(DPATH))
  {
    perror("chdir");
    exit(EXIT_FAILURE);
  }

#ifndef _WIN32
  if(!ServicesState.foreground)
    make_daemon();
  else
    print_startup(getpid());
#endif

  setup_signals();
  memset(&me, 0, sizeof(me));

  libio_init(!ServicesState.foreground);
  init_events();
  iorecv_cb = register_callback("iorecv", iorecv_default);
  connected_cb = register_callback("server connected", server_connected);
  iosend_cb = register_callback("iosend", iosend_default);

  OpenSSL_add_all_digests();
 
  init_interface();
  check_pidfile(ServicesState.pidfile);
  init_log(ServicesState.logfile);

#ifdef HAVE_RUBY
  init_ruby();
  signal(SIGSEGV, SIG_DFL);
#endif

  init_channel();
  init_conf();
  init_client();
  init_parser();
  init_channel_modes();
  init_mqueue();
  init_tor();

  me.from = me.servptr = &me;
  SetServer(&me);
  SetMe(&me);
  dlinkAdd(&me, &me.node, &global_client_list);
  
  read_services_conf(TRUE);
  init_db();
  init_uid();
 
#ifdef HAVE_PYTHON
  init_python();
#endif

  init_kill();

  write_pidfile(ServicesState.pidfile);
  ilog(L_NOTICE, "Services Ready");

  db_load_driver();
#ifdef USE_SHARED_MODULES
  if(chdir(MODPATH))
  {
    ilog(L_ERROR, "Could not load core modules from %s: %s",
         MODPATH, strerror(errno));
    exit(EXIT_FAILURE);
  }

  /* Go back to DPATH after checking to see if we can chdir to MODPATH */
  chdir(DPATH);
#else
  load_all_modules(1);
#endif

  boot_modules(1);
  
  connect_server();

  for(;;)
  {
    while (eventNextTime() <= CurrentTime)
      eventRun();

    execute_callback(do_event_cb);

    if(events_loop() == -1)
    {
      ilog(L_CRIT, "libevent returned error %d", errno);
      services_die("Libevent returned some sort of error", NO);
      break;
    }

    comm_select();
    send_queued_all();

    if(dorehash)
    {
      ilog(L_INFO, "Got SIGHUP, reloading configuration");
      read_services_conf(NO);
      dorehash = 0;
    }
  }

  return 0;
}
Пример #21
0
int main(int argc , char *argv[])
{
    int socket_desc , client_sock , c;
    struct sockaddr_in server , client;
    pthread_t control_thread_id;
    FILE *log=NULL;
    int i,j;

    if(IMUBInit()<0){
	printf("Error with IMU appear\n");
	exit(0);
    }
	IMUB_DLPF(6);
	IMUBAccelScale(16);

	if(argc>=2)
	{
		log=fopen(argv[1],"w");
		if(log==NULL)
		{
			printf("Error to open user file: %s\n",argv[1]);
			return -1;
		}
	}
	else
	{
		printf("Using default name: IMU_log.txt\n");
		log=fopen("IMU_log.txt","w");
	}
	
	#ifdef MOTORS
	//Setup PWM
	setup(1,DELAY_VIA_PWM);
	init_channel(channel, SUBCYCLE_TIME_US_DEFAULT);
	
	for(i=0;i<6;i++)
		add_channel_pulse(channel, esc[i], 0, 1000);	
	#endif

	usleep(5000000);


    	if( pthread_create( &control_thread_id , NULL ,  control_handler , (void*)NULL) < 0)
    	{
       		perror("could not create control thread");
       		return 1;
    	}
     
    //Create socket
    socket_desc = socket(AF_INET , SOCK_STREAM , 0);
    if (socket_desc == -1)
    {
        printf("Could not create socket");
    }
    puts("Socket created");
     
    //Prepare the sockaddr_in structure
    server.sin_family = AF_INET;
    server.sin_addr.s_addr = INADDR_ANY;
    server.sin_port = htons( 8888 );
     
    //Bind
    if( bind(socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0)
    {
        //print the error message
        perror("bind failed. Error");
        return 1;
    }
    puts("bind done");
     
    //Listen
    listen(socket_desc , 3);
     
    //Accept and incoming connection
    puts("Waiting for incoming connections...");
    c = sizeof(struct sockaddr_in);
     
     
    //Accept and incoming connection
    puts("Waiting for incoming connections...");
    c = sizeof(struct sockaddr_in);
	pthread_t thread_id;
	
    while( (client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c)) )
    {
        puts("Connection accepted");
         
        if( pthread_create( &thread_id , NULL ,  connection_handler , (void*) &client_sock) < 0)
        {
            perror("could not create thread");
            return 1;
        }
         
        //Now join the thread , so that we dont terminate before the thread
        //pthread_join( thread_id , NULL);
        puts("Handler assigned");
    }
     
    if (client_sock < 0)
    {
        perror("accept failed");
        return 1;
    }
     
    return 0;
}
Пример #22
0
int main(void)
{
    int init_res;

    puts("\nRIOT netdev test");
    dev = NETDEV_DEFAULT;

    if (dev == NULL) {
        puts("Default device was NULL");
        return 1;
    }

    printf("Initialized dev ");

    switch (dev->type) {
        case NETDEV_TYPE_UNKNOWN:
            printf("of unknown type\n");
            break;

        case NETDEV_TYPE_BASE:
            printf("as basic device\n");
            break;

        default:
            printf("of undefined type\n");
            break;
    }

    if (dev->driver == NULL) {
        puts("Default driver is defined as NULL!");
        return 1;
    }

    dev->driver->init(dev);

    if (!(init_res = init_channel())) {
        return 1;
    }

    if (check_channel() == 0) {
        printf("Channel is not as expected. ");

        if (init_res == 2) {
            printf("But initialization is not supported. Continuing.\n");
        }
        else {
            printf("Aborting\n");
            return 1;
        }
    }

    if (!(init_res = init_address())) {
        return 1;
    }

    if (check_address() == 0) {
        printf("Address is not as expected. ");

        if (init_res == 2) {
            printf("But initialization is not supported. Continuing.\n");
        }
        else {
            printf("Aborting\n");
            return 1;
        }
    }

    if (!(init_res = init_long_address())) {
        return 1;
    }

    if (check_long_address() == 0) {
        printf("Long address is not as expected. ");

        if (init_res == 2) {
            printf("But initialization is not supported. Continuing.\n");
        }
        else {
            printf("Aborting\n");
            return 1;
        }
    }

    if (!(init_res = init_nid())) {
        return 1;
    }

    if (check_nid() == 0) {
        printf("Network ID is not as expected. ");

        if (init_res == 2) {
            printf("But initialization is not supported. Continuing.\n");
        }
        else {
            printf("Aborting\n");
            return 1;
        }
    }

    if (check_max_packet_size() == 0) {
        return 1;
    }

    if (check_protocol() == 0) {
        return 1;
    }

    if (!init_state()) {
        return 1;
    }

    if (!check_state()) {
        return 1;
    }

#ifdef SENDER

    if (!send_packet()) {
        return 1;
    }

#elif RECEIVER

    if (!init_receiver_callback()) {
        return 1;
    }

#endif

    return 0;
}