Exemplo n.º 1
0
func main() {
	configFile, config, err := conf.FromArgs()
	switch {
	case err != nil:
		log.Fatalf("Failed to read %q configuration (%s)", configFile, err)
	case configFile == "":
		log.Warnf("No configuration file provided!")
		log.Infof("Test configuration is used: %+v", config)
	default:
		log.Infof("Starting DeviceHive with %q configuration: %+v", configFile, config)
	}

	log.SetLevelByName(config.LoggingLevel)

	bus, err := dbus.SystemBus()
	if err != nil {
		log.Warnf("Cannot get system bus (error: %s)", err)
		log.Infof("Trying to use session bus for testing purposes...")
		if bus, err = dbus.SessionBus(); err != nil {
			log.Fatalf("Cannot get session bus (error: %s)", err)
			return
		}
	}

	reply, err := bus.RequestName(DBusConnName, dbus.NameFlagDoNotQueue)
	switch {
	case err != nil:
		log.Fatalf("Cannot request name %q (error: %s)", DBusConnName, err)
	case reply != dbus.RequestNameReplyPrimaryOwner:
		log.Fatalf("The name %q already taken", DBusConnName)
	}

	s, err := devicehive.NewService(config.URL, config.AccessKey)
	if err != nil {
		log.Fatalf("Failed to create DeviceHive service (error: %s)", err)
	}

	log.Infof("Starting %v", s)
	mainLoop(bus, s, config)
}
Exemplo n.º 2
0
// initialize test environment
func init() {
	flag.StringVar(&testRestServerUrl, "rest-url", testRestServerUrl, "REST service URL")
	flag.StringVar(&testWsServerUrl, "ws-url", testWsServerUrl, "Websocket service URL")
	flag.StringVar(&testAccessKey, "access-key", testAccessKey, "key to access playground")

	flag.StringVar(&testDeviceId, "device-id", testDeviceId, "test Device identifier")
	flag.StringVar(&testDeviceName, "device-name", testDeviceName, "test Device name")
	flag.StringVar(&testDeviceKey, "device-key", testDeviceKey, "test Device key")

	flag.StringVar(&testDeviceClassName, "device-class-name", testDeviceClassName, "test Device class name")
	flag.StringVar(&testDeviceClassVersion, "device-class-version", testDeviceClassVersion, "test Device class version")

	flag.StringVar(&testNetworkName, "network-name", testNetworkName, "test Network name")
	flag.StringVar(&testNetworkKey, "network-key", testNetworkKey, "test Network key")
	flag.StringVar(&testNetworkDesc, "network-desc", testNetworkDesc, "test Network description")

	flag.IntVar(&testGapMs, "gap", testGapMs, "gap interval, milliseconds")
	flag.IntVar(&testBatchLen, "batch-len", testBatchLen, "batch length")

	flag.StringVar(&testLogLevel, "log-level", testLogLevel, "Logging level: WARN INFO DEBUG TRACE or NOLOG")
	flag.Parse()

	log.SetLevelByName(testLogLevel)
}
Exemplo n.º 3
0
// SetLogLevel changes the global logging level:
// "WARN" "INFO" "DEBUG" "TRACE"
func SetLogLevel(level string) {
	log.SetLevelByName(level)
}