当前位置: 首页>>代码示例>>Golang>>正文


Golang server.RPCCallByName函数代码示例

本文整理汇总了Golang中github.com/PandoCloud/pando-cloud/pkg/server.RPCCallByName函数的典型用法代码示例。如果您正苦于以下问题:Golang RPCCallByName函数的具体用法?Golang RPCCallByName怎么用?Golang RPCCallByName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了RPCCallByName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetDeviceCurrentStatus

func GetDeviceCurrentStatus(urlparams martini.Params, r render.Render) {
	identifier := urlparams["identifier"]
	server.Log.Printf("ACTION GetDeviceCurrentStatus, identifier:: %v", identifier)

	device := &models.Device{}
	err := server.RPCCallByName("registry", "Registry.FindDeviceByIdentifier", identifier, device)
	if err != nil {
		r.JSON(http.StatusOK, renderError(ErrDeviceNotFound, err))
		return
	}

	result := DeviceStatusResponse{}

	onlineargs := rpcs.ArgsGetDeviceStatus{
		Id: uint64(device.ID),
	}
	onlinereply := rpcs.ReplyGetDeviceStatus{}
	err = server.RPCCallByName("devicemanger", "DeviceManager.GetDeviceStatus", onlineargs, &onlinereply)
	if err != nil {
		// if device is not online, just return
		server.Log.Errorf("get devie status error: %v", err)
		r.JSON(http.StatusOK, result)
		return
	}

	// device is online, try read status
	// todo
}
开发者ID:jerry2weng,项目名称:pando-cloud,代码行数:28,代码来源:actions.go

示例2: GetDeviceCurrentStatus

func GetDeviceCurrentStatus(urlparams martini.Params, r render.Render) {
	identifier := urlparams["identifier"]
	server.Log.Printf("ACTION GetDeviceCurrentStatus, identifier:: %v", identifier)

	device := &models.Device{}
	err := server.RPCCallByName("registry", "Registry.FindDeviceByIdentifier", identifier, device)
	if err != nil {
		r.JSON(http.StatusOK, renderError(ErrDeviceNotFound, err))
		return
	}

	onlineargs := rpcs.ArgsGetDeviceOnlineStatus{
		Id: uint64(device.ID),
	}
	onlinereply := rpcs.ReplyGetDeviceOnlineStatus{}
	err = server.RPCCallByName("devicemanager", "DeviceManager.GetDeviceOnlineStatus", onlineargs, &onlinereply)
	if err != nil {
		server.Log.Errorf("get devie online status error: %v", err)
		r.JSON(http.StatusOK, renderError(ErrDeviceNotOnline, err))
		return
	}

	statusargs := rpcs.ArgsGetStatus{
		Id: uint64(device.ID),
	}
	statusreply := rpcs.ReplyGetStatus{}
	err = server.RPCCallByName("controller", "Controller.GetStatus", statusargs, &statusreply)
	if err != nil {
		server.Log.Errorf("get devie status error: %v", err)
		r.JSON(http.StatusOK, renderError(ErrSystemFault, err))
		return
	}

	product := &models.Product{}
	err = server.RPCCallByName("registry", "Registry.FindProduct", device.ProductID, product)
	if err != nil {
		r.JSON(http.StatusOK, renderError(ErrProductNotFound, err))
		return
	}

	c, err := productconfig.New(product.ProductConfig)
	if err != nil {
		r.JSON(http.StatusOK, renderError(ErrWrongProductConfig, err))
		return
	}

	data, err := c.StatusToMap(statusreply.Status)
	if err != nil {
		r.JSON(http.StatusOK, renderError(ErrWrongStatusFormat, err))
		return
	}
	result := DeviceStatusResponse{
		Data: data,
	}

	r.JSON(http.StatusOK, result)
	return
}
开发者ID:zhouhoo,项目名称:pando-cloud,代码行数:58,代码来源:actions.go

示例3: OnDeviceMessage

