rcvr.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package impl
  4. import (
  5. "context"
  6. "smart-auth/impl/v1/device"
  7. "smart-auth/pb"
  8. "smart-auth/pb/v1"
  9. "github.com/jaryhe/gopkgs/tasker/rpctasker"
  10. "google.golang.org/grpc"
  11. )
  12. // 具体实现
  13. type Rcvr struct {
  14. }
  15. func Register(s *grpc.Server) {
  16. pb.RegisterSmartAuthServer(s, &Rcvr{})
  17. }
  18. // 设备信息获取
  19. func (c *Rcvr) DeviceInfo(ctx context.Context, req *v1.DeviceInfoRequest) (reply *v1.DeviceInfoReply, err error) {
  20. t1 := func() error {
  21. reply, err = device.DeviceInfo(ctx, req)
  22. return err
  23. }
  24. return reply, rpctasker.Exec(ctx, t1)
  25. }
  26. func (c *Rcvr) DeviceInfoById(ctx context.Context, req *v1.DeviceInfoByIdRequest) (reply *v1.DeviceInfoByIdReply, err error) {
  27. t1 := func() error {
  28. reply, err = device.DeviceInfoById(ctx, req)
  29. return err
  30. }
  31. return reply, rpctasker.Exec(ctx, t1)
  32. }
  33. // 设备参数设置
  34. func (c *Rcvr) DeviceParamSet(ctx context.Context, req *v1.DeviceParamSetRequest) (reply *v1.DeviceParamSetReply, err error) {
  35. t1 := func() error {
  36. reply, err = device.DeviceParamSet(ctx, req)
  37. return err
  38. }
  39. return reply, rpctasker.Exec(ctx, t1)
  40. }
  41. // 设备状态更新
  42. func (c *Rcvr) DeviceStatusUpdate(ctx context.Context, req *v1.DeviceStatusUpdateRequest) (reply *v1.DeviceStatusUpdateReply, err error) {
  43. t1 := func() error {
  44. reply, err = device.DeviceStatusUpdate(ctx, req)
  45. return err
  46. }
  47. return reply, rpctasker.Exec(ctx, t1)
  48. }
  49. // 设备改变通知
  50. func (c *Rcvr) DeviceChangeNotify(ctx context.Context, req *v1.DeviceChangeNotifyRequest) (reply *v1.DeviceChangeNotifyReply, err error) {
  51. t1 := func() error {
  52. reply, err = device.DeviceChangeNotify(ctx, req)
  53. return err
  54. }
  55. return reply, rpctasker.Exec(ctx, t1)
  56. }
  57. // 获取所有扬尘sn码
  58. func (c *Rcvr) GetAllDustSn(ctx context.Context, req *v1.GetAllDustSnRequest) (reply *v1.GetAllDustSnReply, err error) {
  59. t1 := func() error {
  60. reply, err = device.GetAllDustSn(ctx, req)
  61. return err
  62. }
  63. return reply, rpctasker.Exec(ctx, t1)
  64. }