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