Mahir Gunyel | fa6ea27 | 2020-06-10 17:03:51 -0700 | [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 device |
| 18 | |
| 19 | import ( |
| 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 | |
| 27 | func (agent *Agent) updatePmConfigs(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
| 28 | if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil { |
| 29 | return err |
| 30 | } |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 31 | logger.Debugw(ctx, "updatePmConfigs", log.Fields{"device-id": pmConfigs.Id}) |
Mahir Gunyel | fa6ea27 | 2020-06-10 17:03:51 -0700 | [diff] [blame] | 32 | |
Kent Hagerman | f6db9f1 | 2020-07-22 17:16:19 -0400 | [diff] [blame^] | 33 | cloned := agent.cloneDeviceWithoutLock() |
Mahir Gunyel | fa6ea27 | 2020-06-10 17:03:51 -0700 | [diff] [blame] | 34 | cloned.PmConfigs = proto.Clone(pmConfigs).(*voltha.PmConfigs) |
| 35 | // Store the device |
Kent Hagerman | f6db9f1 | 2020-07-22 17:16:19 -0400 | [diff] [blame^] | 36 | if err := agent.updateDeviceAndReleaseLock(ctx, cloned); err != nil { |
Mahir Gunyel | fa6ea27 | 2020-06-10 17:03:51 -0700 | [diff] [blame] | 37 | 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 | |
| 50 | func (agent *Agent) initPmConfigs(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
| 51 | if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil { |
| 52 | return err |
| 53 | } |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 54 | logger.Debugw(ctx, "initPmConfigs", log.Fields{"device-id": pmConfigs.Id}) |
Mahir Gunyel | fa6ea27 | 2020-06-10 17:03:51 -0700 | [diff] [blame] | 55 | |
Kent Hagerman | f6db9f1 | 2020-07-22 17:16:19 -0400 | [diff] [blame^] | 56 | cloned := agent.cloneDeviceWithoutLock() |
Mahir Gunyel | fa6ea27 | 2020-06-10 17:03:51 -0700 | [diff] [blame] | 57 | cloned.PmConfigs = proto.Clone(pmConfigs).(*voltha.PmConfigs) |
Kent Hagerman | f6db9f1 | 2020-07-22 17:16:19 -0400 | [diff] [blame^] | 58 | return agent.updateDeviceAndReleaseLock(ctx, cloned) |
Mahir Gunyel | fa6ea27 | 2020-06-10 17:03:51 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | func (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 Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 66 | logger.Debugw(ctx, "listPmConfigs", log.Fields{"device-id": agent.deviceID}) |
Mahir Gunyel | fa6ea27 | 2020-06-10 17:03:51 -0700 | [diff] [blame] | 67 | |
Kent Hagerman | f6db9f1 | 2020-07-22 17:16:19 -0400 | [diff] [blame^] | 68 | return agent.getDeviceReadOnly().PmConfigs, nil |
Mahir Gunyel | fa6ea27 | 2020-06-10 17:03:51 -0700 | [diff] [blame] | 69 | } |