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 | |
Stephane Barbarie | a188d94 | 2018-10-16 16:43:04 -0400 | [diff] [blame] | 36 | func commonCallback(args ...interface{}) interface{} { |
| 37 | log.Infof("Running common callback - arg count: %s", len(args)) |
| 38 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 39 | //for i := 0; i < len(args); i++ { |
| 40 | // log.Infof("ARG %d : %+v", i, args[i]) |
| 41 | //} |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 42 | |
| 43 | mutex := sync.Mutex{} |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 44 | mutex.Lock() |
| 45 | defer mutex.Unlock() |
| 46 | |
Stephane Barbarie | a188d94 | 2018-10-16 16:43:04 -0400 | [diff] [blame] | 47 | execStatus := args[1].(*bool) |
| 48 | |
| 49 | // Inform the caller that the callback was executed |
| 50 | *execStatus = true |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 51 | log.Infof("Changed value of exec status to true - stack:%s", string(debug.Stack())) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 52 | |
| 53 | return nil |
| 54 | } |
| 55 | |
| 56 | func commonCallback2(args ...interface{}) interface{} { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 57 | log.Infof("Running common2 callback - arg count: %s %+v", len(args), args) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 58 | |
| 59 | return nil |
| 60 | } |
| 61 | |
| 62 | func commonCallbackFunc(args ...interface{}) interface{} { |
| 63 | log.Infof("Running common callback - arg count: %d", len(args)) |
| 64 | |
| 65 | for i := 0; i < len(args); i++ { |
| 66 | log.Infof("ARG %d : %+v", i, args[i]) |
| 67 | } |
| 68 | execStatusFunc := args[1].(func(bool)) |
| 69 | |
| 70 | // Inform the caller that the callback was executed |
| 71 | execStatusFunc(true) |
Stephane Barbarie | a188d94 | 2018-10-16 16:43:04 -0400 | [diff] [blame] | 72 | |
| 73 | return nil |
| 74 | } |
| 75 | |
| 76 | func firstCallback(args ...interface{}) interface{} { |
| 77 | name := args[0] |
| 78 | id := args[1] |
| 79 | log.Infof("Running first callback - name: %s, id: %s\n", name, id) |
| 80 | return nil |
| 81 | } |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 82 | |
Stephane Barbarie | a188d94 | 2018-10-16 16:43:04 -0400 | [diff] [blame] | 83 | func secondCallback(args ...interface{}) interface{} { |
| 84 | name := args[0].(map[string]string) |
| 85 | id := args[1] |
| 86 | log.Infof("Running second callback - name: %s, id: %f\n", name["name"], id) |
| 87 | // FIXME: the panic call seem to interfere with the logging mechanism |
| 88 | //panic("Generating a panic in second callback") |
| 89 | return nil |
| 90 | } |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 91 | |
Stephane Barbarie | a188d94 | 2018-10-16 16:43:04 -0400 | [diff] [blame] | 92 | func thirdCallback(args ...interface{}) interface{} { |
| 93 | name := args[0] |
| 94 | id := args[1].(*voltha.Device) |
| 95 | log.Infof("Running third callback - name: %+v, id: %s\n", name, id.Id) |
| 96 | return nil |
| 97 | } |