本文整理汇总了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
}
示例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
}
示例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)
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
示例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
}
示例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
}
示例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
}
示例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)
}