示例#1
0
/**
 * Walk through all device in the audio-pcm category.
 * @param callback Function to call on every device.
 * @return Error code.
 */
int hound_server_devices_iterate(device_callback_t callback)
{
	if (!callback)
		return EINVAL;
	static bool resolved = false;
	static category_id_t cat_id = 0;

	if (!resolved) {
		const int ret = loc_category_get_id("audio-pcm", &cat_id,
		    IPC_FLAG_BLOCKING);
		if (ret != EOK)
			return ret;
		resolved = true;
	}

	service_id_t *svcs = NULL;
	size_t count = 0;
	const int ret = loc_category_get_svcs(cat_id, &svcs, &count);
	if (ret != EOK)
		return ret;

	for (unsigned i = 0; i < count; ++i) {
		char *name = NULL;
		loc_service_get_name(svcs[i], &name);
		callback(svcs[i], name);
		free(name);
	}
	free(svcs);
	return EOK;
}
示例#2
0
static int get_wifi_list(service_id_t **wifis, size_t *count)
{
	category_id_t wifi_cat;
	int rc = loc_category_get_id("ieee80211", &wifi_cat, 0);
	if (rc != EOK) {
		printf("Error resolving category 'ieee80211'.\n");
		return rc;
	}
	
	rc = loc_category_get_svcs(wifi_cat, wifis, count);
	if (rc != EOK) {
		printf("Error getting list of WIFIs.\n");
		return rc;
	}
	
	return EOK;
}
示例#3
0
static int show_cat(const char *cat_name, category_id_t cat_id)
{
	service_id_t *svc_ids;
	size_t svc_cnt;
	char *svc_name;
	char *server_name;
	int rc;
	size_t j;

	printf("%s:\n", cat_name);

	rc = loc_category_get_svcs(cat_id, &svc_ids, &svc_cnt);
	if (rc != EOK) {
		printf(NAME ": Failed getting list of services in "
		    "category %s, skipping.\n", cat_name);
		return rc;
	}

	for (j = 0; j < svc_cnt; j++) {
		rc = loc_service_get_name(svc_ids[j], &svc_name);
		if (rc != EOK) {
			printf(NAME ": Unknown service name (SID %"
			    PRIun ").\n", svc_ids[j]);
			continue;
		}

		rc = loc_service_get_server_name(svc_ids[j], &server_name);
		if (rc != EOK && rc != EINVAL) {
			free(svc_name);
			printf(NAME ": Unknown service name (SID %"
			    PRIun ").\n", svc_ids[j]);
			continue;
		}

		if (rc == EOK)
			printf("\t%s : %s\n", svc_name, server_name);
		else
			printf("\t%s\n", svc_name);
	
		free(svc_name);
		free(server_name);
	}

	free(svc_ids);
	return EOK;
}
示例#4
0
static int inet_link_check_new(void)
{
	bool already_known;
	category_id_t iplink_cat;
	service_id_t *svcs;
	size_t count, i;
	int rc;

	fibril_mutex_lock(&inet_discovery_lock);

	rc = loc_category_get_id("iplink", &iplink_cat, IPC_FLAG_BLOCKING);
	if (rc != EOK) {
		log_msg(LVL_ERROR, "Failed resolving category 'iplink'.");
		fibril_mutex_unlock(&inet_discovery_lock);
		return ENOENT;
	}

	rc = loc_category_get_svcs(iplink_cat, &svcs, &count);
	if (rc != EOK) {
		log_msg(LVL_ERROR, "Failed getting list of IP links.");
		fibril_mutex_unlock(&inet_discovery_lock);
		return EIO;
	}

	for (i = 0; i < count; i++) {
		already_known = false;

		list_foreach(inet_link_list, ilink_link) {
			inet_link_t *ilink = list_get_instance(ilink_link,
			    inet_link_t, link_list);
			if (ilink->svc_id == svcs[i]) {
				already_known = true;
				break;
			}
		}

		if (!already_known) {
			log_msg(LVL_DEBUG, "Found IP link '%lu'",
			    (unsigned long) svcs[i]);
			rc = inet_link_open(svcs[i]);
			if (rc != EOK)
				log_msg(LVL_ERROR, "Could not open IP link.");
		}
	}
示例#5
0
void list(void)
{
	category_id_t usbhc_cat;
	service_id_t *svcs;
	size_t count;
	size_t i;
	int rc;

	rc = loc_category_get_id(USB_HC_CATEGORY, &usbhc_cat, 0);
	if (rc != EOK) {
		printf(NAME ": Error resolving category '%s'",
		    USB_HC_CATEGORY);
		return;
	}

	rc = loc_category_get_svcs(usbhc_cat, &svcs, &count);
	if (rc != EOK) {
		printf(NAME ": Error getting list of host controllers.\n");
		return;
	}

	for (i = 0; i < count; i++) {
		devman_handle_t hc_handle = 0;
		int rc = usb_ddf_get_hc_handle_by_sid(svcs[i], &hc_handle);
		if (rc != EOK) {
			printf(NAME ": Error resolving handle of HC with SID %"
			    PRIun ", skipping.\n", svcs[i]);
			continue;
		}
		char path[MAX_PATH_LENGTH];
		rc = devman_fun_get_path(hc_handle, path, MAX_PATH_LENGTH);
		if (rc != EOK) {
			printf(NAME ": Error resolving path of HC with SID %"
			    PRIun ", skipping.\n", svcs[i]);
			continue;
		}
		print_found_hc(svcs[i], path);
		print_hc_devices(hc_handle);
	}

	free(svcs);
}
示例#6
0
文件: barber.c 项目: jvesely/helenos
static void loc_callback(void)
{
	category_id_t led_cat;
	int rc = loc_category_get_id("led", &led_cat, IPC_FLAG_BLOCKING);
	if (rc != EOK)
		return;
	
	service_id_t *svcs;
	size_t count;
	rc = loc_category_get_svcs(led_cat, &svcs, &count);
	if (rc != EOK)
		return;
	
	for (size_t i = 0; i < count; i++) {
		bool known = false;
		
		/* Determine whether we already know this device. */
		list_foreach(led_devs, link, led_dev_t, dev) {
			if (dev->svc_id == svcs[i]) {
				known = true;
				break;
			}
		}
		
		if (!known) {
			led_dev_t *dev = (led_dev_t *) calloc(1, sizeof(led_dev_t));
			if (!dev)
				continue;
			
			link_initialize(&dev->link);
			dev->svc_id = svcs[i];
			dev->sess = loc_service_connect(svcs[i], INTERFACE_DDF, 0);
			
			list_append(&dev->link, &led_devs);
		}
	}
	
	// FIXME: Handle LED device removal
	
	free(svcs);
}
示例#7
0
文件: main.c 项目: jvesely/helenos
int main(int argc, char **argv)
{
	sysarg_t baud = 38400;
	service_id_t svc_id;
	char *serial_port_name = NULL;

	int arg = 1;
	int rc;

	isdv4_event_fn event_fn = emit_event;

	if (argc > arg && str_test_prefix(argv[arg], "--baud=")) {
		size_t arg_offset = str_lsize(argv[arg], 7);
		char* arg_str = argv[arg] + arg_offset;
		if (str_length(arg_str) == 0) {
			fprintf(stderr, "--baud requires an argument\n");
			syntax_print();
			return 1;
		}
		char *endptr;
		baud = strtol(arg_str, &endptr, 10);
		if (*endptr != '\0') {
			fprintf(stderr, "Invalid value for baud\n");
			syntax_print();
			return 1;
		}
		arg++;
	}

	if (argc > arg && str_cmp(argv[arg], "--print-events") == 0) {
		event_fn = print_and_emit_event;
		arg++;
	}

	if (argc > arg) {
		serial_port_name = argv[arg];
		rc = loc_service_get_id(serial_port_name, &svc_id, 0);
		if (rc != EOK) {
			fprintf(stderr, "Cannot find device service %s\n",
			    argv[arg]);
			return 1;
		}
		arg++;
	}
	else {
		category_id_t serial_cat_id;

		rc = loc_category_get_id("serial", &serial_cat_id, 0);
		if (rc != EOK) {
			fprintf(stderr, "Failed getting id of category "
			    "'serial'\n");
			return 1;
		}

		service_id_t *svc_ids;
		size_t svc_count;

		rc = loc_category_get_svcs(serial_cat_id, &svc_ids, &svc_count);		if (rc != EOK) {
			fprintf(stderr, "Failed getting list of services\n");
			return 1;
		}

		if (svc_count == 0) {
			fprintf(stderr, "No service in category 'serial'\n");
			free(svc_ids);
			return 1;
		}

		svc_id = svc_ids[0];

		rc = loc_service_get_name(svc_id, &serial_port_name);
		if (rc != EOK) {
			fprintf(stderr, "Failed getting name of serial service\n");
			return 1;
		}

		free(svc_ids);
	}

	if (argc > arg) {
		fprintf(stderr, "Too many arguments\n");
		syntax_print();
		return 1;
	}

	fibril_mutex_initialize(&client_mutex);

	printf(NAME ": Using serial port %s\n", serial_port_name);

	async_sess_t *sess = loc_service_connect(svc_id, INTERFACE_DDF,
	    IPC_FLAG_BLOCKING);
	if (!sess) {
		fprintf(stderr, "Failed connecting to service\n");
	}

	async_exch_t *exch = async_exchange_begin(sess);
	rc = async_req_4_0(exch, SERIAL_SET_COM_PROPS, baud,
	    SERIAL_NO_PARITY, 8, 1);
	async_exchange_end(exch);

	if (rc != EOK) {
		fprintf(stderr, "Failed setting serial properties\n");
		return 2;
	}

	rc = isdv4_init(&state, sess, event_fn);
	if (rc != EOK) {
		fprintf(stderr, "Failed initializing isdv4 state");
		return 2;
	}

	rc = isdv4_init_tablet(&state);
	if (rc != EOK) {
		fprintf(stderr, "Failed initializing tablet");
		return 2;
	}

	printf("Tablet information:\n");
	printf(" Stylus: %ux%u pressure: %u tilt: ", state.stylus_max_x,
	    state.stylus_max_y, state.stylus_max_pressure);
	if (state.stylus_tilt_supported) {
		printf("%ux%u\n", state.stylus_max_xtilt, state.stylus_max_ytilt);
	}
	else {
		printf("not supported\n");
	}
	printf(" Touch: %ux%u type: %s\n", state.touch_max_x, state.touch_max_y,
		touch_type(state.touch_type));
	
	fid_t fibril = fibril_create(read_fibril, NULL);
	/* From this on, state is to be used only by read_fibril */
	fibril_add_ready(fibril);

	async_set_fallback_port_handler(mouse_connection, NULL);
	rc = loc_server_register(NAME);
	if (rc != EOK) {
		printf("%s: Unable to register driver.\n", NAME);
		return rc;
	}

	service_id_t service_id;
	char *service_name;
	rc = asprintf(&service_name, "mouse/isdv4-%" PRIun, svc_id);
	if (rc < 0) {
		printf(NAME ": Unable to create service name\n");
		return rc;
	}

	rc = loc_service_register(service_name, &service_id);
	if (rc != EOK) {
		printf(NAME ": Unable to register service %s.\n", service_name);
		return rc;
	}

	category_id_t mouse_category;
	rc = loc_category_get_id("mouse", &mouse_category, IPC_FLAG_BLOCKING);
	if (rc != EOK) {
		printf(NAME ": Unable to get mouse category id.\n");
	}
	else {
		rc = loc_service_add_to_cat(service_id, mouse_category);
		if (rc != EOK) {
			printf(NAME ": Unable to add device to mouse category.\n");
		}
	}

	printf("%s: Accepting connections\n", NAME);
	task_retval(0);
	async_manager();

	/* Not reached */
	return 0;
}
示例#8
0
文件: date.c 项目: jvesely/helenos
int
main(int argc, char **argv)
{
	int rc, c;
	category_id_t cat_id;
	size_t        svc_cnt;
	service_id_t  *svc_ids = NULL;
	service_id_t  svc_id;
	char          *svc_name = NULL;
	bool          read_only = true;
	char          *wdate = NULL;
	char          *wtime = NULL;
	struct tm     t;
	int           n_args = argc;

	while ((c = getopt(argc, argv, "hd:t:")) != -1) {
		switch (c) {
		case 'h':
			usage();
			return 0;
		case 'd':
			if (wdate) {
				usage();
				return 1;
			}
			wdate = (char *)optarg;
			read_only = false;
			n_args -= 2;
			break;
		case 't':
			if (wtime) {
				usage();
				return 1;
			}
			wtime = (char *)optarg;
			read_only = false;
			n_args -= 2;
			break;
		case '?':
			usage();
			return 1;
		}
	}

	if (n_args != 1) {
		printf(NAME ": Unrecognized parameter\n");
		usage();
		return 1;
	}

	/* Get the id of the clock category */
	rc = loc_category_get_id("clock", &cat_id, IPC_FLAG_BLOCKING);
	if (rc != EOK) {
		printf(NAME ": Cannot get clock category id\n");
		goto exit;
	}

	/* Get the list of available services in the clock category */
	rc = loc_category_get_svcs(cat_id, &svc_ids, &svc_cnt);
	if (rc != EOK) {
		printf(NAME ": Cannot get the list of services in the clock "
		    "category\n");
		goto exit;
	}

	/* Check if there are available services in the clock category */
	if (svc_cnt == 0) {
		printf(NAME ": No available service found in "
		    "the clock category\n");
		goto exit;
	}

	/* Get the name of the clock service */
	rc = loc_service_get_name(svc_ids[0], &svc_name);
	if (rc != EOK) {
		printf(NAME ": Cannot get the name of the service\n");
		goto exit;
	}

	/* Get the service id for the device */
	rc = loc_service_get_id(svc_name, &svc_id, 0);
	if (rc != EOK) {
		printf(NAME ": Cannot get the service id for device %s",
		    svc_name);
		goto exit;
	}

	/* Connect to the device */
	async_sess_t *sess = loc_service_connect(svc_id, INTERFACE_DDF, 0);
	if (!sess) {
		printf(NAME ": Cannot connect to the device\n");
		goto exit;
	}

	/* Read the current date/time */
	rc = clock_dev_time_get(sess, &t);
	if (rc != EOK) {
		printf(NAME ": Cannot read the current time\n");
		goto exit;
	}

	if (read_only) {
		/* Print the current time and exit */
		printf("%02d/%02d/%d ", t.tm_mday,
		    t.tm_mon + 1, 1900 + t.tm_year);
		printf("%02d:%02d:%02d\n", t.tm_hour, t.tm_min, t.tm_sec);
	} else {
		if (wdate) {
			rc = read_date_from_arg(wdate, &t);
			if (rc != EOK) {
				printf(NAME ": error, date format not "
				    "recognized\n");
				usage();
				goto exit;
			}
		}
		if (wtime) {
			rc = read_time_from_arg(wtime, &t);
			if (rc != EOK) {
				printf(NAME ": error, time format not "
				    "recognized\n");
				usage();
				goto exit;
			}
		}

		rc = tm_sanity_check(&t);
		if (rc != EOK) {
			printf(NAME ": error, invalid date/time\n");
			goto exit;
		}

		rc = clock_dev_time_set(sess, &t);
		if (rc != EOK) {
			printf(NAME ": error, Unable to set date/time\n");
			goto exit;
		}
	}

exit:
	free(svc_name);
	free(svc_ids);
	return rc;
}
示例#9
0
int main(int argc, char **argv)
{
	sysarg_t baud = 9600;
	service_id_t svc_id;

	int arg = 1;
	int rc;

	if (argc > arg && str_test_prefix(argv[arg], "--baud=")) {
		size_t arg_offset = str_lsize(argv[arg], 7);
		char* arg_str = argv[arg] + arg_offset;
		if (str_length(arg_str) == 0) {
			fprintf(stderr, "--baud requires an argument\n");
			syntax_print();
			return 1;
		}
		char *endptr;
		baud = strtol(arg_str, &endptr, 10);
		if (*endptr != '\0') {
			fprintf(stderr, "Invalid value for baud\n");
			syntax_print();
			return 1;
		}
		arg++;
	}

	if (argc > arg) {
		rc = loc_service_get_id(argv[arg], &svc_id, 0);
		if (rc != EOK) {
			fprintf(stderr, "Cannot find device service %s\n",
			    argv[arg]);
			return 1;
		}
		arg++;
	}
	else {
		category_id_t serial_cat_id;

		rc = loc_category_get_id("serial", &serial_cat_id, 0);
		if (rc != EOK) {
			fprintf(stderr, "Failed getting id of category "
			    "'serial'\n");
			return 1;
		}

		service_id_t *svc_ids;
		size_t svc_count;

		rc = loc_category_get_svcs(serial_cat_id, &svc_ids, &svc_count);
		if (rc != EOK) {
			fprintf(stderr, "Failed getting list of services\n");
			return 1;
		}

		if (svc_count == 0) {
			fprintf(stderr, "No service in category 'serial'\n");
			free(svc_ids);
			return 1;
		}

		svc_id = svc_ids[0];
		free(svc_ids);
	}

	if (argc > arg) {
		fprintf(stderr, "Too many arguments\n");
		syntax_print();
		return 1;
	}


	async_sess_t *sess = loc_service_connect(svc_id, INTERFACE_DDF,
	    IPC_FLAG_BLOCKING);
	if (!sess) {
		fprintf(stderr, "Failed connecting to service\n");
	}

	async_exch_t *exch = async_exchange_begin(sess);
	rc = async_req_4_0(exch, SERIAL_SET_COM_PROPS, baud,
	    SERIAL_NO_PARITY, 8, 1);
	async_exchange_end(exch);

	if (rc != EOK) {
		fprintf(stderr, "Failed setting serial properties\n");
		return 2;
	}

	uint8_t *buf = (uint8_t *) malloc(BUF_SIZE);
	if (buf == NULL) {
		fprintf(stderr, "Failed allocating buffer\n");
		return 3;
	}

	while (true) {
		ssize_t read = char_dev_read(sess, buf, BUF_SIZE);
		if (read < 0) {
			fprintf(stderr, "Failed reading from serial device\n");
			break;
		}
		ssize_t i;
		for (i = 0; i < read; i++) {
			printf("%02hhx ", buf[i]);
		}
		fflush(stdout);
	}

	free(buf);
	return 0;
}