blob: 3c38ad9dedc0f23ef6b316ef88823c8c19266216 [file] [log] [blame]
amit.ghosh258d14c2020-10-02 15:13:38 +02001/*
Joey Armstrong3881b732022-12-27 07:55:37 -05002 * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors
amit.ghosh258d14c2020-10-02 15:13:38 +02003
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
17package dmiserver
18
19import (
20 "context"
Hardik Windlass63e35cf2022-02-03 05:58:09 +000021 "github.com/golang/protobuf/ptypes/empty"
hkouser24361d42020-12-14 19:21:47 +053022 "google.golang.org/grpc/codes"
23 "google.golang.org/grpc/status"
amit.ghosh258d14c2020-10-02 15:13:38 +020024
25 dmi "github.com/opencord/device-management-interface/go/dmi"
26)
27
28//ListEvents lists the supported events for the passed device
29func (dms *DmiAPIServer) ListEvents(ctx context.Context, req *dmi.HardwareID) (*dmi.ListEventsResponse, error) {
30 logger.Debugf("ListEvents called with request %+v", req)
hkouser24361d42020-12-14 19:21:47 +053031 events := getEventsList()
32
amit.ghosh258d14c2020-10-02 15:13:38 +020033 return &dmi.ListEventsResponse{
Humera Kousera4442952020-11-23 23:51:19 +053034 Status: dmi.Status_OK_STATUS,
amit.ghosh258d14c2020-10-02 15:13:38 +020035 Events: &dmi.EventsCfg{
36 Items: events,
37 },
38 }, nil
39}
40
41//UpdateEventsConfiguration updates the configuration of the list of events in the request
42func (dms *DmiAPIServer) UpdateEventsConfiguration(ctx context.Context, req *dmi.EventsConfigurationRequest) (*dmi.EventsConfigurationResponse, error) {
43 logger.Debugf("UpdateEventsConfiguration called with request %+v", req)
hkouser24361d42020-12-14 19:21:47 +053044
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
ssiddiqui6ca40702021-03-08 18:20:21 +053050 Reason: dmi.EventsConfigurationResponse_UNDEFINED_REASON,
hkouser24361d42020-12-14 19:21:47 +053051 }, 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.ghosh258d14c2020-10-02 15:13:38 +020069 return &dmi.EventsConfigurationResponse{
Humera Kousera4442952020-11-23 23:51:19 +053070 Status: dmi.Status_OK_STATUS,
amit.ghosh258d14c2020-10-02 15:13:38 +020071 }, nil
72}
Hardik Windlass63e35cf2022-02-03 05:58:09 +000073
74// Initiates the server streaming of the events
75func (dms *DmiAPIServer) StreamEvents(req *empty.Empty, srv dmi.NativeEventsManagementService_StreamEventsServer) error {
76 return status.Errorf(codes.Unimplemented, "rpc StreamEvents not implemented")
77}