Пример #1
0
static
int finish(struct audio_finish *finish)
{
  int i, result = 0;

  if (opened) {
    if (drain() == -1)
      result = -1;
    if (close_dev(wave_handle) == -1)
      result = -1;
  }

  /* restore priority status */

  SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
  SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);

  for (i = 0; i < NBUFFERS; ++i) {
    if (CloseHandle(output[i].event_handle) == 0 && result == 0) {
      audio_error = _("failed to close synchronization object");
      result = -1;
    }
  }

  return result;
}
Пример #2
0
DeviceV4L2Base::~DeviceV4L2Base()
{
	close_dev();
	delete video_lock;
	delete qbfrs_lock;
	delete v4l2_lock;
}
Пример #3
0
/*
 * Decrement a devices use count and remove it if necessary.
 */
void dm_put_device(struct dm_target *ti, struct dm_dev *dd)
{
	if (atomic_dec_and_test(&dd->count)) {
		close_dev(dd, ti->table->md);
		list_del(&dd->list);
		kfree(dd);
	}
}
Пример #4
0
Файл: mtree.c Проект: taysom/tau
void create_mtree(const char *path)
{
	struct dev *dev;

	create_dev(path);
	dev = open_dev(path, NUM_MTREE_BLOCKS);
	close_dev(dev);
}
Пример #5
0
static int hw_dev_close(int dev_index)
{
	struct sr_dev_inst *sdi;

	if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
		sr_err("zp: %s: sdi was NULL", __func__);
		return SR_ERR; /* TODO: SR_ERR_ARG? */
	}

	/* TODO */
	close_dev(sdi);

	return SR_OK;
}
Пример #6
0
int main(int argc, char *argv[])
{
	parse_arg(argc, argv);

	check_params_before();
	check_mount();

	stat_dev();
	open_dev();
	check_params_after();
	create_super_block();
	init_inodes();
	init_root_block();
	link_free_blocks();
	close_dev();

	return 0;
}
Пример #7
0
/*
 * This upgrades the mode on an already open dm_dev.  Being
 * careful to leave things as they were if we fail to reopen the
 * device.
 */
static int upgrade_mode(struct dm_dev *dd, int new_mode)
{
	int r;
	struct dm_dev dd_copy;
	dev_t dev = dd->bdev->bd_dev;

	memcpy(&dd_copy, dd, sizeof(dd_copy));

	dd->mode |= new_mode;
	dd->bdev = NULL;
	r = open_dev(dd, dev);
	if (!r)
		close_dev(&dd_copy);
	else
		memcpy(dd, &dd_copy, sizeof(dd_copy));

	return r;
}
Пример #8
0
/*
 * This upgrades the mode on an already open dm_dev.  Being
 * careful to leave things as they were if we fail to reopen the
 * device.
 */
