static int ca_play (void) { if (!device_id) { if (ca_init()) { return -1; } } if (AudioDeviceStart (device_id, ca_buffer_callback)) { return -1; } state = OUTPUT_STATE_PLAYING; return 0; }
bool cave_generate_map(struct dm_map *map, struct random *r, enum dm_dungeon_type type, coord_t *ul, coord_t *dr) { FIX_UNUSED(type); /* initialise cellular automata */ coord_t size = { .x = dr->x - ul->x, .y = dr->y - ul->y, }; struct ca_map *cmap = ca_init(&size); /* fill the map randomly with floors */ coord_t p; for (p.y = 0; p.y < size.y; p.y++) { for (p.x = 0; p.x < size.x; p.x++) { ca_set_coord(cmap, &p, randpick(r, 45) ); } } /* Fill the map with large caves */ for (int i = 0; i < 4; i++) { ca_generation(cmap, 16, 8, 2); } /* Do a few passes to make them less smooth */ for (int i = 0; i < 2; i++) { int ri = (random_int32(r) % 4) +2; ca_generation(cmap, 5, ri, 1); } /* translate the ca_map to the real map */ for(p.y = 0; p.y < size.y; p.y++) { for(p.x = 0; p.x < size.x; p.x++) { coord_t c = cd_add(ul, &p); /* check if the cell is alive or dead */ if (ca_get_coord(cmap, &p) == CA_ALIVE) { /* fill the tile with the specified type */ if(random_int32(r)%100 < 1) { dm_get_map_me(&c,map)->tile = ts_get_tile_specific(TILE_ID_MAD_CAP_FUNGUS); } else dm_get_map_me(&c,map)->tile = ts_get_tile_specific(TILE_ID_CONCRETE_FLOOR); } } } /* cleanup and return */ ca_free(cmap); return true; }
int dvb_open_device(adapter *ad) { char buf[100]; LOG("trying to open [%d] adapter %d and frontend %d", ad->id, ad->pa, ad->fn); sprintf(buf, "/dev/dvb/adapter%d/frontend%d", ad->pa, ad->fn); ad->fe = open(buf, O_RDWR | O_NONBLOCK); sprintf(buf, "/dev/dvb/adapter%d/dvr%d", ad->pa, ad->fn); ad->dvr = open(buf, O_RDONLY | O_NONBLOCK); sprintf(buf, "/dev/dvb/adapter%d/ca0", ad->pa); if (ad->fe < 0 || ad->dvr < 0) { sprintf(buf, "/dev/dvb/adapter%d/frontend%d", ad->pa, ad->fn); LOGL(0, "Could not open %s in RW mode (fe: %d, dvr: %d)", buf, ad->fe, ad->dvr); if (ad->fe >= 0) close(ad->fe); if (ad->dvr >= 0) close(ad->dvr); ad->fe = ad->dvr = -1; return 1; } ad->type = ADAPTER_DVB; #ifndef DISABLE_DVBCA if(ad->ca > 0) close(ad->ca); ad->ca = open (buf, O_RDWR); if (ad->ca > -1) ad->ca_device = (ca_device_t *)ca_init(ad->ca); #endif LOG("opened DVB adapter %d fe:%d dvr:%d", ad->id, ad->fe, ad->dvr); if (ioctl(ad->dvr, DMX_SET_BUFFER_SIZE, opts.dvr_buffer) < 0) perror("couldn't set DVR buffer size"); else LOG("Done setting DVR buffer to %d bytes", DVR_BUFFER); return 0; }
void ca_imsg(struct mproc *p, struct imsg *imsg) { RSA *rsa; const void *from = NULL; unsigned char *to = NULL; struct msg m; const char *pkiname; size_t flen, tlen, padding; struct pki *pki; int ret = 0; uint64_t id; int v; if (p->proc == PROC_PARENT) { switch (imsg->hdr.type) { case IMSG_CONF_START: return; case IMSG_CONF_END: ca_init(); /* Start fulfilling requests */ mproc_enable(p_pony); return; } } if (p->proc == PROC_CONTROL) { switch (imsg->hdr.type) { case IMSG_CTL_VERBOSE: m_msg(&m, imsg); m_get_int(&m, &v); m_end(&m); log_verbose(v); return; case IMSG_CTL_PROFILE: m_msg(&m, imsg); m_get_int(&m, &v); m_end(&m); profiling = v; return; } } if (p->proc == PROC_PONY) { switch (imsg->hdr.type) { case IMSG_CA_PRIVENC: case IMSG_CA_PRIVDEC: m_msg(&m, imsg); m_get_id(&m, &id); m_get_string(&m, &pkiname); m_get_data(&m, &from, &flen); m_get_size(&m, &tlen); m_get_size(&m, &padding); m_end(&m); pki = dict_get(env->sc_pki_dict, pkiname); if (pki == NULL || pki->pki_pkey == NULL || (rsa = EVP_PKEY_get1_RSA(pki->pki_pkey)) == NULL) fatalx("ca_imsg: invalid pki"); if ((to = calloc(1, tlen)) == NULL) fatalx("ca_imsg: calloc"); switch (imsg->hdr.type) { case IMSG_CA_PRIVENC: ret = RSA_private_encrypt(flen, from, to, rsa, padding); break; case IMSG_CA_PRIVDEC: ret = RSA_private_decrypt(flen, from, to, rsa, padding); break; } m_create(p, imsg->hdr.type, 0, 0, -1); m_add_id(p, id); m_add_int(p, ret); if (ret > 0) m_add_data(p, to, (size_t)ret); m_close(p); free(to); RSA_free(rsa); return; } } errx(1, "ca_imsg: unexpected %s imsg", imsg_to_str(imsg->hdr.type)); }