func (mp *MQTTProvider) OnDeviceMessage(deviceid uint64, msgtype string, message []byte) {
	server.Log.Infof("device {%v} message {%v} : %x", deviceid, msgtype, message)
	switch msgtype {
	case "s":
		// it's a status
		data := &protocol.Data{}
		err := data.UnMarshal(message)
		if err != nil {
			server.Log.Errorf("unmarshal data error : %v", err)
			return
		}
		// if there is a realtime query
		ch, exist := StatusChan[deviceid]
		if exist {
			ch <- data
			return
		}

		// it's a normal report.
		reply := rpcs.ReplyOnStatus{}
		args := rpcs.ArgsOnStatus{
			DeviceId:  deviceid,
			Timestamp: data.Head.Timestamp,
			Subdata:   data.SubData,
		}
		err = server.RPCCallByName("controller", "Controller.OnStatus", args, &reply)
		if err != nil {
			server.Log.Errorf("device report status error. args: %v, error: %v", args, err)
			return
		}
	case "e":
		// it's an event report
		event := &protocol.Event{}
		err := event.UnMarshal(message)
		if err != nil {
			server.Log.Errorf("unmarshal event error : %v", err)
			return
		}
		reply := rpcs.ReplyOnEvent{}
		args := rpcs.ArgsOnEvent{
			DeviceId:  deviceid,
			TimeStamp: event.Head.Timestamp,
			SubDevice: event.Head.SubDeviceid,
			No:        event.Head.No,
			Priority:  event.Head.Priority,
			Params:    event.Params,
		}
		err = server.RPCCallByName("controller", "Controller.OnEvent", args, &reply)
		if err != nil {
			server.Log.Errorf("device on event error. args: %v, error: %v", args, err)
			return
		}
	default:
		server.Log.Infof("unkown message type: %v", msgtype)
	}
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:56,代码来源:mqtt_provider.go

示例4: Check

func (ift *Ifttt) Check(deviceid uint64, eventid uint16) error {
	actions := &[]models.Rule{}
	query := &models.Rule{
		RuleType: "ifttt",
		DeviceID: int64(deviceid),
	}
	err := server.RPCCallByName("registry", "Registry.QueryRules", query, actions)
	if err != nil {
		server.Log.Warnf("load ifttt rules error : %v", err)
		return err
	}

	if len(*actions) > 0 {
		device := &models.Device{}
		err := server.RPCCallByName("registry", "Registry.FindDeviceById", int64(deviceid), device)
		if err != nil {
			server.Log.Errorf("find device error : %v", err)
			return err
		}

		product := &models.Product{}
		err = server.RPCCallByName("registry", "Registry.FindProduct", device.ProductID, product)
		if err != nil {
			server.Log.Errorf("find product error : %v", err)
			return err
		}

		c, err := productconfig.New(product.ProductConfig)
		if err != nil {
			server.Log.Errorf("product config error : %v", err)
			return err
		}

		name := ""
		for _, ev := range c.Events {
			if ev.No == int(eventid) {
				name = ev.Name
			}
		}

		for _, action := range *actions {
			if action.Trigger == name {
				err := performRuleAction(action.Target, action.Action)
				if err != nil {
					server.Log.Warnf("ifttt action failed: %v", err)
				}
			}
		}
	}

	return nil
}
开发者ID:PandoCloud,项目名称:pando-cloud,代码行数:52,代码来源:ifttt.go

示例5: AddRule

func AddRule(device *models.Device, req *http.Request, r render.Render) {
	var ruleReq CreateRuleRequest
	decoder := json.NewDecoder(req.Body)
	err := decoder.Decode(&ruleReq)
	if err != nil {
		r.JSON(http.StatusOK, renderError(ErrWrongRequestFormat, err))
		return
	}

	rule := &models.Rule{
		DeviceID: device.ID,
		RuleType: ruleReq.Type,
		Trigger:  ruleReq.Trigger,
		Target:   ruleReq.Target,
		Action:   ruleReq.Action,
	}
	reply := &rpcs.ReplyEmptyResult{}

	err = server.RPCCallByName("registry", "Registry.CreateRule", rule, reply)
	if err != nil {
		server.Log.Errorf("create device rule error: %v", err)
		r.JSON(http.StatusOK, renderError(ErrSystemFault, err))
		return
	}

	r.JSON(http.StatusOK, Common{})
	return

}
开发者ID:PandoCloud,项目名称:pando-cloud,代码行数:29,代码来源:actions.go

示例6: addVendor

func addVendor() error {
	args := models.Vendor{}

	reader := bufio.NewReader(os.Stdin)

	fmt.Printf("vendor name: ")
	name, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	args.VendorName = strings.Replace(name, "\n", "", -1)

	fmt.Printf("vendor description: ")
	desc, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	args.VendorDescription = strings.Replace(desc, "\n", "", -1)

	reply := &models.Vendor{}

	err = server.RPCCallByName("registry", "Registry.SaveVendor", &args, reply)
	if err != nil {
		return err
	}

	fmt.Println("=======> vendor created successfully:")
	printStruct(reply)
	fmt.Println("=======")

	return nil
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:32,代码来源:vendor.go

示例7: GetDeviceCurrentStatus

func GetDeviceCurrentStatus(device *models.Device, config *productconfig.ProductConfig,
	urlparams martini.Params, r render.Render) {
	server.Log.Printf("ACTION GetDeviceCurrentStatus, identifier:: %v", device.DeviceIdentifier)

	statusargs := rpcs.ArgsGetStatus{
		Id: uint64(device.ID),
	}
	statusreply := rpcs.ReplyGetStatus{}
	err := server.RPCCallByName("controller", "Controller.GetStatus", statusargs, &statusreply)
	if err != nil {
		server.Log.Errorf("get devie status error: %v", err)
		r.JSON(http.StatusOK, renderError(ErrSystemFault, err))
		return
	}

	status, err := config.StatusToMap(statusreply.Status)
	if err != nil {
		r.JSON(http.StatusOK, renderError(ErrWrongRequestFormat, err))
		return
	}
	result := DeviceStatusResponse{
		Data: status,
	}

	r.JSON(http.StatusOK, result)
	return
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:27,代码来源:actions.go

示例8: RegisterDevice

func RegisterDevice(args DeviceRegisterArgs, r render.Render) {
	server.Log.Printf("ACTION RegisterDevice, args:: %v ", args)
	rpcargs := &rpcs.ArgsDeviceRegister{
		ProductKey:    args.ProductKey,
		DeviceCode:    args.DeviceCode,
		DeviceVersion: args.Version,
	}
	device := &models.Device{}
	err := server.RPCCallByName("registry", "Registry.RegisterDevice", rpcargs, device)
	if err != nil {
		r.JSON(http.StatusOK, renderError(ErrSystemFault, err))
		return
	}
	server.Log.Infof("register device success: %v", device)

	result := DeviceRegisterResponse{}
	result.Data = DeviceRegisterData{
		DeviceId:         device.ID,
		DeviceSecret:     device.DeviceSecret,
		DeviceKey:        device.DeviceKey,
		DeviceIdentifier: device.DeviceIdentifier,
	}
	r.JSON(http.StatusOK, result)
	return
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:25,代码来源:actions.go

示例9: OnDeviceOnline

func (mp *MQTTProvider) OnDeviceOnline(args rpcs.ArgsGetOnline) error {
	reply := rpcs.ReplyGetOnline{}
	err := server.RPCCallByName("devicemanager", "DeviceManager.GetOnline", args, &reply)
	if err != nil {
		server.Log.Errorf("device online error. args: %v, error: %v", args, err)
	}

	return err
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:9,代码来源:mqtt_provider.go

示例10: OnDeviceHeartBeat

func (mp *MQTTProvider) OnDeviceHeartBeat(deviceid uint64) error {
	args := rpcs.ArgsDeviceId{
		Id: deviceid,
	}
	reply := rpcs.ReplyHeartBeat{}
	err := server.RPCCallByName("devicemanager", "DeviceManager.HeartBeat", args, &reply)
	if err != nil {
		server.Log.Errorf("device heartbeat error. deviceid: %v, error: %v", deviceid, err)
	}
	return err
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:11,代码来源:mqtt_provider.go

示例11: updateApplications

func (n *Notifier) updateApplications() error {
	for {

		err := server.RPCCallByName("registry", "Registry.GetApplications", 0, &n.apps)
		if err != nil {
			server.Log.Errorf("get applications error : %v", err)
		}

		time.Sleep(time.Minute)
	}
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:11,代码来源:notifier.go

示例12: addApplication

func addApplication() error {
	args := models.Application{}

	reader := bufio.NewReader(os.Stdin)

	fmt.Printf("application name: ")
	name, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	args.AppName = strings.Replace(name, "\n", "", -1)

	fmt.Printf("application description: ")
	desc, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	args.AppDescription = strings.Replace(desc, "\n", "", -1)

	fmt.Printf("application domain: ")
	domain, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	args.AppDomain = strings.Replace(domain, "\n", "", -1)

	fmt.Printf("application report url: ")
	url, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	args.ReportUrl = strings.Replace(url, "\n", "", -1)

	fmt.Printf("application token: ")
	token, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	args.AppToken = strings.Replace(token, "\n", "", -1)

	reply := &models.Application{}

	err = server.RPCCallByName("registry", "Registry.SaveApplication", &args, reply)
	if err != nil {
		return err
	}

	fmt.Println("=======> application created successfully:")
	printStruct(reply)
	fmt.Println("=======")

	return nil
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:53,代码来源:application.go

示例13: getAccessRPCHost

func getAccessRPCHost(deviceid uint64) (string, error) {
	args := rpcs.ArgsGetDeviceOnlineStatus{
		Id: deviceid,
	}
	reply := &rpcs.ReplyGetDeviceOnlineStatus{}
	err := server.RPCCallByName("devicemanager", "DeviceManager.GetDeviceOnlineStatus", args, reply)
	if err != nil {
		return "", err
	}

	return reply.AccessRPCHost, nil
}
开发者ID:PandoCloud,项目名称:pando-cloud,代码行数:12,代码来源:controller.go

示例14: OnDeviceOffline

func (mp *MQTTProvider) OnDeviceOffline(deviceid uint64) error {
	args := rpcs.ArgsGetOffline{
		Id: deviceid,
	}
	reply := rpcs.ReplyGetOffline{}
	err := server.RPCCallByName("devicemanager", "DeviceManager.GetOffline", args, &reply)
	if err != nil {
		server.Log.Errorf("device offline error. deviceid: %v, error: %v", deviceid, err)
	}

	return err
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:12,代码来源:mqtt_provider.go

示例15: CheckDeviceIdentifier

// get device identifier
func CheckDeviceIdentifier(context martini.Context, params martini.Params, req *http.Request, r render.Render) {
	identifier := params["identifier"]

	device := &models.Device{}
	err := server.RPCCallByName("registry", "Registry.FindDeviceByIdentifier", identifier, device)
	if err != nil {
		r.JSON(http.StatusOK, renderError(ErrDeviceNotFound, err))
		return
	}

	context.Map(device)
}
开发者ID:PandoCloud,项目名称:pando-cloud,代码行数:13,代码来源:middleware.go


注:本文中的github.com/PandoCloud/pando-cloud/pkg/server.RPCCallByName函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。