static int upgrade_mode(struct dm_dev *dd, int new_mode, struct mapped_device *md)
{
	int r;
	struct dm_dev dd_copy;
	dev_t dev = dd->bdev->bd_dev;

	dd_copy = *dd;

	dd->mode |= new_mode;
	dd->bdev = NULL;
	r = open_dev(dd, dev, md);
	if (!r)
		close_dev(&dd_copy, md);
	else
		*dd = dd_copy;

	return r;
}
Пример #9
0
static
int config(struct audio_config *config)
{
  unsigned int bitdepth;

  bitdepth = config->precision & ~7;
  if (bitdepth == 0)
    bitdepth = 16;
  else if (bitdepth > 32)
    bitdepth = 32;

  if (opened) {
    if (drain() == -1)
      return -1;

    close_dev(wave_handle);
  }

  if (open_dev(&wave_handle, config->channels, config->speed, bitdepth) == -1)
    return -1;

  switch (config->precision = bitdepth) {
  case 8:
    audio_pcm = audio_pcm_u8;
    break;

  case 16:
    audio_pcm = audio_pcm_s16le;
    break;

  case 24:
    audio_pcm = audio_pcm_s24le;
    break;

  case 32:
    audio_pcm = audio_pcm_s32le;
    break;
  }

  samplerate = config->speed;
  samplesize = bitdepth / 8;

  return 0;
}
Пример #10
0
int main(int argc, char **argv)
{
	int handle;

	if (argc < 2)
		usage();
	if (argc > 1 && (streq(argv[1], "-h") || streq(argv[1], "--help")))
		usage();

	handle = open_dev("/dev/hidraw%d");
	if (handle == -1)
		trouble_shooting();

	init_dev(handle);

	configure(handle, argc, argv);

	close_dev(handle);
	exit(0);
}
Пример #11
0
static int hw_cleanup(void)
{
	GSList *l;
	struct sr_dev_inst *sdi;

	for (l = dev_insts; l; l = l->next) {
		sdi = l->data;
		/* Properly close all devices... */
		close_dev(sdi);
		/* ...and free all their memory. */
		sr_dev_inst_free(sdi);
	}
	g_slist_free(dev_insts);
	dev_insts = NULL;

	if (usb_context)
		libusb_exit(usb_context);
	usb_context = NULL;

	return SR_OK;
}
Пример #12
0
int main()
{
    int ret;
    int ii;
    CTRL_MSG outmsg;
    CTRL_MSG inmsg;
    SAMPLE sample;
    
    sample.sample_rate = 10000;
    sample.high_channel=6;
    sample.low_channel=0;
    sample.sample_range=V5;
    sample.num_samples=100;


    ret = mc_init_device(&daq, VENDOR_ID, PRODUCT_ID);
    if(ret!=MC_SUCCESS) {
      //mc_perror(ret, "Could not initialize device");
      exit(ret);  
    }

    for(ii=0;ii<2;ii=ii+1) {
      printf("%d:",ii);
      mc_msg_load(&outmsg,"DEV:FLASHLED/1");
      ret = mc_send_msg(&daq, &outmsg, &inmsg);
      if(ret!=MC_SUCCESS) {
          mc_perror(ret, "Huh?");
          close_dev();
      }
      printf("OUTMSG:%s\tINMSG:%s\n",outmsg.msg,inmsg.msg);
      //sleep(1);
    }
    mc_get_calibration(&daq);
    mc_init_sample(&daq, &sample);
    mc_sample_single(&daq, &sample);
    mc_print_data(&daq,&sample);
    mc_free_sample(&sample); 
    exit(EXIT_SUCCESS);

}
Пример #13
0
/* signals usr1 & usr2 are sent by the spnav_x11 script to start/stop the
 * daemon's connection to the X server.
 */
