blob: 623d24ba958138b82786e7989a951f30e2eb2de3 [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"
William Kurkiandaa6bb22019-03-07 12:26:28 -050020 "github.com/opencord/voltha-protos/go/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
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040036var callbackMutex sync.Mutex
37
38func commonChanCallback(args ...interface{}) interface{} {
39 log.Infof("Running common callback - arg count: %d", len(args))
Stephane Barbariea188d942018-10-16 16:43:04 -040040
Stephane Barbarie1039ec42019-02-04 10:43:16 -050041 //for i := 0; i < len(args); i++ {
42 // log.Infof("ARG %d : %+v", i, args[i])
43 //}
Stephane Barbariedc5022d2018-11-19 15:21:44 -050044
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040045 callbackMutex.Lock()
46 defer callbackMutex.Unlock()
Stephane Barbarie1039ec42019-02-04 10:43:16 -050047
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040048 execDoneChan := args[1].(*chan struct{})
Stephane Barbariea188d942018-10-16 16:43:04 -040049
50 // Inform the caller that the callback was executed
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040051 if *execDoneChan != nil {
52 log.Infof("Sending completion indication - stack:%s", string(debug.Stack()))
53 close(*execDoneChan)
54 *execDoneChan = nil
55 }
Stephane Barbariedc5022d2018-11-19 15:21:44 -050056
57 return nil
58}
59
60func commonCallback2(args ...interface{}) interface{} {
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040061 log.Infof("Running common2 callback - arg count: %d %+v", len(args), args)
Stephane Barbariedc5022d2018-11-19 15:21:44 -050062
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)
Stephane Barbariea188d942018-10-16 16:43:04 -040076
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}
Stephane Barbariedc5022d2018-11-19 15:21:44 -050086
Stephane Barbariea188d942018-10-16 16:43:04 -040087func 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 Barbariedc5022d2018-11-19 15:21:44 -050095
Stephane Barbariea188d942018-10-16 16:43:04 -040096func 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}