sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [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 | package model |
| 17 | |
| 18 | import ( |
| 19 | "github.com/opencord/voltha-lib-go/v2/pkg/db" |
| 20 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
| 21 | "github.com/opencord/voltha-protos/v2/go/voltha" |
| 22 | "runtime/debug" |
| 23 | "sync" |
| 24 | ) |
| 25 | |
| 26 | type ModelTestConfig struct { |
| 27 | Root *root |
| 28 | Backend *db.Backend |
| 29 | RootProxy *Proxy |
| 30 | DbPrefix string |
| 31 | DbType string |
| 32 | DbHost string |
| 33 | DbPort int |
| 34 | DbTimeout int |
| 35 | } |
| 36 | |
| 37 | var callbackMutex sync.Mutex |
| 38 | |
| 39 | func commonChanCallback(args ...interface{}) interface{} { |
| 40 | log.Infof("Running common callback - arg count: %d", len(args)) |
| 41 | |
| 42 | //for i := 0; i < len(args); i++ { |
| 43 | // log.Infof("ARG %d : %+v", i, args[i]) |
| 44 | //} |
| 45 | |
| 46 | callbackMutex.Lock() |
| 47 | defer callbackMutex.Unlock() |
| 48 | |
| 49 | execDoneChan := args[1].(*chan struct{}) |
| 50 | |
| 51 | // Inform the caller that the callback was executed |
| 52 | if *execDoneChan != nil { |
| 53 | log.Infof("Sending completion indication - stack:%s", string(debug.Stack())) |
| 54 | close(*execDoneChan) |
| 55 | *execDoneChan = nil |
| 56 | } |
| 57 | |
| 58 | return nil |
| 59 | } |
| 60 | |
| 61 | func commonCallback2(args ...interface{}) interface{} { |
| 62 | log.Infof("Running common2 callback - arg count: %d %+v", len(args), args) |
| 63 | |
| 64 | return nil |
| 65 | } |
| 66 | |
| 67 | func commonCallbackFunc(args ...interface{}) interface{} { |
| 68 | log.Infof("Running common callback - arg count: %d", len(args)) |
| 69 | |
| 70 | for i := 0; i < len(args); i++ { |
| 71 | log.Infof("ARG %d : %+v", i, args[i]) |
| 72 | } |
| 73 | execStatusFunc := args[1].(func(bool)) |
| 74 | |
| 75 | // Inform the caller that the callback was executed |
| 76 | execStatusFunc(true) |
| 77 | |
| 78 | return nil |
| 79 | } |
| 80 | |
| 81 | func firstCallback(args ...interface{}) interface{} { |
| 82 | name := args[0] |
| 83 | id := args[1] |
| 84 | log.Infof("Running first callback - name: %s, id: %s\n", name, id) |
| 85 | return nil |
| 86 | } |
| 87 | |
| 88 | func secondCallback(args ...interface{}) interface{} { |
| 89 | name := args[0].(map[string]string) |
| 90 | id := args[1] |
| 91 | log.Infof("Running second callback - name: %s, id: %f\n", name["name"], id) |
| 92 | // FIXME: the panic call seem to interfere with the logging mechanism |
| 93 | //panic("Generating a panic in second callback") |
| 94 | return nil |
| 95 | } |
| 96 | |
| 97 | func thirdCallback(args ...interface{}) interface{} { |
| 98 | name := args[0] |
| 99 | id := args[1].(*voltha.Device) |
| 100 | log.Infof("Running third callback - name: %+v, id: %s\n", name, id.Id) |
| 101 | return nil |
| 102 | } |