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-protos/v3/go/voltha" |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 24 | ) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 25 | |
| 26 | var callbackMutex sync.Mutex |
| 27 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 28 | func commonChanCallback(ctx context.Context, args ...interface{}) interface{} { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 29 | logger.Infof("Running common callback - arg count: %d", len(args)) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 30 | |
| 31 | //for i := 0; i < len(args); i++ { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 32 | // logger.Infof("ARG %d : %+v", i, args[i]) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 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 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 42 | logger.Infof("Sending completion indication - stack:%s", string(debug.Stack())) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 43 | close(*execDoneChan) |
| 44 | *execDoneChan = nil |
| 45 | } |
| 46 | |
| 47 | return nil |
| 48 | } |
| 49 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 50 | func commonCallback2(ctx context.Context, args ...interface{}) interface{} { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 51 | logger.Infof("Running common2 callback - arg count: %d %+v", len(args), args) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 52 | |
| 53 | return nil |
| 54 | } |
| 55 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 56 | func commonCallbackFunc(ctx context.Context, args ...interface{}) interface{} { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 57 | logger.Infof("Running common callback - arg count: %d", len(args)) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 58 | |
| 59 | for i := 0; i < len(args); i++ { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 60 | logger.Infof("ARG %d : %+v", i, args[i]) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 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 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 70 | func firstCallback(ctx context.Context, args ...interface{}) interface{} { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 71 | name := args[0] |
| 72 | id := args[1] |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 73 | logger.Infof("Running first callback - name: %s, id: %s\n", name, id) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 74 | return nil |
| 75 | } |
| 76 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 77 | func secondCallback(ctx context.Context, args ...interface{}) interface{} { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 78 | name := args[0].(map[string]string) |
| 79 | id := args[1] |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 80 | logger.Infof("Running second callback - name: %s, id: %f\n", name["name"], id) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 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 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 86 | func thirdCallback(ctx context.Context, args ...interface{}) interface{} { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 87 | name := args[0] |
| 88 | id := args[1].(*voltha.Device) |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 89 | logger.Infof("Running third callback - name: %+v, id: %s\n", name, id.Id) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 90 | return nil |
| 91 | } |