blob: 033e6f4f0fedf1a7148e26b6e7699b2b78db5199 [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 }
Rohan Agrawal31f21802020-06-12 05:38:46 +000031 logger.Debugw(ctx, "updatePmConfigs", log.Fields{"device-id": pmConfigs.Id})
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070032
Kent Hagermanf6db9f12020-07-22 17:16:19 -040033 cloned := agent.cloneDeviceWithoutLock()
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070034 cloned.PmConfigs = proto.Clone(pmConfigs).(*voltha.PmConfigs)
35 // Store the device
Kent Hagermanf6db9f12020-07-22 17:16:19 -040036 if err := agent.updateDeviceAndReleaseLock(ctx, cloned); err != nil {
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070037 return err
38 }
39 // Send the request to the adapter
40 subCtx, cancel := context.WithTimeout(context.Background(), agent.defaultTimeout)
41 ch, err := agent.adapterProxy.UpdatePmConfigs(subCtx, cloned, pmConfigs)
42 if err != nil {
43 cancel()
44 return err
45 }
46 go agent.waitForAdapterResponse(subCtx, cancel, "updatePmConfigs", ch, agent.onSuccess, agent.onFailure)
47 return nil
48}
49
50func (agent *Agent) initPmConfigs(ctx context.Context, pmConfigs *voltha.PmConfigs) error {
51 if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil {
52 return err
53 }
Rohan Agrawal31f21802020-06-12 05:38:46 +000054 logger.Debugw(ctx, "initPmConfigs", log.Fields{"device-id": pmConfigs.Id})
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070055
Kent Hagermanf6db9f12020-07-22 17:16:19 -040056 cloned := agent.cloneDeviceWithoutLock()
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070057 cloned.PmConfigs = proto.Clone(pmConfigs).(*voltha.PmConfigs)
Kent Hagermanf6db9f12020-07-22 17:16:19 -040058 return agent.updateDeviceAndReleaseLock(ctx, cloned)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070059}
60
61func (agent *Agent) listPmConfigs(ctx context.Context) (*voltha.PmConfigs, error) {
62 if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil {
63 return nil, err
64 }
65 defer agent.requestQueue.RequestComplete()
Rohan Agrawal31f21802020-06-12 05:38:46 +000066 logger.Debugw(ctx, "listPmConfigs", log.Fields{"device-id": agent.deviceID})
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070067
Kent Hagermanf6db9f12020-07-22 17:16:19 -040068 return agent.getDeviceReadOnly().PmConfigs, nil
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070069}