amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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" |
hkouser | 24361d4 | 2020-12-14 19:21:47 +0530 | [diff] [blame^] | 21 | "google.golang.org/grpc/codes" |
| 22 | "google.golang.org/grpc/status" |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 23 | |
| 24 | dmi "github.com/opencord/device-management-interface/go/dmi" |
| 25 | ) |
| 26 | |
| 27 | //ListEvents lists the supported events for the passed device |
| 28 | func (dms *DmiAPIServer) ListEvents(ctx context.Context, req *dmi.HardwareID) (*dmi.ListEventsResponse, error) { |
| 29 | logger.Debugf("ListEvents called with request %+v", req) |
hkouser | 24361d4 | 2020-12-14 19:21:47 +0530 | [diff] [blame^] | 30 | events := getEventsList() |
| 31 | |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 32 | return &dmi.ListEventsResponse{ |
Humera Kouser | a444295 | 2020-11-23 23:51:19 +0530 | [diff] [blame] | 33 | Status: dmi.Status_OK_STATUS, |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 34 | Events: &dmi.EventsCfg{ |
| 35 | Items: events, |
| 36 | }, |
| 37 | }, nil |
| 38 | } |
| 39 | |
| 40 | //UpdateEventsConfiguration updates the configuration of the list of events in the request |
| 41 | func (dms *DmiAPIServer) UpdateEventsConfiguration(ctx context.Context, req *dmi.EventsConfigurationRequest) (*dmi.EventsConfigurationResponse, error) { |
| 42 | logger.Debugf("UpdateEventsConfiguration called with request %+v", req) |
hkouser | 24361d4 | 2020-12-14 19:21:47 +0530 | [diff] [blame^] | 43 | |
| 44 | if req == nil || req.Operation == nil { |
| 45 | return &dmi.EventsConfigurationResponse{ |
| 46 | Status: dmi.Status_ERROR_STATUS, |
| 47 | //TODO reason must be INVALID_PARAMS, currently this is not available in Device Management interface (DMI), |
| 48 | // change below reason with type INVALID_PARAMS once DMI is updated |
| 49 | Reason: dmi.Reason_UNDEFINED_REASON, |
| 50 | }, status.Errorf(codes.FailedPrecondition, "request is nil") |
| 51 | } |
| 52 | |
| 53 | switch x := req.Operation.(type) { |
| 54 | case *dmi.EventsConfigurationRequest_Changes: |
| 55 | for _, eventConfig := range x.Changes.Items { |
| 56 | UpdateEventConfig(eventConfig) |
| 57 | } |
| 58 | case *dmi.EventsConfigurationRequest_ResetToDefault: |
| 59 | logger.Debugf("To be implemented later") |
| 60 | case nil: |
| 61 | // The field is not set. |
| 62 | logger.Debugf("Update request operation type is nil") |
| 63 | return &dmi.EventsConfigurationResponse{ |
| 64 | Status: dmi.Status_UNDEFINED_STATUS, |
| 65 | }, nil |
| 66 | } |
| 67 | |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 68 | return &dmi.EventsConfigurationResponse{ |
Humera Kouser | a444295 | 2020-11-23 23:51:19 +0530 | [diff] [blame] | 69 | Status: dmi.Status_OK_STATUS, |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 70 | }, nil |
| 71 | } |