Exemplo n.º 1
0
Arquivo: scan.c Projeto: jolin90/dbus
int main(int argc, char *argv[])
{
    DBusConnection *conn;
    struct ADAPTER_PROPERTIES *p;

    conn = init_dbus();

    p = (struct ADAPTER_PROPERTIES *)malloc(sizeof(struct ADAPTER_PROPERTIES));
    p->DiscoverableTimeout = 0;
    p->PairableTimeout = 0;
    p->Pairable = true;
    p->Discoverable = true;
    set_property(conn, "DiscoverableTimeout", p);
    set_property(conn, "PairableTimeout", p);
    set_property(conn, "Pairable", p);
    set_property(conn, "Discoverable", p);
    free(p);

    get_properties(conn);

    printf("%s %d\n", __func__, __LINE__);
    start_discovery(conn);
    printf("%s %d\n", __func__, __LINE__);

    return 0;
}
Exemplo n.º 2
0
static gboolean
init (NstPlugin *plugin)
{
	g_print ("Init gajim plugin\n");

	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	
	/* connect to gajim dbus service */
	jid_table = g_hash_table_new (g_str_hash, g_str_equal);
	if (!init_dbus()) {
		return FALSE;
	}
	return TRUE;
}
Exemplo n.º 3
0
Arquivo: uhvm.c Projeto: mjessome/uhvm
static int
init_uhvm(void)
{
    DBusError error;

    dbus_error_init(&error);
    if (init_dbus(&error) < 0) {
        if (dbus_error_is_set(&error)) {
            syslog(LOG_ERR, "%s:%d: %s:%s", __FILE__, __LINE__,
                   error.name, error.message);
            dbus_error_free(&error);
            return -1;
        }
    }

    return init_hal();
}
Exemplo n.º 4
0
int
xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg)
{
	gboolean success;

	xchat_plugin_get_info (plugin_name, plugin_desc, plugin_version, NULL);

	ph = plugin_handle;

	success = init_dbus ();
	if (success) {
		xchat_hook_print (ph, "Motd",         XCHAT_PRI_NORM, connected_cb, NULL);
		xchat_hook_print (ph, "MOTD Skipped", XCHAT_PRI_NORM, connected_cb, NULL);
		
		xchat_find_set_context (ph);
		xchat_printf (ph, _("%s loaded successfully\n"), NET_MONITOR_NAME);
	}
	return success;
}
Exemplo n.º 5
0
Arquivo: cneod.c Projeto: fgau/cneo
int
main(int argc, char **argv)
{
	init_signals();

	if (init_dbus() < 0) {
		fprintf(stderr, "Cannot initialize DBus\n");
		return 1;
	}

	while (dbus_connection_read_write(conn, -1)) {
		while (dbus_connection_dispatch(conn) != DBUS_DISPATCH_COMPLETE) {
		}
	}

	shutdown_dbus();

	return 0;
}
static int send_thermal_mgr_event(bool activated) {
	DBusConnection* conn = NULL;
	int result;
	char *msg_value = activated ? STE_MAD_FEATURE_ON : STE_MAD_FEATURE_OFF;

	result = init_dbus(&conn);
	if (result < 0) {
		ERR("failed to init DBUS\n");
		return result;
	}

	result = send_dbus_signal(conn, STE_MAD_TXBO_THERMAL_MANAGER,
				msg_value);
	if (result < 0) {
		ERR("DBUS message failed to send\n");
	}

	if (conn) {
		dbus_connection_unref(conn);
	}

	return result;
}
Exemplo n.º 7
0
int API
main (int argc, char *argv[], char *envp[])
{
  initalize_syslog ();
  struct state state;
  /* TODO(wad) EVENT_BASE_FLAG_PRECISE_TIMER | EVENT_BASE_FLAG_PRECISE_TIMER */
  struct event_base *base = event_base_new();
  if (!base)
    {
      fatal ("could not allocated new event base");
    }
  /* Add three priority levels:
   * 0 - time saving.  Must be done before any other events are handled.
   * 1 - network synchronization events
   * 2 - any other events (wake, platform, etc)
   */
  event_base_priority_init (base, MAX_EVENT_PRIORITIES);
  memset (&state, 0, sizeof (state));
  set_conf_defaults (&state.opts);
  parse_argv (&state.opts, argc, argv);
  check_conf (&state);
  load_conf (&state.opts);
  check_conf (&state);
  if (!state.opts.sources)
    add_source_to_conf (&state.opts, DEFAULT_HOST, DEFAULT_PORT, DEFAULT_PROXY);
  state.base = base;
  state.envp = envp;
  state.backoff = state.opts.wait_between_tries;
  /* TODO(wad) move this into setup_time_setter */
  /* grab a handle to /dev/rtc for time-setter. */
  if (state.opts.should_sync_hwclock &&
      platform->rtc_open(&state.hwclock))
    {
      pinfo ("can't open hwclock fd");
      state.opts.should_sync_hwclock = 0;
    }
  /* install the SIGCHLD handler for the setter and tlsdate */
  if (setup_sigchld_event (&state, 1))
    {
      error ("Failed to setup SIGCHLD event");
      goto out;
    }
  /* fork off the privileged helper */
  info ("spawning time setting helper . . .");
  if (setup_time_setter (&state))
    {
      error ("could not fork privileged coprocess");
      goto out;
    }
  /* release the hwclock now that the time-setter is running. */
  if (state.opts.should_sync_hwclock)
    {
      platform->rtc_close (&state.hwclock);
    }
  /* drop privileges before touching any untrusted data */
  drop_privs_to (state.opts.user, state.opts.group);
  /* register a signal handler to save time at shutdown */
  if (state.opts.should_save_disk)
    {
      struct event *event = event_new (base, SIGTERM, EV_SIGNAL|EV_PERSIST,
                                       action_sigterm, &state);
      if (!event)
        fatal ("Failed to create SIGTERM event");
      event_priority_set (event, PRI_SAVE);
      event_add (event, NULL);
    }
  if (state.opts.should_dbus && init_dbus (&state))
    {
      error ("Failed to initialize DBus");
      goto out;
    }
  /* Register the tlsdate event before any listeners could show up. */
  state.events[E_TLSDATE] = event_new (base, -1, EV_TIMEOUT,
                                       action_run_tlsdate, &state);
  if (!state.events[E_TLSDATE])
    {
      error ("Failed to create tlsdate event");
      goto out;
    }
  event_priority_set (state.events[E_TLSDATE], PRI_NET);
  /* The timeout and fd will be filled in per-call. */
  if (setup_tlsdate_status (&state))
    {
      error ("Failed to create tlsdate status event");
      goto out;
    }
  /* TODO(wad) Could use a timeout on this to catch setter death? */
  /* EV_READ is for truncation/EPIPE notification */
  state.events[E_SAVE] = event_new (base, state.setter_save_fd,
                                    EV_READ|EV_WRITE, action_sync_and_save,
                                    &state);
  if (!state.events[E_SAVE])
    {
      error ("Failed to create sync & save event");
      goto out;
    }
  event_priority_set (state.events[E_SAVE], PRI_SAVE);
  /* Start by grabbing the system time. */
  state.last_sync_type = SYNC_TYPE_RTC;
  state.last_time = time (NULL);
  /* If possible, grab disk time and check the two. */
  if (state.opts.should_load_disk)
    {
      time_t disk_time = state.last_time;
      if (!load_disk_timestamp (state.timestamp_path, &disk_time))
        {
          info ("disk timestamp available: yes");
          if (!is_sane_time (state.last_time) ||
              state.last_time < disk_time)
            {
              state.last_sync_type = SYNC_TYPE_DISK;
              state.last_time = disk_time;
            }
        }
      else
        {
          info ("disk timestamp available: no");
        }
    }
  if (!is_sane_time (state.last_time))
    {
      state.last_sync_type = SYNC_TYPE_BUILD;
      state.last_time = RECENT_COMPILE_DATE + 1;
    }
  /* Save and announce the initial time source. */
  trigger_event (&state, E_SAVE, -1);
  info ("initial time sync type: %s", sync_type_str (state.last_sync_type));
  /* Initialize platform specific loop behavior */
  if (platform_init_cros (&state))
    {
      error ("Failed to initialize platform code");
      goto out;
    }
  if (setup_event_route_up (&state))
    {
      error ("Failed to setup route up monitoring");
      goto out;
    }
  if (setup_event_timer_sync (&state))
    {
      error ("Failed to setup a timer event");
      goto out;
    }
  if (setup_event_timer_continuity (&state))
    {
      error ("Failed to setup continuity timer");
      goto out;
    }
  /* Add a forced sync event to the event list. */
  action_kickoff_time_sync (-1, EV_TIMEOUT, &state);
  info ("Entering dispatch . . .");
  event_base_dispatch (base);
  info ("tlsdated terminating gracefully");
out:
  return cleanup_main (&state);
}
Exemplo n.º 8
0
gint main(gint argc, gchar *argv[])
{
	gint ret = 0;
	struct con_win *cwin;

	cwin = g_slice_new0(struct con_win);
	cwin->pixbuf = g_slice_new0(struct pixbuf);
	cwin->cpref = g_slice_new0(struct con_pref);
	cwin->cstate = g_slice_new0(struct con_state);
	cwin->cdbase = g_slice_new0(struct con_dbase);
	cwin->cmixer = g_slice_new0(struct con_mixer);
	cwin->clibao = g_slice_new0(struct con_libao);
	cwin->clastfm = g_slice_new0(struct con_lastfm);
	#if HAVE_GLIB_2_26
	cwin->cmpris2 = g_slice_new0(struct con_mpris2);
	#endif

	if(init_first_state(cwin) == -1)
		return -1;

	debug_level = 0;

	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	if (init_dbus(cwin) == -1) {
		g_critical("Unable to init dbus connection");
		return -1;
	}

	if (init_dbus_handlers(cwin) == -1) {
		g_critical("Unable to initialize DBUS filter handlers");
		return -1;
	}

	if (init_options(cwin, argc, argv) == -1)
		return -1;

	/* Allow only one instance */

	if (!cwin->cstate->unique_instance)
		return 0;

	if (init_config(cwin) == -1) {
		g_critical("Unable to init configuration");
		return -1;
	}

	if (init_musicdbase(cwin) == -1) {
		g_critical("Unable to init music dbase");
		return -1;
	}

	ret = init_audio(cwin);
	if (ret == -EINVAL) {
		g_critical("Unable to init audio");
		return -1;
	} else if (ret == -ENODEV) {
		g_critical("Audio init failed, choose appropriate settings "
			   "from the preferences.");
	}

	/* Init libcurl before spawning threads */

	if (init_lastfm(cwin) == -1) {
		g_critical("Unable to initialize curl");
	}

	if (init_threads(cwin) == -1) {
		g_critical("Unable to init threads");
		return -1;
	}

	if (init_notify(cwin) == -1) {
		g_critical("Unable to initialize libnotify");
		return -1;
	}

	#ifdef HAVE_LIBKEYBINDER
	if (init_keybinder(cwin) == -1) {
		g_critical("Unable to initialize keybinder");
		return -1;
	}
	#endif

	#ifdef HAVE_LIBGLYR
	if (init_glyr_related(cwin) == -1) {
		g_critical("Unable to initialize libglyr");
	}
	#endif

	#if HAVE_GLIB_2_26
	if (mpris_init(cwin) == -1) {
		g_critical("Unable to initialize MPRIS");
		return -1;
	}
	#endif

	gdk_threads_enter();
	init_gui(argc, argv, cwin);
	CDEBUG(DBG_INFO, "Init done. Running ...");
	gtk_main();
	gdk_threads_leave();

	return 0;
}