blob: 8432b9bb48a96bc7aea230967476be4182679a59 [file] [log] [blame]
Mahir Gunyelfa6ea272020-06-10 17:03:51 -07001/*
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
17package device
18
19import (
20 "context"
21
22 "github.com/gogo/protobuf/proto"
23 "github.com/opencord/voltha-lib-go/v3/pkg/log"
24 "github.com/opencord/voltha-protos/v3/go/voltha"
25)
26
27func (agent *Agent) updatePmConfigs(ctx context.Context, pmConfigs *voltha.PmConfigs) error {
28 if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil {
29 return err
30 }
31 defer agent.requestQueue.RequestComplete()
32 logger.Debugw("updatePmConfigs", log.Fields{"device-id": pmConfigs.Id})
33
34 cloned := agent.getDeviceWithoutLock()
35 cloned.PmConfigs = proto.Clone(pmConfigs).(*voltha.PmConfigs)
36 // Store the device
37 if err := agent.updateDeviceInStoreWithoutLock(ctx, cloned, false, ""); err != nil {
38 return err
39 }
40 // Send the request to the adapter
41 subCtx, cancel := context.WithTimeout(context.Background(), agent.defaultTimeout)
42 ch, err := agent.adapterProxy.UpdatePmConfigs(subCtx, cloned, pmConfigs)
43 if err != nil {
44 cancel()
45 return err
46 }
47 go agent.waitForAdapterResponse(subCtx, cancel, "updatePmConfigs", ch, agent.onSuccess, agent.onFailure)
48 return nil
49}
50
51func (agent *Agent) initPmConfigs(ctx context.Context, pmConfigs *voltha.PmConfigs) error {
52 if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil {
53 return err
54 }
55 defer agent.requestQueue.RequestComplete()
56 logger.Debugw("initPmConfigs", log.Fields{"device-id": pmConfigs.Id})
57
58 cloned := agent.getDeviceWithoutLock()
59 cloned.PmConfigs = proto.Clone(pmConfigs).(*voltha.PmConfigs)
60 return agent.updateDeviceInStoreWithoutLock(ctx, cloned, false, "")
61}
62
63func (agent *Agent) listPmConfigs(ctx context.Context) (*voltha.PmConfigs, error) {
64 if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil {
65 return nil, err
66 }
67 defer agent.requestQueue.RequestComplete()
68 logger.Debugw("listPmConfigs", log.Fields{"device-id": agent.deviceID})
69
70 return agent.getDeviceWithoutLock().PmConfigs, nil
71}