David Bainbridge | f8ce7d2 | 2020-04-08 12:49:41 -0700 | [diff] [blame] | 1 | /* |
Joey Armstrong | 9bc3fa5 | 2023-01-03 14:10:07 -0500 | [diff] [blame] | 2 | * Copyright 2020-2023 Open Networking Foundation (ONF) and the ONF Contributors |
David Bainbridge | f8ce7d2 | 2020-04-08 12:49:41 -0700 | [diff] [blame] | 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 holder |
| 18 | |
| 19 | import ( |
| 20 | "sync" |
| 21 | |
David K. Bainbridge | e05cf0c | 2021-08-19 03:16:50 +0000 | [diff] [blame] | 22 | "github.com/opencord/voltha-protos/v5/go/voltha" |
David Bainbridge | f8ce7d2 | 2020-04-08 12:49:41 -0700 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | // VolthaServiceClientHolder provides a consistent (voluntarily unmutable) reference |
| 26 | // point for a mutable value that represents a GRPC service interface to |
| 27 | // VOLTHA |
| 28 | type VolthaServiceClientHolder struct { |
| 29 | mutex sync.RWMutex |
| 30 | volthaSvcClient voltha.VolthaServiceClient |
| 31 | } |
| 32 | |
| 33 | type VolthaServiceClientReference struct { |
| 34 | } |
| 35 | |
| 36 | // Clear sets the held value to nil (not set) |
| 37 | func (h *VolthaServiceClientHolder) Clear() { |
| 38 | h.mutex.Lock() |
| 39 | defer h.mutex.Unlock() |
| 40 | h.volthaSvcClient = nil |
| 41 | } |
| 42 | |
| 43 | // Set assigns the value being held to the specified value |
| 44 | func (h *VolthaServiceClientHolder) Set(client voltha.VolthaServiceClient) { |
| 45 | h.mutex.Lock() |
| 46 | defer h.mutex.Unlock() |
| 47 | h.volthaSvcClient = client |
| 48 | } |
| 49 | |
| 50 | // Get returns the currently held value |
| 51 | func (h *VolthaServiceClientHolder) Get() voltha.VolthaServiceClient { |
| 52 | h.mutex.RLock() |
| 53 | defer h.mutex.RUnlock() |
| 54 | return h.volthaSvcClient |
| 55 | } |