Example #1
0
void OMXControl::init(OMXClock *m_av_clock, OMXPlayerAudio *m_player_audio, OMXPlayerSubtitles *m_player_subtitles, OMXReader *m_omx_reader, std::string& dbus_name)
{
  clock     = m_av_clock;
  audio     = m_player_audio;
  subtitles = m_player_subtitles;
  reader    = m_omx_reader;

  if (dbus_connect(dbus_name) < 0)
  {
    CLog::Log(LOGWARNING, "DBus connection failed, trying alternate");
    dbus_disconnect();
    std::stringstream ss;
    ss << getpid();
    dbus_name += ".instance";
    dbus_name += ss.str();
    if (dbus_connect(dbus_name) < 0)
    {
      CLog::Log(LOGWARNING, "DBus connection failed, alternate failed, will continue without DBus");
      dbus_disconnect();
    } else {
      CLog::Log(LOGDEBUG, "DBus connection succeeded");
      dbus_threads_init_default();
    }
  }
  else
  {
    CLog::Log(LOGDEBUG, "DBus connection succeeded");
    dbus_threads_init_default();
  }
}
Example #2
0
wxDBusConnection::wxDBusConnection(int ID, wxEvtHandler * EvtHandler, bool System)
{
	// Make sure libdbus locks its data structures, otherwise
	// there'll be crashes if it gets used from multiple threads
	// at the same time
	dbus_threads_init_default();

	m_error = new wxDBusError;
	m_connection = System ? dbus_bus_get(DBUS_BUS_SYSTEM, &(m_error->GetError())) : dbus_bus_get(DBUS_BUS_SESSION, &(m_error->GetError()));
	if (!m_connection) {
		fprintf(stderr, "Failed to connect to D-BUS: %s\n", m_error->GetError().message);
	}
	else
	{
		m_filter_installed = dbus_connection_add_filter(m_connection, handle_message, (void *) this, NULL);
		m_ID = ID;
		m_EvtHandler = EvtHandler;
		m_thread = new DBusThread(wxTHREAD_JOINABLE, this, ID, m_connection);
		if (!m_thread->Init())
		{
			fprintf(stderr, "Failed to create worker thread\n");
			delete m_thread;
			m_thread = NULL;

			if (m_filter_installed)
			{
				dbus_connection_remove_filter(m_connection, handle_message, (void *) this);
				m_filter_installed = false;
			}

			dbus_connection_unref(m_connection);
			m_connection = 0;
		}
	}
}
Example #3
0
Keyboard::Keyboard() 
{
  if (isatty(STDIN_FILENO)) 
  {
    struct termios new_termios;

    tcgetattr(STDIN_FILENO, &orig_termios);

    new_termios = orig_termios;
    new_termios.c_lflag &= ~(ICANON | ECHO | ECHOCTL | ECHONL);
    new_termios.c_cflag |= HUPCL;
    new_termios.c_cc[VMIN] = 0;

    tcsetattr(STDIN_FILENO, TCSANOW, &new_termios);
  } 
  else 
  {    
    orig_fl = fcntl(STDIN_FILENO, F_GETFL);
    fcntl(STDIN_FILENO, F_SETFL, orig_fl | O_NONBLOCK);
  }

  if (dbus_connect() < 0)
  {
    CLog::Log(LOGWARNING, "DBus connection failed");
  } 
  else 
  {
    CLog::Log(LOGDEBUG, "DBus connection succeeded");
  }

  dbus_threads_init_default();
  Create();
}
void* SignalsInit(BridgeService* service, pthread_mutex_t* startLock, char* compressed_rule)
{
	DBusError dbusError;
	dbus_error_init(&dbusError);

	Signals* signals = malloc(sizeof(Signals));
	signals->con = dbus_bus_get_private(FLAGS_bustype, &dbusError);
	signals->service = service;
	signals->startLock = startLock;

	if(dbus_error_is_set(&dbusError))
	{
		fprintf(stderr, "%s %d MethodInit Error occurred: %s %s\n", __FILE__, __LINE__,  dbusError.name, dbusError.message);
		free(signals);
		return NULL;
	}
	pthread_mutex_init(&signals->dbus_mutex, NULL);

	signals->work = 1;
	dbus_threads_init_default();
    char* busname = compressed_rule;
    char* objectpath = busname + strlen(busname) + 1;
    char* interfacename = objectpath + strlen(objectpath) + 1;
    char* signalname = interfacename + strlen(interfacename) + 1;
	addSignalWatch(signals, busname, objectpath, interfacename, signalname);
	pthread_create(&signals->dbusSignalWatcher, NULL, signalWatch, signals);

	return signals;
}
Example #5
0
static void
setup (Fixture *f,
    gconstpointer data)
{
  if (!dbus_threads_init_default ())
    g_error ("OOM");

  f->loop = _dbus_loop_new ();
  g_assert (f->loop != NULL);

  dbus_error_init (&f->e);

  f->server = dbus_server_listen ("tcp:host=127.0.0.1", &f->e);
  assert_no_error (&f->e);
  g_assert (f->server != NULL);

  if (!dbus_connection_allocate_data_slot (&connection_slot))
    g_error ("OOM");

  if (!dbus_server_allocate_data_slot (&server_slot))
    g_error ("OOM");

  if (!dbus_message_allocate_data_slot (&message_slot))
    g_error ("OOM");

  if (!dbus_pending_call_allocate_data_slot (&pending_call_slot))
    g_error ("OOM");
}
Example #6
0
void
daemon_init (void)
{
  DBusConnection *connection;
  DBusError derror;

  setlocale (LC_ALL, "");

  bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);
  
  dbus_threads_init_default ();
  g_thread_init (NULL);
  g_type_init ();

  g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, log_debug, NULL);

  
  dbus_error_init (&derror);
  connection = dbus_bus_get (DBUS_BUS_SESSION, &derror);
  if (connection == NULL)
    {
      g_printerr (_("Error connecting to D-Bus: %s"), derror.message);
      g_printerr ("\n");
      dbus_error_free (&derror);
      exit (1);
    }
}
Example #7
0
Client::Client()
    : mMode(INIT) {
	// Making sure dbus is operating in a thread safe manner
        dbus_threads_init_default();
        bool runningDaemonRequired = true;
        start(runningDaemonRequired);
}
bool
DBusThread::SetUpEventLoop()
{
  // If we already have a connection, exit
  if (mConnection) {
    return false;
  }

  dbus_threads_init_default();
  DBusError err;
  dbus_error_init(&err);

  // If we can't establish a connection to dbus, nothing else will work
  nsresult rv = EstablishDBusConnection();
  if (NS_FAILED(rv)) {
    NS_WARNING("Cannot create DBus Connection for DBus Thread!");
    return false;
  }

  // Set which messages will be processed by this dbus connection.
  // Since we are maintaining a single thread for all the DBus bluez
  // signals we want, register all of them in this thread at startup.
  // The event handler will sort the destinations out as needed.
  for (uint32_t i = 0; i < ArrayLength(DBUS_SIGNALS); ++i) {
    dbus_bus_add_match(mConnection,
                       DBUS_SIGNALS[i],
                       &err);
    if (dbus_error_is_set(&err)) {
      LOG_AND_FREE_DBUS_ERROR(&err);
      return false;
    }
  }
  return true;
}
/* Returns true on success (even if adapter is present but disabled).
 * Return false if dbus is down, or another serious error (out of memory)
*/
static bool initNative(JNIEnv* env, jobject object) {
    LOGV(__FUNCTION__);
#ifdef HAVE_BLUETOOTH
    nat = (native_data_t *)calloc(1, sizeof(native_data_t));
    if (NULL == nat) {
        LOGE("%s: out of memory!", __FUNCTION__);
        return false;
    }
    env->GetJavaVM( &(nat->vm) );
    nat->envVer = env->GetVersion();
    nat->me = env->NewGlobalRef(object);

    DBusError err;
    dbus_error_init(&err);
    dbus_threads_init_default();
    nat->conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
    if (dbus_error_is_set(&err)) {
        LOGE("Could not get onto the system bus: %s", err.message);
        dbus_error_free(&err);
        return false;
    }
    dbus_connection_set_exit_on_disconnect(nat->conn, FALSE);
#endif  /*HAVE_BLUETOOTH*/
    return true;
}
Example #10
0
void dbus_initialize(void) {
	DBusError err;

	dbus_threads_init_default();
	dbus_error_init(&err);

	if (!(service_bus = dbus_connection_open(SERVICE_BUS_ADDRESS, &err))) {
		dbus_error_free(&err);
		errx(1, "failed to connect to service bus: %s: %s", err.name, err.message);
	}

	if (!dbus_bus_register(service_bus, &err)) {
		dbus_error_free(&err);
		errx(1, "failed to register with service bus: %s: %s", err.name, err.message);
	}
	
	dbus_error_free(&err);
	
	service_thread = std::thread([]() {
		// dispatch messages until disconnect
		while (dbus_connection_read_write_dispatch(service_bus, -1));
		dbus_connection_unref(service_bus);
	});

    service_thread.detach();
}
Example #11
0
static DBusConnection *virDBusBusInit(DBusBusType type, DBusError *dbuserr)
{
    DBusConnection *bus;

    /* Allocate and initialize a new HAL context */
    dbus_connection_set_change_sigpipe(FALSE);
    dbus_threads_init_default();

    dbus_error_init(dbuserr);
    bus = sharedBus ?
        dbus_bus_get(type, dbuserr) :
        dbus_bus_get_private(type, dbuserr);
    if (!bus)
        return NULL;

    dbus_connection_set_exit_on_disconnect(bus, FALSE);

    /* Register dbus watch callbacks */
    if (!dbus_connection_set_watch_functions(bus,
                                             virDBusAddWatch,
                                             virDBusRemoveWatch,
                                             virDBusToggleWatch,
                                             bus, NULL)) {
        return NULL;
    }
    return bus;
}
Example #12
0
Q_DECL_EXPORT int main( int argc, char* argv[] )
{
    // remove this later on if not needed in harmattan,
    // this IS needed for fremantle
    dbus_threads_init_default(); // magical line making program not crash

    QCoreApplication app(argc, argv);

    // The below two lines are added as a workaround for QT bug 11413
    // http://bugreports.qt.nokia.com/browse/QTBUG-11413
    QDBusConnection::sessionBus();
    QDBusConnection::systemBus();

    // Initialize the logger
    if (qApp->arguments().contains("-d")) {
        Buteo::Logger::createInstance("", true); // log to stdout
        Buteo::Logger::instance()->setLogLevel(Buteo::Logger::NUM_LEVELS);
    } else {
        Buteo::Logger::instance();
    }

    LOG_DEBUG("Starting Log At :"  << QDateTime::currentDateTime()  );

    Buteo::Synchronizer *synchronizer = new Buteo::Synchronizer(&app);
    if (synchronizer == 0) {
        LOG_FATAL("Failed to create synchronizer");
    }

    if(!synchronizer->initialize() ) {
        delete synchronizer;
        synchronizer = 0;
        return -1;
    }

    //Note:- Since we can't call Qt functions from Unix signal handlers.
    // This class provide hanlding unix  signal.
    SyncSigHandler *sigHandler = new SyncSigHandler();

    LOG_DEBUG("Entering event loop");
    int returnValue = app.exec();
    LOG_DEBUG("Exiting event loop");

    synchronizer->close();
    delete synchronizer;
    synchronizer = 0;

    if (sigHandler) {
        delete sigHandler;
        sigHandler = 0;
    }

    LOG_DEBUG("Stopping logger");

    Buteo::Logger::deleteInstance();

    qDebug() << "Exiting program";

    return returnValue;
}
Example #13
0
/**
 * dbus_g_thread_init:
 *
 * Initializes the D-BUS thread system.
 * This function may only be called
 * once and must be called prior to calling any
 * other function in the D-BUS API.
 */
