Пример #1
0
// Start Loader.
//
func serviceDbus(log cdtype.Logger) (*srvdbus.Loader, error) {
	dockpath.DbusPathDock = "/org/cdc/Cdc" // TODO: improve to autodetect.

	loader := srvdbus.NewLoader(log)
	if loader == nil {
		return nil, errors.New("Dbus service failed to start")
	}

	active, e := loader.Connect()
	switch {
	case e != nil:
		return nil, e

	case !active:
		return nil, errors.New("service already active")
	}

	return loader, nil
}
Пример #2
0
// Start Loader with the list of applets and args received for the first applet.
//
func service(args []string) {
	loader := srvdbus.NewLoader(logger)
	if loader == nil {
		return
	}

	mgr := mgrdbus.NewManager(loader, logger)
	loader.SetManager(mgr)

	active, e := loader.Start(mgr, nil)
	if logger.Err(e, "StartServer") {
		return
	}

	if !active { // Someone else is active, forward the start applet and quit.
		// Whether the first program instance will handle successfully the
		// request or not, this isn't our problem anymore, we still must quit.
		mgrdbus.StartApplet(args[0], args[1], args[2], args[3], args[4], args[5], args[6])
		return
	}

	// I am the chosen one. Let's create the first miracle, and keep it alive.
	mgr.StartApplet("", args[0], args[1], args[2], args[3], args[4], args[5], args[6])

	// defer allapps.OnStop()
	if gtkStart != nil && allapps.GtkNeeded() {
		go func() {
			loader.StartLoop()
			logger.Info("cdc stopped")
			gtkStop()
		}()
		gtkStart()

	} else {
		loader.StartLoop()
	}
	loader.Conn.Close()
}