blob: 4f44e45e6549394ef536337f13ebe6c2db4801ac [file] [log] [blame]
Scott Baker2c1c4822019-10-16 11:02:41 -07001/*
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 (
Scott Bakerce767002019-10-23 13:30:24 -070019 "github.com/opencord/voltha-lib-go/v2/pkg/log"
Scott Baker2c1c4822019-10-16 11:02:41 -070020 "github.com/opencord/voltha-protos/go/voltha"
21 "runtime/debug"
22 "sync"
23)
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
36var callbackMutex sync.Mutex
37
38func commonChanCallback(args ...interface{}) interface{} {
39 log.Infof("Running common callback - arg count: %d", len(args))
40
41 //for i := 0; i < len(args); i++ {
42 // log.Infof("ARG %d : %+v", i, args[i])
43 //}
44
45 callbackMutex.Lock()
46 defer callbackMutex.Unlock()
47
48 execDoneChan := args[1].(*chan struct{})
49
50 // Inform the caller that the callback was executed
51 if *execDoneChan != nil {
52 log.Infof("Sending completion indication - stack:%s", string(debug.Stack()))
53 close(*execDoneChan)
54 *execDoneChan = nil
55 }
56
57 return nil
58}
59
60func commonCallback2(args ...interface{}) interface{} {
61 log.Infof("Running common2 callback - arg count: %d %+v", len(args), args)
62
63 return nil
64}
65
66func 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)
76
77 return nil
78}
79
80func 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}
86
87func 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}
95
96func 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}