blob: cf3718e7d09fb430b6f299b8e4fab0abf953b2d7 [file] [log] [blame]
mpagenkoc8bba412021-01-15 15:38:44 +00001/*
2 * Copyright 2020-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 adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
19
20import (
21 "context"
mpagenko057889c2021-01-21 16:51:58 +000022 //"errors"
mpagenkoc8bba412021-01-15 15:38:44 +000023 "sync"
24
25 //"time"
26
27 "github.com/opencord/voltha-protos/v4/go/voltha"
28
29 "github.com/opencord/voltha-lib-go/v4/pkg/log"
30)
31
32// ### downloadToAdapter related definitions ####
33
34//not yet defined to go with sca..., later also some configure options ??
35//const defaultDownloadTimeout = 60 // (?) Seconds
36//const localImgPath = "/home/lcui/work/tmp"
37
38// ### downloadToAdapter - end ####
39
40//adapterDownloadManager structure holds information needed for downloading to and storing images within the adapter
41type adapterDownloadManager struct {
42 mutexDownloadImageDsc sync.RWMutex
43 downloadImageDscSlice []*voltha.ImageDownload
44}
45
46//newAdapterDownloadManager constructor returns a new instance of a adapterDownloadManager
47//mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
48func newAdapterDownloadManager(ctx context.Context) *adapterDownloadManager {
49 logger.Debug(ctx, "init-adapterDownloadManager")
50 var localDnldMgr adapterDownloadManager
51 localDnldMgr.downloadImageDscSlice = make([]*voltha.ImageDownload, 0)
52
53 return &localDnldMgr
54}
55
56//imageExists returns true if the requested image already exists within the adapter
57func (dm *adapterDownloadManager) imageExists(ctx context.Context, apImageDsc *voltha.ImageDownload) bool {
58 logger.Debugw(ctx, "checking on existence of the image", log.Fields{"image-name": (*apImageDsc).Name})
59 dm.mutexDownloadImageDsc.RLock()
60 defer dm.mutexDownloadImageDsc.RUnlock()
61
62 for _, pDnldImgDsc := range dm.downloadImageDscSlice {
63 if (*pDnldImgDsc).Name == (*apImageDsc).Name {
64 //image found (by name)
65 return true
66 }
67 }
68 //image not found (by name)
69 return false
70}
71
72//startDownload returns true if the download of the requested image could be started
73func (dm *adapterDownloadManager) startDownload(ctx context.Context, apImageDsc *voltha.ImageDownload) error {
mpagenko057889c2021-01-21 16:51:58 +000074 logger.Warnw(ctx, "image download requested - but not yet processed", log.Fields{"image-name": apImageDsc.Name})
75 //return success to comfort the core processing during integration
76 return nil
77 // TODO!!: also verify error response behavior
78 //return fmt.Errorf("onuSwUpgrade not yet implemented")
mpagenkoc8bba412021-01-15 15:38:44 +000079}