コード例 #1
0
ファイル: Setup.go プロジェクト: ThingFu/hub
// Scans for defintions under home's /things subdirectory
// and it walks through the path.
// if the descriptor.json file is found, it is assumed that the
// directory it resides in contains a thing defintion
//
func loadThingTypes(env api.Environment) {
	log.Println("[INFO] Pressing the Any Key...")
	thingManager := container.Instance().ThingManager()
	home := env.GetHome()
	root := home + "/things"

	filepath.Walk(root, func(path string, f os.FileInfo, err error) error {
		if strings.HasSuffix(path, "descriptor.json") {
			content, err := ioutil.ReadFile(path)
			if err != nil {
				panic(err)
			}

			var thingType api.ThingType
			err = json.Unmarshal(content, &thingType)

			if err != nil {
				log.Println("error: ", err)
			}
			thingType.Path = strings.Replace(path, "/descriptor.json", "", -1)
			thingManager.RegisterThingType(thingType)
		}
		return nil
	})
}
コード例 #2
0
ファイル: Setup.go プロジェクト: ThingFu/hub
func loadRules(env api.Environment) {
	log.Println("[INFO] Dividing by Zero")
	rulesService := container.Instance().RulesManager()
	filepath.Walk(env.GetHome()+"/rules", func(path string, f os.FileInfo, err error) error {
		if !f.IsDir() {
			content, err := ioutil.ReadFile(path)
			if err != nil {
				panic(err)
			}

			var rule api.Rule
			err = json.Unmarshal(content, &rule)

			if err != nil {
				log.Printf("[ERROR] Parsing Rule %s\n", path)
				return nil
			}
			rule.Id = utils.RandomString(7)

			rule.Path = path[strings.LastIndex(path, "/")+1:]

			log.Printf("[INFO] Registering rule file: %s\n", rule.Name)

			rulesService.RegisterRule(rule)
		}
		return nil
	})
}
コード例 #3
0
ファイル: Setup.go プロジェクト: ThingFu/hub
// Call each Protocol Handler's Start.
// Each protocol handler would need its own dedicated
// goroutine/thread to run in
//
func setupChannels() {
	log.Println("[INFO] Setting Up Channels")
	c := container.Instance()

	// func (d *DefaultCommChannelManager) Register(protocol string, channel api.CommunicationChannel) {
	commManager := c.CommChannelManager()
	commManager.InitChannels(c.Env().GetConfig().Channels)
}
コード例 #4
0
ファイル: WebApplication.go プロジェクト: ThingFu/hub
func NewWebApplication(port uint16) {
	w := new(WebApplication)
	w.port = port

	c := container.Instance()
	w.container = c
	w.rulesService = c.RulesManager()
	w.dataSource = c.DataSource()
	w.thingManager = c.ThingManager()
	w.environment = c.Env()
	w.factory = c.Factory()

	r := w.initializeRoutes()
	portStr := fmt.Sprintf("%d", w.port)

	http.Handle("/", r)
	log.Println("[INFO] Start Node WebServer @ " + portStr)
	err := http.ListenAndServe(":"+portStr, nil)
	if err != nil {
		log.Print("Error starting GoHome: ", err)
	}
}
コード例 #5
0
ファイル: Setup.go プロジェクト: ThingFu/hub
// Loads thing definitions from a DataSource
// and registers them
//
func loadThings(env api.Environment) {
	log.Println("[INFO] Finding Waldo..")

	thingManager := container.Instance().ThingManager()
	thingManager.LoadThings()
}
コード例 #6
0
ファイル: Setup.go プロジェクト: ThingFu/hub
func startScheduler() {
	log.Println("[INFO] Whipping Hamsters into a Frenzy..")
	scheduleService := container.Instance().ScheduleService()
	scheduleService.Start()
}