Ejemplo n.º 1
0
Archivo: os.c Proyecto: Pachot/mlworks
extern void os_init(void)
{
  word x = check_windows();
  if (x)
    error ("This computer requires a Sun kernel "
	   "patch before this application will run.\n"
           "Please contact the application's vendor "
	   "for details of the patch required.");
  pioc_init();
  unix_init();
  x_init();
}
Ejemplo n.º 2
0
static int unix_strtoaddr_ex(const char *str, struct sockaddr_un *add)
{
    char *cp;
    if (!unix_init ())
        return 0;
    TRC(fprintf(stderr, "unix_strtoaddress: %s\n", str ? str : "NULL"));
    add->sun_family = AF_UNIX;
    strncpy(add->sun_path, str, sizeof(add->sun_path)-1);
    add->sun_path[sizeof(add->sun_path)-1] = 0;
    cp = strchr (add->sun_path, ':');
    if (cp)
        *cp = '\0';
    return 1;
}
Ejemplo n.º 3
0
static int audio_init(void)
{
	GKeyFile *config;
	gboolean enable_sco;

	connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
	if (connection == NULL)
		return -EIO;

	config = load_config_file(CONFIGDIR "/audio.conf");

	if (unix_init() < 0) {
		error("Unable to setup unix socket");
		goto failed;
	}

	if (audio_manager_init(connection, config, &enable_sco) < 0)
		goto failed;

	if (!enable_sco)
		return 0;

	sco_server = bt_io_listen(BT_IO_SCO, sco_server_cb, NULL, NULL,
					NULL, NULL,
					BT_IO_OPT_INVALID);
	if (!sco_server) {
		error("Unable to start SCO server socket");
		goto failed;
	}

	return 0;

failed:
	audio_manager_exit();
	unix_exit();

	if (connection) {
		dbus_connection_unref(connection);
		connection = NULL;
	}

	return -EIO;
}
Ejemplo n.º 4
0
/*
 * This function is always called through the cs_create() macro.
 * s >= 0: socket has already been established for us.
 */
