blob: 38f456759e152c03806c2e5ab7072a0b01002aa9 [file] [log] [blame]
Stephane Barbariea188d942018-10-16 16:43:04 -04001/*
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 */
16package model
17
18import (
19 "github.com/opencord/voltha-go/common/log"
Stephane Barbariea188d942018-10-16 16:43:04 -040020 "github.com/opencord/voltha-go/protos/voltha"
Stephane Barbarie1039ec42019-02-04 10:43:16 -050021 "runtime/debug"
Stephane Barbariedc5022d2018-11-19 15:21:44 -050022 "sync"
Stephane Barbariea188d942018-10-16 16:43:04 -040023)
24
25type 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 Barbariea188d942018-10-16 16:43:04 -040036func commonCallback(args ...interface{}) interface{} {
37 log.Infof("Running common callback - arg count: %s", len(args))
38
Stephane Barbarie1039ec42019-02-04 10:43:16 -050039 //for i := 0; i < len(args); i++ {
40 // log.Infof("ARG %d : %+v", i, args[i])
41 //}
Stephane Barbariedc5022d2018-11-19 15:21:44 -050042
43 mutex := sync.Mutex{}
Stephane Barbarie1039ec42019-02-04 10:43:16 -050044 mutex.Lock()
45 defer mutex.Unlock()
46
Stephane Barbariea188d942018-10-16 16:43:04 -040047 execStatus := args[1].(*bool)
48
49 // Inform the caller that the callback was executed
50 *execStatus = true
Stephane Barbarie1039ec42019-02-04 10:43:16 -050051 log.Infof("Changed value of exec status to true - stack:%s", string(debug.Stack()))
Stephane Barbariedc5022d2018-11-19 15:21:44 -050052
53 return nil
54}
55
56func commonCallback2(args ...interface{}) interface{} {
Stephane Barbarie1039ec42019-02-04 10:43:16 -050057 log.Infof("Running common2 callback - arg count: %s %+v", len(args), args)
Stephane Barbariedc5022d2018-11-19 15:21:44 -050058
59 return nil
60}
61
62func 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 Barbariea188d942018-10-16 16:43:04 -040072
73 return nil
74}
75
76func 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 Barbariedc5022d2018-11-19 15:21:44 -050082
Stephane Barbariea188d942018-10-16 16:43:04 -040083func 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 Barbariedc5022d2018-11-19 15:21:44 -050091
Stephane Barbariea188d942018-10-16 16:43:04 -040092func 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}