void sig_handler(int s)
{
	int tmp;

	switch(s) {
	case SIGHUP:
		tmp = cfg.led;
		read_cfg("/etc/spnavrc", &cfg);
		if(cfg.led != tmp) {
			set_led(cfg.led);
		}
		break;

	case SIGSEGV:
		fprintf(stderr, "Segmentation fault caught, trying to exit gracefully\n");
	case SIGINT:
	case SIGTERM:
		close_x11();	/* call to avoid leaving garbage in the X server's root windows */
		close_dev();
		remove(PIDFILE);
		exit(0);

#ifdef USE_X11
	case SIGUSR1:
		init_x11();
		break;

	case SIGUSR2:
		close_x11();
		break;
#endif

	default:
		break;
	}
}
Пример #14
0
int
main(int argc, char *argv[])
{
	int ret = 1, i;
	dldev_t dev;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	while((i = getopt(argc, argv, "hd:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/

	fprintf(stdout, "a: acd.app_idx\nc: acd.code_loc\nd: acd.db_loc\n"
		"i: acd.code_invalid\nm: acd.db_modified\nI: acd.db_invalid\n"
		"p: acd.passwd_req\nb: acd.user_banner\nidx "
		"acdimIpb type inst  asd  add stat refr bann code banner\n");
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		fprintf(stdout, "%2d: %d%d%d%d%d%d%d%d   %02x   %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.user_banner,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,

				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}

	fprintf(stdout, "sync id: %s\n", dev.icb.sync_id);

/******************************************************************************/
	if(exit_session(&dev)){
		ERROR("exit_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
Пример #15
0
int
main(int argc, char *argv[])
{
	int ret = 1, i, idx;
	dldev_t dev;
	tymer_t db;
	u8 *data;
	u16 len;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	i = strlen(argv[0]) - 1;
	for(; i >= 0 && argv[0][i] != '/'; i--);
	i++;
	if(strstr(argv[0] + i, "interval")){
		set_timer(POR_INTERVAL);
		is_countdn = 0;
	}

	while((i = getopt(argc, argv, "hd:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	if((idx = find_app(&dev, uapp_name)) < 0){
		ERROR("%s application not found", uapp_name);
		goto end;
	}

	if(dump_add(&dev, idx, &data, &len)){
		ERROR("dump_add");
		goto end;
	}
	read_timer(&db, data);
	free(data);

	print_timer(&db, stdout);
	free_timer(&db);

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
Пример #16
0
int
main(int argc, char *argv[])
{
	int ret = 1, i;
	char *tz[3], *date = NULL, *hr24 = NULL, *week_no = NULL, *dst = NULL,
	     *euro = NULL, *observe_dst = NULL, *adjust = NULL;
	u8 date_format_;
	time_t dsec[3], adjust_sec = 0;
	time_t tloc, tloc2;
	struct tm *tm;
	dldev_t dev;
	tod_t db;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	while((i = getopt(argc, argv, "hd:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	memset(tz, 0, sizeof(tz));
	BEGIN_OPT()
		OPT("tz1", tz[0])
		OPT("tz2", tz[1])
		OPT("tz3", tz[2])
		OPT("date", date)
		OPT("24hr", hr24)
		OPT("week_no", week_no)
		OPT("dst", dst)
		OPT("euro", euro)
		OPT("observe_dst", observe_dst)
		/* non-standard options */
		OPT("adjust", adjust)
	END_OPT()

	if(date){
		for(i = 0; i < 3 && strcmp(date, date_format[i]); i++);
		if(i == 3){
			fprintf(stderr, "%s: format error!\n", date);
			usage();
		}
		date_format_ = i;
	}else
		date_format_ = mdy;

	for(i = 0; i < 3; i++){
		dsec[i] = 0;
		if(tz[i] && tz[i][0]){
			char buf[10];

			strncpy(buf, tz[i], 9);
			buf[9] = 0;
			if(strlen(buf) != 9 ||
					(buf[3] != '+' && buf[3] != '-')){
				fprintf(stderr, "%s: format error!\n", tz[i]);
				usage();
			}
			buf[6] = 0;
			dsec[i] = atoi(buf+3) * 3600 + atoi(buf+7) * 60;
		}
	}
	if(adjust && adjust[0]){
		char buf[10];

		strncpy(buf, adjust, 9);
		buf[9] = 0;
		if(strlen(buf) != 9 || (buf[0] != '+' && buf[0] != '-')){
			fprintf(stderr, "%s: format error!\n", adjust);
			usage();
		}
		buf[3] = buf[6] = 0;
		adjust_sec = atoi(buf) * 3600 + atoi(buf+4) * 60 + atoi(buf+7);
	}

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	time(&tloc);

	memset(&db, 0, sizeof(tod_t));

	for(i = 0; i < 3; i++){
		db.tod[i].primary = !i;	/* user */

		db.tod[i].update_tz_id = 1; /* -> tz_id */
		db.tod[i].update_display = 1; /* -> everything else? */
		db.tod[i].update_tz_name = 1; /* -> tz_name */
		db.tod[i].update_hms = 1; /* -> hour/minute/second */
		db.tod[i].update_mdy = 1; /* -> year/month/day */

		/* update_display */
		db.tod[i].date_format = date_format_; /* user */
		db.tod[i].hr24_format = (hr24 && strcmp(hr24, "no")); /* user */
		db.tod[i].display_week_no = (week_no && strcmp(week_no, "no"));
			/* user */
		db.tod[i].tz_in_dst = (dst && strcmp(dst, "no")); /* user */
		db.tod[i].euro_format = (euro && strcmp(euro, "no")); /* user */
		db.tod[i].tz_observes_dst =
			(observe_dst && strcmp(observe_dst, "no")); /* user */

		/* set if update_mdy = 1 */
		db.tod[i].tz_entered_set_state = 1;

		/* update_tz_name */
		if(tz[i] && tz[i][0])
			strncpy(db.tod[i].tz_name, tz[i], 3); /* user */
		else
			strncpy(db.tod[i].tz_name, "UTC", 3); /* user */

		/* update_tz_id */
		db.tod[i].tz_id = 0; /* used for WorldTime WristApp */

		tloc2 = tloc + dsec[i] + adjust_sec;
		tm = gmtime(&tloc2);

		/* update_hms */
		db.tod[i].second = tm->tm_sec; /* user */
		db.tod[i].minute = tm->tm_min; /* user */
		db.tod[i].hour = tm->tm_hour; /* user */

		/* update_mdy */
		db.tod[i].day = tm->tm_mday; /* user */
		db.tod[i].month = tm->tm_mon + 1; /* user */
		db.tod[i].year = tm->tm_year + 1900; /* user */
	}

	if(update_tod(&dev, &db)){
		ERROR("update_tod");
		goto end;
	}

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
Пример #17
0
int
main(int argc, char *argv[])
{
	int ret = 1, istty, i, idx, delete_all = 0, updated = 0;
	dldev_t dev;
	contact_t db;
	contact_data_t rec;
	u8 *data;
	u16 len;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	istty = isatty(0);

	while((i = getopt(argc, argv, "hd:a")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'a':
			delete_all = 1;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	memset(&rec, 0, sizeof(contact_data_t));
	BEGIN_OPT()
		OPT("msg", rec.msg)
		OPT("type", rec.type)
		OPT("area", rec.area)
		OPT("number", rec.number)
	END_OPT()

	if(delete_all){
		fprintf(stderr,
			"WARNING: DELETE ALL CONTACTS IN THE WATCH (Y/N)? ");
		if(tolower(getchar()) != 'y')
			exit(0);
	}else
	if(istty && (!rec.msg || !rec.type || !rec.area || !rec.number))
		usage();

	/* TODO: long phone number extending to the next or previous record */

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	if((idx = find_app(&dev, "CONTACT")) < 0){
		ERROR("CONTACT application not found");
		goto end;
	}

	if(dump_add(&dev, idx, &data, &len)){
		ERROR("dump_add");
		goto end;
	}

	read_contact(&db, data);
	free(data);

	if(delete_all){
		while(!del_contact(&db, 0))
			updated = 1;
	}else{
		if(!istty && !del_contact_file(&db, stdin))
			updated = 1;

		if(rec.msg && rec.type && rec.area && rec.number &&
			(i = find_contact(&db, &rec)) >= 0 &&
			!del_contact(&db, i))
			updated = 1;
	}

	if(updated){
		create_contact(&db, &data, &len);
		if(load_add(&dev, idx, data)){
			ERROR("load_add");
			goto end;
		}
		free(data);
	}

	print_contact(&db, stdout);
	free_contact(&db);

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
Пример #18
0
int
main(int argc, char *argv[])
{
	int ret = 1, i;
	dldev_t dev;
	note_t db;
	u8 *data;
	u16 len;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	while((i = getopt(argc, argv, "hd:u:e:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'u':
			unused_recs = atoi(optarg);
			if(unused_recs < 0)
				unused_recs = 0;
			break;
		case 'e':
			extra_msg_len = atoi(optarg);
			if(extra_msg_len < 0)
				extra_msg_len = 0;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

	set_note_unused_recs(unused_recs);
	set_note_extra_len(extra_msg_len);

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	if(read_note_mem(&dev, &db)){
		ERROR("read_note_mem");
		goto end;
	}

	create_note(&db, &data, &len);
	if(load_add(&dev, find_app(&dev, "NOTE"), data)){
		ERROR("load_add");
		goto end;
	}
	free(data);

	print_note(&db, stdout);
	free_note(&db);

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
Пример #19
0
int
main(int argc, char *argv[])
{
	int ret = 1, istty, i, idx;
	char *msg = NULL, *timer = NULL, *at_end = NULL, *halfway = NULL;
	dldev_t dev;
	tymer_t db;
	u8 *data;
	u16 len;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	istty = isatty(0);

	i = strlen(argv[0]) - 1;
	for(; i >= 0 && argv[0][i] != '/'; i--);
	i++;
	if(strstr(argv[0] + i, "interval")){
		set_timer(POR_INTERVAL);
		is_countdn = 0;
	}

	while((i = getopt(argc, argv, "hd:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	BEGIN_OPT()
		OPT("msg", msg)
		OPT("timer", timer)
		OPT("at_end", at_end)
		OPT("halfway", halfway)
	END_OPT()

	/* allows the user to change only at_end in interval timer */
	if(istty && ((!msg || !timer) && (is_countdn || !at_end)))
		usage();

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	if((idx = find_app(&dev, uapp_name)) < 0){
		ERROR("%s application not found", uapp_name);
		goto end;
	}

	if(dump_add(&dev, idx, &data, &len)){
		ERROR("dump_add");
		goto end;
	}
	read_timer(&db, data);
	free(data);

	if(!istty)
		add_timer_file(&db, stdin);

	if(msg && timer){
		char buf[BUFSIZ];
		timer_data_t rec;

		sprintf(buf, "%s\t%s\t%s%s", msg, timer,
			(at_end ? at_end : "stop"),
			(halfway && strcmp(halfway, "no") ? "\thalfway" : ""));
		if(read_timer_line(&rec, buf))
			fprintf(stderr, "add_%s: format error!\n", lapp_name);
		else
		if(find_timer(&db, &rec) < 0)
			add_timer(&db, &rec);
	}
	if(!is_countdn && at_end){
		int i;

		for(i = 0; i < 3 && strcmp(at_end, timer_at_end[i]); i++);
		if(i < 3){
			set_timer_at_end(i);
			update_timer_at_end(&db);
		}
	}

	create_timer(&db, &data, &len);
	if(load_add(&dev, idx, data)){
		ERROR("load_add");
		goto end;
	}
	free(data);

	print_timer(&db, stdout);
	free_timer(&db);

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
Пример #20
0
int
main(int argc, char *argv[])
{
	int ret = 1, i, idx, fd, num_apps = 0;
	char *dev_file = "/dev/uhid0", *banner, *file;
	dldev_t dev;
	appinfo *app = NULL;
	u8 *data;
	u16 len;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	while((i = getopt(argc, argv, "hd:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	BEGIN_OPT()
		APP_OPT("rom", -3)
		APP_OPT("eeprom", -2)
		APP_OPT("wristapp", -1)
		APP_OPT("contact", APP_CONTACT)
		APP_OPT("note", APP_NOTE)
		APP_OPT("appt", APP_APPT)
		APP_OPT("alarm", APP_ALARM)
		APP_OPT("schedule", APP_SCHEDULE)
		APP_OPT("occasion", APP_OCCASION)
		APP_OPT("chrono", APP_CHRONO)
		APP_OPT("countdn", APP_TIMER)
		APP_OPT("interval", APP_TIMER | 0x100)
#if 0
		APP_OPT("synchro", APP_SYNCHRO)
#endif
		APP_OPT("option", APP_OPTION)
	END_OPT()

	if(!num_apps)
		usage();

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	tucp_progress(1);

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	for(i = 0; i < num_apps; i++){
		if(app[i].file[0])
			fprintf(stderr, "%s\n", app[i].file);
		else
			continue;

		banner = NULL;
		file = app[i].file;

		switch(app[i].app){
		case -3:
			if(dump_rom(&dev, &data, &len)){
				ERROR("dump_rom");
				goto end;
			}
			break;
		case -2:
			if(dump_eeprom(&dev, &data, &len)){
				ERROR("dump_eeprom");
				goto end;
			}
			break;
		case -1:
			banner = file;
			for(; *file && *file != '='; file++);
			if(*file)
				*file++ = 0;
			if(!(*file)){
				ERROR("%s: no file name specified", banner);
				goto end;
			}
			for(; *banner; banner++)
				*banner = toupper(*banner);
			banner = app[i].file;
			break;
		case APP_CONTACT:
			banner = "CONTACT";
			break;
		case APP_NOTE:
			banner = "NOTE";
			break;
		case APP_APPT:
			banner = "APPT";
			break;
		case APP_ALARM:
			banner = "ALARM";
			break;
		case APP_SCHEDULE:
			banner = "SCHEDULE";
			break;
		case APP_OCCASION:
			banner = "OCCASION";
			break;
		case APP_CHRONO:
			banner = "CHRONO";
			break;
		case APP_TIMER:
			banner = "COUNTDN TIMER";
			break;
		case APP_TIMER | 0x100:
			banner = "INTERVAL TIMER";
			break;
#if 0
		case APP_SYNCHRO:
			banner = "SYNCHRO";
			break;
#endif
		case APP_OPTION:
			len = 15;
			data = (u8 *)malloc(len);
			if(read_abs_addr(&dev, dev.sysmap.opt_addr, int_mem,
						data, len)){
				ERROR("read_abs_addr");
				goto end;
			}
			break;
		}

		if(banner){
			if((idx = find_app(&dev, banner)) < 0){
				ERROR("%s application not found", banner);
				goto end;
			}
			if(dump_add(&dev, idx, &data, &len)){
				ERROR("dump_add");
				goto end;
			}
		}

		if((fd = open(file, O_WRITE, S_IRWUSR)) < 0){
			ERROR("%s: open failed", file);
			goto end;
		}
		if(write(fd, data, len) != len){
			ERROR("%s: write failed", file);
			goto end;
		}
		close(fd);
		free(data);
	}

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	tucp_progress(0);

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
Пример #21
0
int main(int argc, char **argv)
{
	int i, become_daemon = 1;

	for(i=1; i<argc; i++) {
		if(argv[i][0] == '-' && argv[i][2] == 0) {
			switch(argv[i][1]) {
			case 'd':
				become_daemon = !become_daemon;
				break;

			case 'v':
				verbose = 1;
				break;

			case 'h':
				printf("usage: %s [options]\n", argv[0]);
				printf("options:\n");
				printf("  -d\tdo not daemonize\n");
				printf("  -v\tverbose output\n");
				printf("  -h\tprint this usage information\n");
				return 0;

			default:
				fprintf(stderr, "unrecognized argument: %s\n", argv[i]);
				return 1;
			}
		} else {
			fprintf(stderr, "unexpected argument: %s\n", argv[i]);
			return 1;
		}
	}

	if(become_daemon) {
		daemonize();
	}
	write_pid_file();

	read_cfg("/etc/spnavrc", &cfg);

	if(!(client_list = malloc(sizeof *client_list))) {
		perror("failed to allocate client list");
		return 1;
	}
	client_list->next = 0;

	signal(SIGINT, sig_handler);
	signal(SIGTERM, sig_handler);
	signal(SIGSEGV, sig_handler);
	signal(SIGHUP, sig_handler);
	signal(SIGUSR1, sig_handler);
	signal(SIGUSR2, sig_handler);

	init_dev();
	init_unix();
#ifdef USE_X11
	init_x11();
#endif

	/* event handling loop */
	while(1) {
		fd_set rd_set;

		if(dev_fd == -1) {
			if(init_dev() == -1) {
				sleep(30);
				continue;
			}
		}

		if(select_all(&rd_set) >= 0) {
			handle_events(&rd_set);
		}
	}

	/* just for the sense of symmetry, execution can't reach this :) */
#ifdef USE_X11
	close_x11();
#endif
	close_dev();
	return 0;
}
Пример #22
0
Файл: mtree.c Проект: taysom/tau
void close_mtree(struct mtree *mt)
{
	close_dev(mt->dev);
	free(mt);
}