blob: 94bb185fbb12a345bdd15377b6b8eae1ccf2266c [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 (
npujar467fe752020-01-16 20:17:45 +053019 "context"
sbarbari17d7e222019-11-05 10:02:29 -050020 "runtime/debug"
21 "sync"
sbarbari17d7e222019-11-05 10:02:29 -050022
serkant.uluderya2ae470f2020-01-21 11:13:09 -080023 "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
npujar467fe752020-01-16 20:17:45 +053028func commonChanCallback(ctx context.Context, args ...interface{}) interface{} {
Girish Kumarf56a4682020-03-20 20:07:46 +000029 logger.Infof("Running common callback - arg count: %d", len(args))
sbarbari17d7e222019-11-05 10:02:29 -050030
31 //for i := 0; i < len(args); i++ {
Girish Kumarf56a4682020-03-20 20:07:46 +000032 // logger.Infof("ARG %d : %+v", i, args[i])
sbarbari17d7e222019-11-05 10:02:29 -050033 //}
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 {
Girish Kumarf56a4682020-03-20 20:07:46 +000042 logger.Infof("Sending completion indication - stack:%s", string(debug.Stack()))
sbarbari17d7e222019-11-05 10:02:29 -050043 close(*execDoneChan)
44 *execDoneChan = nil
45 }
46
47 return nil
48}
49
npujar467fe752020-01-16 20:17:45 +053050func commonCallback2(ctx context.Context, args ...interface{}) interface{} {
Girish Kumarf56a4682020-03-20 20:07:46 +000051 logger.Infof("Running common2 callback - arg count: %d %+v", len(args), args)
sbarbari17d7e222019-11-05 10:02:29 -050052
53 return nil
54}
55
npujar467fe752020-01-16 20:17:45 +053056func commonCallbackFunc(ctx context.Context, args ...interface{}) interface{} {
Girish Kumarf56a4682020-03-20 20:07:46 +000057 logger.Infof("Running common callback - arg count: %d", len(args))
sbarbari17d7e222019-11-05 10:02:29 -050058
59 for i := 0; i < len(args); i++ {
Girish Kumarf56a4682020-03-20 20:07:46 +000060 logger.Infof("ARG %d : %+v", i, args[i])
sbarbari17d7e222019-11-05 10:02:29 -050061 }
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
npujar467fe752020-01-16 20:17:45 +053070func firstCallback(ctx context.Context, args ...interface{}) interface{} {
sbarbari17d7e222019-11-05 10:02:29 -050071 name := args[0]
72 id := args[1]
Girish Kumarf56a4682020-03-20 20:07:46 +000073 logger.Infof("Running first callback - name: %s, id: %s\n", name, id)
sbarbari17d7e222019-11-05 10:02:29 -050074 return nil
75}
76
npujar467fe752020-01-16 20:17:45 +053077func secondCallback(ctx context.Context, args ...interface{}) interface{} {
sbarbari17d7e222019-11-05 10:02:29 -050078 name := args[0].(map[string]string)
79 id := args[1]
Girish Kumarf56a4682020-03-20 20:07:46 +000080 logger.Infof("Running second callback - name: %s, id: %f\n", name["name"], id)
sbarbari17d7e222019-11-05 10:02:29 -050081 // FIXME: the panic call seem to interfere with the logging mechanism
82 //panic("Generating a panic in second callback")
83 return nil
84}
85
npujar467fe752020-01-16 20:17:45 +053086func thirdCallback(ctx context.Context, args ...interface{}) interface{} {
sbarbari17d7e222019-11-05 10:02:29 -050087 name := args[0]
88 id := args[1].(*voltha.Device)
Girish Kumarf56a4682020-03-20 20:07:46 +000089 logger.Infof("Running third callback - name: %+v, id: %s\n", name, id.Id)
sbarbari17d7e222019-11-05 10:02:29 -050090 return nil
91}