blob: e9e4caceb23e978097a8d74f4aea3e8f796e9da5 [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 (
sbarbari17d7e222019-11-05 10:02:29 -050019 "runtime/debug"
20 "sync"
sbarbari17d7e222019-11-05 10:02:29 -050021
serkant.uluderya2ae470f2020-01-21 11:13:09 -080022 "github.com/opencord/voltha-lib-go/v3/pkg/log"
23 "github.com/opencord/voltha-protos/v3/go/voltha"
npujar9a30c702019-11-14 17:06:39 +053024)
sbarbari17d7e222019-11-05 10:02:29 -050025
26var callbackMutex sync.Mutex
27
28func commonChanCallback(args ...interface{}) interface{} {
29 log.Infof("Running common callback - arg count: %d", len(args))
30
31 //for i := 0; i < len(args); i++ {
32 // log.Infof("ARG %d : %+v", i, args[i])
33 //}
34
35 callbackMutex.Lock()
36 defer callbackMutex.Unlock()
37
38 execDoneChan := args[1].(*chan struct{})
39
40 // Inform the caller that the callback was executed
41 if *execDoneChan != nil {
42 log.Infof("Sending completion indication - stack:%s", string(debug.Stack()))
43 close(*execDoneChan)
44 *execDoneChan = nil
45 }
46
47 return nil
48}
49
50func commonCallback2(args ...interface{}) interface{} {
51 log.Infof("Running common2 callback - arg count: %d %+v", len(args), args)
52
53 return nil
54}
55
56func commonCallbackFunc(args ...interface{}) interface{} {
57 log.Infof("Running common callback - arg count: %d", len(args))
58
59 for i := 0; i < len(args); i++ {
60 log.Infof("ARG %d : %+v", i, args[i])
61 }
62 execStatusFunc := args[1].(func(bool))
63
64 // Inform the caller that the callback was executed
65 execStatusFunc(true)
66
67 return nil
68}
69
70func firstCallback(args ...interface{}) interface{} {
71 name := args[0]
72 id := args[1]
73 log.Infof("Running first callback - name: %s, id: %s\n", name, id)
74 return nil
75}
76
77func secondCallback(args ...interface{}) interface{} {
78 name := args[0].(map[string]string)
79 id := args[1]
80 log.Infof("Running second callback - name: %s, id: %f\n", name["name"], id)
81 // FIXME: the panic call seem to interfere with the logging mechanism
82 //panic("Generating a panic in second callback")
83 return nil
84}
85
86func thirdCallback(args ...interface{}) interface{} {
87 name := args[0]
88 id := args[1].(*voltha.Device)
89 log.Infof("Running third callback - name: %+v, id: %s\n", name, id.Id)
90 return nil
91}