void
dbus_g_thread_init (void)
{
  if (!g_thread_supported ())
    g_error ("g_thread_init() must be called before dbus_threads_init()");

  dbus_threads_init_default ();
}
int main()
{
	DBusConnection* connection;
	DBusError error;
	int cnt;
	int data_slot = -1;
	threadData1 thrData;
	
	pthread_t thread[MAX_THREAD];
	int thrVal[MAX_THREAD]={0};
	void* thrValPtr[MAX_THREAD];
	
	for(cnt=0; cnt<MAX_THREAD; cnt++)
		thrValPtr[cnt] = (void*)&thrVal[cnt];

	 
	dbus_error_init(&error);
	connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
	if(!connection || dbus_error_is_set(&error))
		return handle_error(&error);
	
	pthread_mutex_init(&thrData.mutex, NULL);
	pthread_cond_init(&thrData.cond, NULL);
 	thrData.ret = 0;
 	
 	dbus_connection_allocate_data_slot(&data_slot);
	dbus_connection_set_data(connection, data_slot, &thrData, NULL);
 	
 	dbus_threads_init_default();

 	for(cnt=0; cnt<MAX_THREAD; cnt++)
 		pthread_create(&thread[cnt], NULL, &send_msg1, &data_slot);
	 
	sleep(1);  
	
	pthread_cond_broadcast(&thrData.cond);
	
	for(cnt=0; cnt<MAX_THREAD; cnt++)
		pthread_join(thread[cnt], &thrValPtr[cnt]); 
	 
	if(thrData.ret != MAX_THREAD)
	{ 
		std_log(LOG_FILENAME_LINE, "No. of threads crashed %d", (MAX_THREAD - thrData.ret));
		create_xml(1);
		return 1;
	}
	 
	dbus_connection_unref(connection);
	
	std_log(LOG_FILENAME_LINE, "Test Successful"); 
	create_xml(0);
	return 0;
}
Example #15
0
OMXControl::OMXControl()
{
    if (dbus_connect() < 0)
    {
        CLog::Log(LOGWARNING, "DBus connection failed");
    }
    else
    {
        CLog::Log(LOGDEBUG, "DBus connection succeeded");
    }

    dbus_threads_init_default();
}
Example #16
0
static bool cgm_dbus_connect(void)
{
	DBusError dbus_error;
	static DBusConnection *connection;

	cgm_lock();
	if (!dbus_threads_initialized) {
		// tell dbus to do struct locking for thread safety
		dbus_threads_init_default();
		dbus_threads_initialized = true;
	}

	dbus_error_init(&dbus_error);

	connection = dbus_connection_open_private(CGMANAGER_DBUS_SOCK, &dbus_error);
	if (!connection) {
		DEBUG("Failed opening dbus connection: %s: %s",
				dbus_error.name, dbus_error.message);
		dbus_error_free(&dbus_error);
		cgm_unlock();
		return false;
	}
	dbus_connection_set_exit_on_disconnect(connection, FALSE);
	dbus_error_free(&dbus_error);
	cgroup_manager = nih_dbus_proxy_new(NULL, connection,
				NULL /* p2p */,
				"/org/linuxcontainers/cgmanager", NULL, NULL);
	dbus_connection_unref(connection);
	if (!cgroup_manager) {
		NihError *nerr;
		nerr = nih_error_get();
		ERROR("Error opening cgmanager proxy: %s", nerr->message);
		nih_free(nerr);
		cgm_dbus_disconnect();
		return false;
	}

	// get the api version
	if (cgmanager_get_api_version_sync(NULL, cgroup_manager, &api_version) != 0) {
		NihError *nerr;
		nerr = nih_error_get();
		ERROR("Error cgroup manager api version: %s", nerr->message);
		nih_free(nerr);
		cgm_dbus_disconnect();
		return false;
	}
	if (api_version < CGM_SUPPORTS_NAMED)
		cull_user_controllers();
	return true;
}
Example #17
0
/**
* Description:
*   WSM Debus initialize function
*
* Parameter:
*   NULL
*
* Return:
*   0: Successed; -1: failed
*
*/
int wsm_dbus_init(void)
{
	DBusError err;
	DBusObjectPathVTable wsm_vtbl = {NULL, &wsm_dbus_msg_handler, NULL, NULL, NULL, NULL};
	unsigned char dbus_name[WSM_PATH_MAX] = {0};
	unsigned char obj_path[WSM_PATH_MAX] = {0};

	sprintf(dbus_name, "%s%d_%d", WSM_DBUS_BUSNAME,local, vrrid);
	sprintf(obj_path, "%s%d_%d", WSM_DBUS_OBJPATH,local, vrrid);

	WSMLog(L_INFO, "%s: dbus name : %s\n", __func__, dbus_name);
	WSMLog(L_INFO, "%s: obj name : %s\n", __func__, obj_path);
	
	dbus_threads_init_default();
	dbus_connection_set_change_sigpipe (1);
	dbus_error_init (&err);
	wsm_dbus_conn = dbus_bus_get_private (DBUS_BUS_SYSTEM, &err);

	if (!wsm_dbus_conn)
	{
		WSMLog(L_CRIT, "%s: wsm_dbus_conn = NULL.\n", __func__);
		return -1;
	}

	if (!dbus_connection_register_fallback (wsm_dbus_conn, obj_path, &wsm_vtbl, NULL)) 
	{
		WSMLog(L_CRIT, "%s: register fallback failed.\n", __func__);
		return -1;
	}
	
	dbus_bus_request_name (wsm_dbus_conn, dbus_name, 0, &err);

	if (dbus_error_is_set (&err))
	{
		WSMLog(L_CRIT, "%s: dbus_bus_request_name() ERR:%s\n", __func__,
				err.message);
		return -1;
	}
	
	dbus_connection_add_filter (wsm_dbus_conn, wsm_dbus_filter_function, NULL, NULL);
	dbus_bus_add_match (wsm_dbus_conn,
				"type='signal'"
				",interface='"DBUS_INTERFACE_DBUS"'"
				",sender='"DBUS_SERVICE_DBUS"'"
				",member='NameOwnerChanged'",
				NULL);

	return 0;
}
Example #18
0
int wbmd_dbus_reinit(void)
{	
	int i = 0;
	DBusError dbus_error;
	dbus_threads_init_default();
	
	DBusObjectPathVTable	wbmd_vtable = {NULL, &wbmd_dbus_message_handler, NULL, NULL, NULL, NULL};	


	dbus_connection_set_change_sigpipe (TRUE);

	dbus_error_init (&dbus_error);
	wbmd_dbus_connection = dbus_bus_get_private (DBUS_BUS_SYSTEM, &dbus_error);
	if (wbmd_dbus_connection == NULL) {
		wbmd_syslog_err("dbus_bus_get(): %s\n", dbus_error.message);
		return FALSE;
	}

	// Use npd to handle subsection of NPD_DBUS_OBJPATH including slots
	if (!dbus_connection_register_fallback (wbmd_dbus_connection, WBMD_DBUS_OBJPATH, &wbmd_vtable, NULL)) {
		wbmd_syslog_err("can't register D-BUS handlers (fallback NPD). cannot continue.\n");
		return FALSE;
		
	}
	
	
	i = dbus_bus_request_name (wbmd_dbus_connection, WBMD_DBUS_BUSNAME,
			       0, &dbus_error);
		
	wbmd_syslog_debug_debug(WBMD_DBUS,"dbus_bus_request_name:%d",i);
	
	if (dbus_error_is_set (&dbus_error)) {
		wbmd_syslog_debug_debug(WBMD_DBUS,"dbus_bus_request_name(): %s",
			    dbus_error.message);
		return FALSE;
	}

	dbus_connection_add_filter (wbmd_dbus_connection, wbmd_dbus_filter_function, NULL, NULL);

	dbus_bus_add_match (wbmd_dbus_connection,
			    "type='signal'"
					    ",interface='"DBUS_INTERFACE_DBUS"'"
					    ",sender='"DBUS_SERVICE_DBUS"'"
					    ",member='NameOwnerChanged'",
			    NULL);
	
	return TRUE;
  
}
Example #19
0
int bsd_dbus_init(void)
{	
	int i = 0;
	DBusError dbus_error;
	dbus_threads_init_default();
	
	DBusObjectPathVTable	bsd_vtable = {NULL, &bsd_dbus_message_handler, NULL, NULL, NULL, NULL};	

	dbus_connection_set_change_sigpipe (TRUE);

	dbus_error_init (&dbus_error);
	bsd_dbus_connection = dbus_bus_get_private (DBUS_BUS_SYSTEM, &dbus_error);
	bsd_dbus_connection2 = dbus_bus_get_private (DBUS_BUS_SYSTEM, &dbus_error);

	if (bsd_dbus_connection == NULL) {
		bsd_syslog_err("dbus_bus_get(): %s\n", dbus_error.message);
		return FALSE;
	}
    
	if (!dbus_connection_register_fallback (bsd_dbus_connection, BSD_DBUS_OBJPATH, &bsd_vtable, NULL)) {
		bsd_syslog_err("can't register D-BUS handlers (fallback NPD). cannot continue.\n");
		return FALSE;
		
	}
	
	i = dbus_bus_request_name (bsd_dbus_connection, BSD_DBUS_BUSNAME,
			       0, &dbus_error);
	dbus_bus_request_name (bsd_dbus_connection2, "aw.bsd2",
			       0, &dbus_error);

	if (dbus_error_is_set (&dbus_error)) {
		bsd_syslog_debug_debug(BSD_DBUS,"dbus_bus_request_name(): %s",
			    dbus_error.message);
		return FALSE;
	}

	dbus_connection_add_filter (bsd_dbus_connection, bsd_dbus_filter_function, NULL, NULL);

	dbus_bus_add_match (bsd_dbus_connection,
			    "type='signal'"
					    ",interface='"DBUS_INTERFACE_DBUS"'"
					    ",sender='"DBUS_SERVICE_DBUS"'"
					    ",member='NameOwnerChanged'",
			    NULL);
	
//	printf("init finished\n");
	return TRUE;
  
}
Example #20
0
int dbus_provider_init(dbus_state_holder settings_struct)
{
#ifdef ENABLE_CHECKING
	if (settings_struct == NULL)
		return FALSE;
#endif
	memset(settings_struct, 0, sizeof(struct dbus_state_holder_def));
	dbus_threads_init_default();

	if (pthread_mutex_init(&(settings_struct->mutex), NULL) != 0)
		message(LOG_ERROR, FACILITY_THREADING | FACILITY_DBUS,
				"can't init dbus mutex\n");

	return TRUE;
}
void NetworkStatus::InitializeLoop()
{
    statusCheckWork = new kroll::KFunctionPtrMethod(&StatusCheckWork);

    g_type_init();
    dbus_threads_init_default();

    GError* error = 0;
    bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);

    if (!bus)
    {
        Logger::Get("NetworkStatus")->Error(
            "Could not connect to dbus: %s", error->message);
    }
}
static void initializeNativeDataNative(JNIEnv* env, jobject object) {
    LOGV(__FUNCTION__);

#ifdef HAVE_BLUETOOTH
    if (conn == NULL) {
        DBusError err;
        dbus_error_init(&err);
        dbus_threads_init_default();
        conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
        if (dbus_error_is_set(&err)) {
            LOGE("Could not get onto the system bus!");
            dbus_error_free(&err);
        }
    }
#endif
}
Example #23
0
int main(int argc, char *argv[]) {

    pthread_t *threads;
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    int i, j, nthreads = 5, iterations=5, opt;

    while ((opt = getopt_long(argc, argv, "j:i:c", options, NULL)) != -1) {
        switch(opt) {
            case 'j':
                nthreads = atoi(optarg);
                break;
            case 'i':
                iterations = atoi(optarg);
                break;
	    case 'c':
	    	connect_only = true;
		break;
            default:
                usage(argv[0]);
                exit(1);
        }
    }
    dbus_threads_init_default();
    threads = malloc(sizeof(*threads) * nthreads);
    pthread_attr_init(&attr);

    for (i = 0; i < iterations; i++) {
        for (j = 0; j < nthreads; j++) {
            if (pthread_create(&threads[j], &attr, concurrent, NULL) != 0) {
                perror("pthread_create() error");
                exit(1);
            }

        }
        for (j = 0; j < nthreads; j++) {
            if (pthread_join(threads[j], NULL) != 0) {
                perror("pthread_join() error");
                exit(EXIT_FAILURE);
            }
        }
    }

    pthread_attr_destroy(&attr);
    free(threads);
    exit(0);
}
Example #24
0
int fluid_rtkit_make_realtime(pid_t thread, int priority) {
	DBusConnection *conn = NULL;
	DBusError error;
	int max_prio, res;
	long long max_rttime;
	struct rlimit old_limit, new_limit;

	if (!dbus_threads_init_default())
		return -ENOMEM;

	/* Initialize system bus connection */
	dbus_error_init(&error);
	conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
	if (conn == NULL) {
		res = translate_error(error.name);
        	dbus_error_free(&error);
		return res;
	}
        dbus_error_free(&error);
	
	/* Make sure we don't fail by wanting too much */
	max_prio = rtkit_get_max_realtime_priority(conn);
	if (max_prio < 0) 
                MAKE_REALTIME_RETURN(max_prio);

	if (priority >= max_prio) 
		priority = max_prio;
	
	/* Enforce RLIMIT_RTTIME, also a must for obtaining rt prio through rtkit */
	max_rttime = rtkit_get_rttime_nsec_max(conn);
	if (max_rttime < 0)
		MAKE_REALTIME_RETURN(max_rttime);
	new_limit.rlim_cur = new_limit.rlim_max = max_rttime;
	if (getrlimit(RLIMIT_RTTIME, &old_limit) < 0) 
		MAKE_REALTIME_RETURN(-1);
	if (setrlimit(RLIMIT_RTTIME, &new_limit) < 0)
		MAKE_REALTIME_RETURN(-1);
	
	/* Finally, let's try */
	res = rtkit_make_realtime(conn, thread, priority);
	if (res != 0) {
		setrlimit(RLIMIT_RTTIME, &old_limit);
	}
	MAKE_REALTIME_RETURN(res);
	
}
Example #25
0
/**
 * Init dbus for usb_moded
 *
 * @return TRUE when everything went ok
 */
