github.com/cloudwan/edgelq-sdk@v1.15.4/devices/resources/v1/device_hardware/device_hardware.pb.access.go (about)

     1  // Code generated by protoc-gen-goten-resource
     2  // Resource: DeviceHardware
     3  // DO NOT EDIT!!!
     4  
     5  package device_hardware
     6  
     7  import (
     8  	"context"
     9  
    10  	"google.golang.org/grpc/codes"
    11  	"google.golang.org/grpc/status"
    12  
    13  	gotenobject "github.com/cloudwan/goten-sdk/runtime/object"
    14  	gotenresource "github.com/cloudwan/goten-sdk/runtime/resource"
    15  	"github.com/cloudwan/goten-sdk/types/watch_type"
    16  )
    17  
    18  // proto imports
    19  import (
    20  	cellular_api_sim_card "github.com/cloudwan/edgelq-sdk/cellular-api/resources/v1/sim_card"
    21  	device "github.com/cloudwan/edgelq-sdk/devices/resources/v1/device"
    22  	project "github.com/cloudwan/edgelq-sdk/devices/resources/v1/project"
    23  	provisioning_policy "github.com/cloudwan/edgelq-sdk/devices/resources/v1/provisioning_policy"
    24  	meta "github.com/cloudwan/goten-sdk/types/meta"
    25  )
    26  
    27  // ensure the imports are used
    28  var (
    29  	_ = new(context.Context)
    30  
    31  	_ = codes.Internal
    32  	_ = status.Status{}
    33  
    34  	_ = watch_type.WatchType_STATEFUL
    35  	_ = new(gotenobject.FieldPath)
    36  	_ = new(gotenresource.ListQuery)
    37  )
    38  
    39  // make sure we're using proto imports
    40  var (
    41  	_ = &cellular_api_sim_card.SimCard{}
    42  	_ = &device.Device{}
    43  	_ = &project.Project{}
    44  	_ = &provisioning_policy.ProvisioningPolicy{}
    45  	_ = &meta.Meta{}
    46  )
    47  
    48  type DeviceHardwareAccess interface {
    49  	GetDeviceHardware(context.Context, *GetQuery, ...gotenresource.GetOption) (*DeviceHardware, error)
    50  	BatchGetDeviceHardwares(context.Context, []*Reference, ...gotenresource.BatchGetOption) error
    51  	QueryDeviceHardwares(context.Context, *ListQuery, ...gotenresource.QueryOption) (*QueryResultSnapshot, error)
    52  	WatchDeviceHardware(context.Context, *GetQuery, func(*DeviceHardwareChange) error) error
    53  	WatchDeviceHardwares(context.Context, *WatchQuery, func(*QueryResultChange) error) error
    54  	SaveDeviceHardware(context.Context, *DeviceHardware, ...gotenresource.SaveOption) error
    55  	DeleteDeviceHardware(context.Context, *Reference, ...gotenresource.DeleteOption) error
    56  }
    57  
    58  type anyCastAccess struct {
    59  	DeviceHardwareAccess
    60  }
    61  
    62  func AsAnyCastAccess(access DeviceHardwareAccess) gotenresource.Access {
    63  	return &anyCastAccess{DeviceHardwareAccess: access}
    64  }
    65  
    66  func (a *anyCastAccess) Get(ctx context.Context, q gotenresource.GetQuery, opts ...gotenresource.GetOption) (gotenresource.Resource, error) {
    67  	if asDeviceHardwareQuery, ok := q.(*GetQuery); ok {
    68  		return a.GetDeviceHardware(ctx, asDeviceHardwareQuery, opts...)
    69  	}
    70  	return nil, status.Errorf(codes.Internal,
    71  		"Unrecognized descriptor, expected DeviceHardware, got: %s",
    72  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    73  }
    74  
    75  func (a *anyCastAccess) Query(ctx context.Context, q gotenresource.ListQuery, opts ...gotenresource.QueryOption) (gotenresource.QueryResultSnapshot, error) {
    76  	if asDeviceHardwareQuery, ok := q.(*ListQuery); ok {
    77  		return a.QueryDeviceHardwares(ctx, asDeviceHardwareQuery, opts...)
    78  	}
    79  	return nil, status.Errorf(codes.Internal,
    80  		"Unrecognized descriptor, expected DeviceHardware, got: %s",
    81  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    82  }
    83  
    84  func (a *anyCastAccess) Search(ctx context.Context, q gotenresource.SearchQuery, opts ...gotenresource.QueryOption) (gotenresource.QueryResultSnapshot, error) {
    85  	return nil, status.Errorf(codes.Internal, "Search is not available for DeviceHardware")
    86  }
    87  
    88  func (a *anyCastAccess) Watch(ctx context.Context, q gotenresource.GetQuery, cb func(ch gotenresource.ResourceChange) error) error {
    89  	if asDeviceHardwareQuery, ok := q.(*GetQuery); ok {
    90  		return a.WatchDeviceHardware(ctx, asDeviceHardwareQuery, func(change *DeviceHardwareChange) error {
    91  			return cb(change)
    92  		})
    93  	}
    94  	return status.Errorf(codes.Internal,
    95  		"Unrecognized descriptor, expected DeviceHardware, got: %s",
    96  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    97  }
    98  
    99  func (a *anyCastAccess) WatchQuery(ctx context.Context, q gotenresource.WatchQuery, cb func(ch gotenresource.QueryResultChange) error) error {
   100  	if asDeviceHardwareQuery, ok := q.(*WatchQuery); ok {
   101  		return a.WatchDeviceHardwares(ctx, asDeviceHardwareQuery, func(change *QueryResultChange) error {
   102  			return cb(change)
   103  		})
   104  	}
   105  	return status.Errorf(codes.Internal,
   106  		"Unrecognized descriptor, expected DeviceHardware, got: %s",
   107  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   108  }
   109  
   110  func (a *anyCastAccess) Save(ctx context.Context, res gotenresource.Resource, opts ...gotenresource.SaveOption) error {
   111  	if asDeviceHardwareRes, ok := res.(*DeviceHardware); ok {
   112  		return a.SaveDeviceHardware(ctx, asDeviceHardwareRes, opts...)
   113  	}
   114  	return status.Errorf(codes.Internal,
   115  		"Unrecognized descriptor, expected DeviceHardware, got: %s",
   116  		res.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   117  }
   118  
   119  func (a *anyCastAccess) Delete(ctx context.Context, ref gotenresource.Reference, opts ...gotenresource.DeleteOption) error {
   120  	if asDeviceHardwareRef, ok := ref.(*Reference); ok {
   121  		return a.DeleteDeviceHardware(ctx, asDeviceHardwareRef, opts...)
   122  	}
   123  	return status.Errorf(codes.Internal,
   124  		"Unrecognized descriptor, expected DeviceHardware, got: %s",
   125  		ref.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   126  }
   127  
   128  func (a *anyCastAccess) BatchGet(ctx context.Context, toGet []gotenresource.Reference, opts ...gotenresource.BatchGetOption) error {
   129  	deviceHardwareRefs := make([]*Reference, 0, len(toGet))
   130  	for _, ref := range toGet {
   131  		if asDeviceHardwareRef, ok := ref.(*Reference); !ok {
   132  			return status.Errorf(codes.Internal,
   133  				"Unrecognized descriptor, expected DeviceHardware, got: %s",
   134  				ref.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   135  		} else {
   136  			deviceHardwareRefs = append(deviceHardwareRefs, asDeviceHardwareRef)
   137  		}
   138  	}
   139  	return a.BatchGetDeviceHardwares(ctx, deviceHardwareRefs, opts...)
   140  }
   141  
   142  func (a *anyCastAccess) GetResourceDescriptors() []gotenresource.Descriptor {
   143  	return []gotenresource.Descriptor{
   144  		GetDescriptor(),
   145  	}
   146  }