amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 1 | /* |
Joey Armstrong | 3881b73 | 2022-12-27 07:55:37 -0500 | [diff] [blame^] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package dmiserver |
| 18 | |
| 19 | import ( |
| 20 | "context" |
Hardik Windlass | 63e35cf | 2022-02-03 05:58:09 +0000 | [diff] [blame] | 21 | "github.com/golang/protobuf/ptypes/empty" |
hkouser | 24361d4 | 2020-12-14 19:21:47 +0530 | [diff] [blame] | 22 | "google.golang.org/grpc/codes" |
| 23 | "google.golang.org/grpc/status" |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 24 | |
| 25 | dmi "github.com/opencord/device-management-interface/go/dmi" |
| 26 | ) |
| 27 | |
| 28 | //ListEvents lists the supported events for the passed device |
| 29 | func (dms *DmiAPIServer) ListEvents(ctx context.Context, req *dmi.HardwareID) (*dmi.ListEventsResponse, error) { |
| 30 | logger.Debugf("ListEvents called with request %+v", req) |
hkouser | 24361d4 | 2020-12-14 19:21:47 +0530 | [diff] [blame] | 31 | events := getEventsList() |
| 32 | |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 33 | return &dmi.ListEventsResponse{ |
Humera Kouser | a444295 | 2020-11-23 23:51:19 +0530 | [diff] [blame] | 34 | Status: dmi.Status_OK_STATUS, |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 35 | Events: &dmi.EventsCfg{ |
| 36 | Items: events, |
| 37 | }, |
| 38 | }, nil |
| 39 | } |
| 40 | |
| 41 | //UpdateEventsConfiguration updates the configuration of the list of events in the request |
| 42 | func (dms *DmiAPIServer) UpdateEventsConfiguration(ctx context.Context, req *dmi.EventsConfigurationRequest) (*dmi.EventsConfigurationResponse, error) { |
| 43 | logger.Debugf("UpdateEventsConfiguration called with request %+v", req) |
hkouser | 24361d4 | 2020-12-14 19:21:47 +0530 | [diff] [blame] | 44 | |
| 45 | if req == nil || req.Operation == nil { |
| 46 | return &dmi.EventsConfigurationResponse{ |
| 47 | Status: dmi.Status_ERROR_STATUS, |
| 48 | //TODO reason must be INVALID_PARAMS, currently this is not available in Device Management interface (DMI), |
| 49 | // change below reason with type INVALID_PARAMS once DMI is updated |
ssiddiqui | 6ca4070 | 2021-03-08 18:20:21 +0530 | [diff] [blame] | 50 | Reason: dmi.EventsConfigurationResponse_UNDEFINED_REASON, |
hkouser | 24361d4 | 2020-12-14 19:21:47 +0530 | [diff] [blame] | 51 | }, status.Errorf(codes.FailedPrecondition, "request is nil") |
| 52 | } |
| 53 | |
| 54 | switch x := req.Operation.(type) { |
| 55 | case *dmi.EventsConfigurationRequest_Changes: |
| 56 | for _, eventConfig := range x.Changes.Items { |
| 57 | UpdateEventConfig(eventConfig) |
| 58 | } |
| 59 | case *dmi.EventsConfigurationRequest_ResetToDefault: |
| 60 | logger.Debugf("To be implemented later") |
| 61 | case nil: |
| 62 | // The field is not set. |
| 63 | logger.Debugf("Update request operation type is nil") |
| 64 | return &dmi.EventsConfigurationResponse{ |
| 65 | Status: dmi.Status_UNDEFINED_STATUS, |
| 66 | }, nil |
| 67 | } |
| 68 | |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 69 | return &dmi.EventsConfigurationResponse{ |
Humera Kouser | a444295 | 2020-11-23 23:51:19 +0530 | [diff] [blame] | 70 | Status: dmi.Status_OK_STATUS, |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 71 | }, nil |
| 72 | } |
Hardik Windlass | 63e35cf | 2022-02-03 05:58:09 +0000 | [diff] [blame] | 73 | |
| 74 | // Initiates the server streaming of the events |
| 75 | func (dms *DmiAPIServer) StreamEvents(req *empty.Empty, srv dmi.NativeEventsManagementService_StreamEventsServer) error { |
| 76 | return status.Errorf(codes.Unimplemented, "rpc StreamEvents not implemented") |
| 77 | } |