gboolean usb_moded_dbus_init(void)
{
  gboolean status = FALSE;
  DBusError error;
  int ret;

  dbus_error_init(&error);

  /* connect to system bus */
  if ((dbus_connection_sys = dbus_bus_get(DBUS_BUS_SYSTEM, &error)) == NULL) 
  {
   	log_debug("Failed to open connection to system message bus; %s\n",  error.message);
        goto EXIT;
  }

  /* Initialise message handlers */
  if (!dbus_connection_add_filter(dbus_connection_sys, msg_handler, NULL, NULL)) 
   	goto EXIT;

  /* Acquire D-Bus service */
  ret = dbus_bus_request_name(dbus_connection_sys, USB_MODE_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, &error);
  if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) 
  {
	log_debug("failed claiming dbus name\n");
	if( dbus_error_is_set(&error) )
		log_debug("DBUS ERROR: %s, %s \n", error.name, error.message);
        goto EXIT;
  }

  /* only match on signals/methods we support (if needed)
  dbus_bus_add_match(dbus_connection_sys, USB_MODE_INTERFACE, &error);
  */

  dbus_threads_init_default();

  /* Connect D-Bus to the mainloop */
  dbus_connection_setup_with_g_main(dbus_connection_sys, NULL);

  /* everything went fine */
  status = TRUE;

