sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package model |
| 17 | |
| 18 | import ( |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 19 | "context" |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 20 | "runtime/debug" |
| 21 | "sync" |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 22 | |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 23 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 24 | "github.com/opencord/voltha-protos/v3/go/voltha" |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 25 | ) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 26 | |
| 27 | var callbackMutex sync.Mutex |
| 28 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 29 | func commonChanCallback(ctx context.Context, args ...interface{}) interface{} { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 30 | 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 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 51 | func commonCallback2(ctx context.Context, args ...interface{}) interface{} { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 52 | log.Infof("Running common2 callback - arg count: %d %+v", len(args), args) |
| 53 | |
| 54 | return nil |
| 55 | } |
| 56 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 57 | func commonCallbackFunc(ctx context.Context, args ...interface{}) interface{} { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 58 | 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 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 71 | func firstCallback(ctx context.Context, args ...interface{}) interface{} { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 72 | 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 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 78 | func secondCallback(ctx context.Context, args ...interface{}) interface{} { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 79 | 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 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 87 | func thirdCallback(ctx context.Context, args ...interface{}) interface{} { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 88 | 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 | } |