blob: 45a6cdcda05e40d74117bf1aac01f747e5b9f95f [file] [log] [blame]
sbarbari17d7e222019-11-05 10:02:29 -05001/*
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-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
26type 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
37var callbackMutex sync.Mutex
38
39func 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
61func commonCallback2(args ...interface{}) interface{} {
62 log.Infof("Running common2 callback - arg count: %d %+v", len(args), args)
63
64 return nil
65}
66
67func 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
81func 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
88func 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
97func 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}