EXIT:		
  dbus_error_free(&error);
  return status;
}
int main(int argc, char *argv[])
{
	GError *error = NULL;
	gint32 err;
	g_type_init();
	g_thread_init(NULL);


	err = process_args(argc, argv);
	if (err < 0) {
		usage(argv[0]);
		exit(1);
	}

	dbus_g_thread_init();
	dbus_threads_init_default();
	init_log("notifucation_test", verbose);


	connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
	if (connection == NULL) {
		log(LOG_ERR, "Can't connect to system bus: %s\n",
		    error->message);
		g_error_free(error);
		return -1;
	}

	proxy = dbus_g_proxy_new_for_name(connection, "com.test.Notification",
					  "/com/test/Notification", "com.test.Notification");
        dbus_g_proxy_add_signal(proxy, "Notify",G_TYPE_INVALID);
        dbus_g_proxy_connect_signal(proxy, "Notify", test_callback, NULL, NULL);

//        proxy = dbus_g_proxy_new_for_name(connection, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus");

 //       dbus_g_proxy_add_signal(proxy, "NameOwnerChanged", G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING, G_TYPE_INVALID);
  //      dbus_g_proxy_connect_signal(proxy, "NameOwnerChanged", test_callback, NULL, NULL);

	err = run_main_loop();
	if (err < 0) {
		log(LOG_ERR, "Can't run main loop\n");
		exit(1);
	}

	return 0;
}
static gboolean
skype_connect()
{
    GError *error = NULL;
    DBusObjectPathVTable vtable;

    //Initialise threading
    dbus_threads_init_default();

    if (connection == NULL)
    {
        connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
        if (connection == NULL && error != NULL)
        {
            skype_debug_info("skype_dbus", "Error: %s\n", error->message);
            g_error_free(error);
            return FALSE;
        }
    }

    if (proxy == NULL)
    {
        proxy = dbus_g_proxy_new_for_name_owner (connection,
                "com.Skype.API",
                "/com/Skype",
                "com.Skype.API",
                &error);
        if (proxy == NULL && error != NULL)
        {
            skype_debug_warning("skype_dbus", "%s\n", error->message);
            g_error_free(error);
            return FALSE;
        }

        g_signal_connect(G_OBJECT(proxy), "destroy", G_CALLBACK(skype_destroy_handler), NULL);
#ifdef DBUS_MAJOR_VERSION
        dbus_g_proxy_set_default_timeout(proxy, 3000);
#endif
        vtable.message_function = &skype_notify_handler;
        dbus_connection_register_object_path(dbus_g_connection_get_connection(connection), "/com/Skype/Client", &vtable, NULL);
    }

    return TRUE;
}
Example #28
0
/*
 * lixiang edit at 2012-01-16
 * start
 */