COMSTACK unix_type(int s, int flags, int protocol, void *vp)
{
    COMSTACK p;
    unix_state *state;
    int new_socket;

    if (!unix_init ())
        return 0;
    if (s < 0)
    {
        if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
            return 0;
        new_socket = 1;
    }
    else
        new_socket = 0;
    if (!(p = (struct comstack *)xmalloc(sizeof(struct comstack))))
        return 0;
    if (!(state = (struct unix_state *)(p->cprivate =
                                        xmalloc(sizeof(unix_state)))))
        return 0;

    p->flags = flags;
    if (!(p->flags&CS_FLAGS_BLOCKING))
    {
        if (fcntl(s, F_SETFL, O_NONBLOCK) < 0)
            return 0;
#ifndef MSG_NOSIGNAL
        signal (SIGPIPE, SIG_IGN);
#endif
    }

    p->io_pending = 0;
    p->iofile = s;
    p->type = unix_type;
    p->protocol = (enum oid_proto) protocol;

    p->f_connect = unix_connect;
    p->f_rcvconnect = unix_rcvconnect;
    p->f_get = unix_get;
    p->f_put = unix_put;
    p->f_close = unix_close;
    p->f_more = unix_more;
    p->f_bind = unix_bind;
    p->f_listen = unix_listen;
    p->f_accept = unix_accept;
    p->f_addrstr = unix_addrstr;
    p->f_straddr = unix_straddr;
    p->f_set_blocking = unix_set_blocking;

    p->state = new_socket ? CS_ST_UNBND : CS_ST_IDLE; /* state of line */
    p->event = CS_NONE;
    p->cerrno = 0;
    p->stackerr = 0;
    p->user = 0;

    state->altbuf = 0;
    state->altsize = state->altlen = 0;
    state->towrite = state->written = -1;
    if (protocol == PROTO_WAIS)
        state->complete = completeWAIS;
    else
        state->complete = cs_complete_auto;

    p->timeout = COMSTACK_DEFAULT_TIMEOUT;
    TRC(fprintf(stderr, "Created new UNIX comstack\n"));

    return p;
}
Ejemplo n.º 5
0
int
main (int UNUSED (argc), char *argv[])
{
  int chan;			/* temporary channel number */
#ifdef SYSV_IPC
  struct msgbuf *msgp;		/* message buffer */
#else
  int ils = -1;			/* internet domain listen socket */
  int uls = -1;			/* unix domain listen socket */
#endif /* SYSV_IPC */

  progname = argv[0];

  for(chan=3; chan < _NFILE; close(chan++)) /* close unwanted channels */
    ;


#ifdef WIN32_NATIVE
  tmpdir = getenv ("TEMP");
  if (!tmpdir)
    tmpdir = getenv ("TMP");
  if (!tmpdir)
    tmpdir = "c:\\";
#else
#ifdef USE_TMPDIR
  tmpdir = getenv ("TMPDIR");
#endif
  if (!tmpdir)
    tmpdir = "/tmp";
#endif /* WIN32_NATIVE */
#ifdef USE_LITOUT
  {
    /* this is to allow ^D to pass to emacs */
    int d = LLITOUT;
    (void) ioctl(fileno(stdout), TIOCLBIS, &d);
  }
#endif

#ifdef SYSV_IPC
  ipc_init(&msgp);		/* get a msqid to listen on, and a message buffer */
#endif /* SYSV_IPC */

#ifdef INTERNET_DOMAIN_SOCKETS
  ils = internet_init();	/* get an internet domain socket to listen on */
#endif /* INTERNET_DOMAIN_SOCKETS */

#ifdef UNIX_DOMAIN_SOCKETS
  uls = unix_init();		/* get a unix domain socket to listen on */
#endif /* UNIX_DOMAIN_SOCKETS */

  while (1) {
#ifdef SYSV_IPC
    handle_ipc_request(msgp);
#else /* NOT SYSV_IPC */
    fd_set rmask;
    FD_ZERO(&rmask);
    FD_SET(fileno(stdin), &rmask);
    if (uls >= 0)
      FD_SET(uls, &rmask);
    if (ils >= 0)
      FD_SET(ils, &rmask);

    if (select(max2(fileno(stdin),max2(uls,ils)) + 1, &rmask,
	       (fd_set *)NULL, (fd_set *)NULL, (struct timeval *)NULL) < 0)
      {
	perror(progname);
	fprintf(stderr,"%s: unable to select\n",progname);
	return 1;
      } /* if */

#ifdef UNIX_DOMAIN_SOCKETS
    if (uls > 0 && FD_ISSET(uls, &rmask))
      handle_unix_request(uls);
#endif

#ifdef INTERNET_DOMAIN_SOCKETS
    if (ils > 0 && FD_ISSET(ils, &rmask))
      handle_internet_request(ils);
#endif /* INTERNET_DOMAIN_SOCKETS */

    if (FD_ISSET(fileno(stdin), &rmask))      /* from stdin (gnu process) */
      handle_response();
#endif /* NOT SYSV_IPC */
  } /* while (1) */
} /* main */
Ejemplo n.º 6
0
int audio_manager_init(DBusConnection *conn, GKeyFile *conf,
							gboolean *enable_sco)
{
	char **list;
	int i;
	char *str;
	gboolean b;
	GError *err = NULL;

	connection = dbus_connection_ref(conn);

	if (!conf)
		goto proceed;

	config = conf;

	list = g_key_file_get_string_list(config, "General", "Enable",
						NULL, NULL);
	for (i = 0; list && list[i] != NULL; i++) {
		if (g_str_equal(list[i], "Headset"))
			enabled.headset = TRUE;
		else if (g_str_equal(list[i], "Gateway"))
			enabled.gateway = TRUE;
		else if (g_str_equal(list[i], "Sink"))
			enabled.sink = TRUE;
		else if (g_str_equal(list[i], "Source"))
			enabled.source = TRUE;
		else if (g_str_equal(list[i], "Control"))
			enabled.control = TRUE;
		else if (g_str_equal(list[i], "Socket"))
			enabled.socket = TRUE;
		else if (g_str_equal(list[i], "Media"))
			enabled.media = TRUE;
	}
	g_strfreev(list);

	list = g_key_file_get_string_list(config, "General", "Disable",
						NULL, NULL);
	for (i = 0; list && list[i] != NULL; i++) {
		if (g_str_equal(list[i], "Headset"))
			enabled.headset = FALSE;
		else if (g_str_equal(list[i], "Gateway"))
			enabled.gateway = FALSE;
		else if (g_str_equal(list[i], "Sink"))
			enabled.sink = FALSE;
		else if (g_str_equal(list[i], "Source"))
			enabled.source = FALSE;
		else if (g_str_equal(list[i], "Control"))
			enabled.control = FALSE;
		else if (g_str_equal(list[i], "Socket"))
			enabled.socket = FALSE;
		else if (g_str_equal(list[i], "Media"))
			enabled.media = FALSE;
	}
	g_strfreev(list);

	b = g_key_file_get_boolean(config, "General", "AutoConnect", &err);
	if (err) {
		DBG("audio.conf: %s", err->message);
		g_clear_error(&err);
	} else
		auto_connect = b;

	b = g_key_file_get_boolean(config, "Headset", "HFP",
					&err);
	if (err)
		g_clear_error(&err);
	else
		enabled.hfp = b;

	err = NULL;
	i = g_key_file_get_integer(config, "Headset", "MaxConnected",
					&err);
	if (err) {
		DBG("audio.conf: %s", err->message);
		g_clear_error(&err);
	} else
		max_connected_headsets = i;

	str = g_key_file_get_string(config, "WBspeech",
						"I2sEnable", &err);
	if (err)
		g_clear_error(&err);
	else {
		wbs_commands_param.I2sEnable = strtol(str, NULL, 16);
	}

	str = g_key_file_get_string(config, "WBspeech",
						"IsMaster", &err);
	if (err)
		g_clear_error(&err);
	else {
		wbs_commands_param.IsMaster = strtol(str, NULL, 16);
	}

	str = g_key_file_get_string(config, "WBspeech",
						"ClockRate", &err);
	if (err)
		g_clear_error(&err);
	else {
		wbs_commands_param.ClockRate = strtol(str, NULL, 16);
	}


	str = g_key_file_get_string(config, "WBspeech",
						"PcmInterfaceRate", &err);
	if (err)
		g_clear_error(&err);
	else {
		wbs_commands_param.PcmInterfaceRate = strtol(str, NULL, 16);
	}

proceed:
	if (enabled.socket)
		unix_init();

	if (enabled.media)
		btd_register_adapter_driver(&media_server_driver);

	if (enabled.headset)
		btd_register_adapter_driver(&headset_server_driver);

	if (enabled.gateway)
		btd_register_adapter_driver(&gateway_server_driver);

	if (enabled.source || enabled.sink)
		btd_register_adapter_driver(&a2dp_server_driver);

	if (enabled.control)
		btd_register_adapter_driver(&avrcp_server_driver);

	btd_register_device_driver(&audio_driver);

	*enable_sco = (enabled.gateway || enabled.headset);

	return 0;
}