blob: 91fa89f31d908071ccb846fccdb06035f0540f6b [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-lib-go/v3/pkg/log"
24 "github.com/opencord/voltha-protos/v3/go/voltha"
npujar9a30c702019-11-14 17:06:39 +053025)
sbarbari17d7e222019-11-05 10:02:29 -050026
27var callbackMutex sync.Mutex
28
npujar467fe752020-01-16 20:17:45 +053029func commonChanCallback(ctx context.Context, args ...interface{}) interface{} {
sbarbari17d7e222019-11-05 10:02:29 -050030 log.Infof("Running common callback - arg count: %d", len(args))
31
32 //for i := 0; i < len(args); i++ {
33 // log.Infof("ARG %d : %+v", i, args[i])
34 //}
35
36 callbackMutex.Lock()
37 defer callbackMutex.Unlock()
38
39 execDoneChan := args[1].(*chan struct{})
40
41 // Inform the caller that the callback was executed
42 if *execDoneChan != nil {
43 log.Infof("Sending completion indication - stack:%s", string(debug.Stack()))
44 close(*execDoneChan)
45 *execDoneChan = nil
46 }
47
48 return nil
49}
50
npujar467fe752020-01-16 20:17:45 +053051func commonCallback2(ctx context.Context, args ...interface{}) interface{} {
sbarbari17d7e222019-11-05 10:02:29 -050052 log.Infof("Running common2 callback - arg count: %d %+v", len(args), args)
53
54 return nil
55}
56
npujar467fe752020-01-16 20:17:45 +053057func commonCallbackFunc(ctx context.Context, args ...interface{}) interface{} {
sbarbari17d7e222019-11-05 10:02:29 -050058 log.Infof("Running common callback - arg count: %d", len(args))
59
60 for i := 0; i < len(args); i++ {
61 log.Infof("ARG %d : %+v", i, args[i])
62 }
63 execStatusFunc := args[1].(func(bool))
64
65 // Inform the caller that the callback was executed
66 execStatusFunc(true)
67
68 return nil
69}
70
npujar467fe752020-01-16 20:17:45 +053071func firstCallback(ctx context.Context, args ...interface{}) interface{} {
sbarbari17d7e222019-11-05 10:02:29 -050072 name := args[0]
73 id := args[1]
74 log.Infof("Running first callback - name: %s, id: %s\n", name, id)
75 return nil
76}
77
npujar467fe752020-01-16 20:17:45 +053078func secondCallback(ctx context.Context, args ...interface{}) interface{} {
sbarbari17d7e222019-11-05 10:02:29 -050079 name := args[0].(map[string]string)
80 id := args[1]
81 log.Infof("Running second callback - name: %s, id: %f\n", name["name"], id)
82 // FIXME: the panic call seem to interfere with the logging mechanism
83 //panic("Generating a panic in second callback")
84 return nil
85}
86
npujar467fe752020-01-16 20:17:45 +053087func thirdCallback(ctx context.Context, args ...interface{}) interface{} {
sbarbari17d7e222019-11-05 10:02:29 -050088 name := args[0]
89 id := args[1].(*voltha.Device)
90 log.Infof("Running third callback - name: %+v, id: %s\n", name, id.Id)
91 return nil
92}