int dbus_connection_init(void) {

	DBusError dbus_error;
	dbus_threads_init_default();
	
	dbus_error_init(&dbus_error);
	
	if(NULL == ccgi_dbus_connection) {
		ccgi_dbus_connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &dbus_error);
		if (ccgi_dbus_connection == NULL) {		    
            if (dbus_error_is_set(&dbus_error)) {
			    syslog(LOG_WARNING, "dbus_connection_init: dbus_bus_get(): %s", dbus_error.message);
                dbus_error_free(&dbus_error);
			}    
		    return CCGI_FAIL;
		}
	}
	return CCGI_SUCCESS;
}
Example #29
0
static void
setup (Fixture *f,
    gconstpointer data)
{
  if (!dbus_threads_init_default ())
    g_error ("OOM");

  f->n_threads = N_THREADS;
  f->n_refs = N_REFS;

  // wine sets WINESERVERSOCKET for its child processes automatically
  if (g_getenv ("WINESERVERSOCKET") != NULL)
    {
      /* Our reference-counting is really slow under Wine (it involves
       * IPC to wineserver). Do fewer iterations: enough to demonstrate
       * that it works, rather than a performance test.
       */
      f->n_threads = 10;
      f->n_refs = 10;
    }

  f->loop = _dbus_loop_new ();
  g_assert (f->loop != NULL);

  dbus_error_init (&f->e);

  f->server = dbus_server_listen ("tcp:host=127.0.0.1", &f->e);
  assert_no_error (&f->e);
  g_assert (f->server != NULL);

  if (!dbus_connection_allocate_data_slot (&connection_slot))
    g_error ("OOM");

  if (!dbus_server_allocate_data_slot (&server_slot))
    g_error ("OOM");

  if (!dbus_message_allocate_data_slot (&message_slot))
    g_error ("OOM");

  if (!dbus_pending_call_allocate_data_slot (&pending_call_slot))
    g_error ("OOM");
}
/* Returns true on success (even if adapter is present but disabled).
 * Return false if dbus is down, or another serious error (out of memory)
*/
static bool initNative(JNIEnv* env, jobject object) {
    DBusMessage *msg = NULL, *reply = NULL;
    DBusError err;
    const char *device_path = NULL;
    int attempt = 0;

    LOGV("%s", __FUNCTION__);
#ifdef HAVE_BLUETOOTH
    native_data_t *nat = (native_data_t *)calloc(1, sizeof(native_data_t));
    if (NULL == nat) {
        LOGE("%s: out of memory!", __FUNCTION__);
        return false;
    }

    env->SetIntField(object, field_mNativeData, (jint)nat);
    gnat = nat;

    env->GetJavaVM( &(nat->vm) );
    nat->envVer = env->GetVersion();
    nat->me = env->NewGlobalRef(object);

    dbus_error_init(&err);
    dbus_threads_init_default();
    nat->conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
    if (dbus_error_is_set(&err)) {
        LOGE("Could not get onto the system bus: %s", err.message);
        dbus_error_free(&err);
        return false;
    }
    dbus_connection_set_exit_on_disconnect(nat->conn, FALSE);

    LOGE("%s Registering obecjt path at %s",__FUNCTION__, GATT_CLIENT_WATCHER_PATH);
    if (!dbus_connection_register_object_path(nat->conn, GATT_CLIENT_WATCHER_PATH,
            &gattclient_vtable, nat)) {
        LOGE("%s: Can't register object path %s for GATT Client watcher!",
              __FUNCTION__, GATT_CLIENT_WATCHER_PATH);
        return -1;
    }

#endif
    return true;
}