11
11
// //
12
12
// Unless required by applicable law or agreed to in writing, software //
13
13
// distributed under the License is distributed on an "AS IS" BASIS, //
14
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
14
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
15
15
// See the License for the specific language governing permissions and //
16
16
// limitations under the License. //
17
17
// //
@@ -31,22 +31,23 @@ package translib
31
31
32
32
import (
33
33
"errors"
34
- log "github.com/golang/glog"
35
- "github.com/openconfig/ygot/ygot"
36
34
"reflect"
37
35
"strings"
36
+
38
37
"github.com/Azure/sonic-mgmt-common/translib/db"
38
+ log "github.com/golang/glog"
39
+ "github.com/openconfig/ygot/ygot"
39
40
)
40
41
41
- //Structure containing app module information
42
+ // Structure containing app module information
42
43
type appInfo struct {
43
44
appType reflect.Type
44
45
ygotRootType reflect.Type
45
46
isNative bool
46
47
tablesToWatch []* db.TableSpec
47
48
}
48
49
49
- //Structure containing the app data coming from translib infra
50
+ // Structure containing the app data coming from translib infra
50
51
type appData struct {
51
52
path string
52
53
payload []byte
@@ -59,23 +60,23 @@ type appData struct {
59
60
// These include RESTCONF query parameters like - depth, fields etc.
60
61
type appOptions struct {
61
62
62
- // depth limits subtree levels in the response data.
63
- // 0 indicates unlimited depth.
64
- // Valid for GET API only.
65
- depth uint
63
+ // depth limits subtree levels in the response data.
64
+ // 0 indicates unlimited depth.
65
+ // Valid for GET API only.
66
+ depth uint
66
67
67
- // deleteEmptyEntry indicates if the db entry should be deleted upon
68
- // deletion of last field. This is a non standard option.
69
- deleteEmptyEntry bool
68
+ // deleteEmptyEntry indicates if the db entry should be deleted upon
69
+ // deletion of last field. This is a non standard option.
70
+ deleteEmptyEntry bool
70
71
}
71
72
72
- //map containing the base path to app module info
73
+ // map containing the base path to app module info
73
74
var appMap map [string ]* appInfo
74
75
75
- //array containing all the supported models
76
+ // array containing all the supported models
76
77
var models []ModelData
77
78
78
- //Interface for all App Modules
79
+ // Interface for all App Modules
79
80
type appInterface interface {
80
81
initialize (data appData )
81
82
translateCreate (d * db.DB ) ([]db.WatchKeys , error )
@@ -84,16 +85,17 @@ type appInterface interface {
84
85
translateDelete (d * db.DB ) ([]db.WatchKeys , error )
85
86
translateGet (dbs [db .MaxDB ]* db.DB ) error
86
87
translateAction (dbs [db .MaxDB ]* db.DB ) error
87
- translateSubscribe (dbs [ db . MaxDB ] * db. DB , path string ) (* notificationOpts , * notificationInfo , error )
88
+ translateSubscribe (req * translateSubRequest ) (* translateSubResponse , error )
88
89
processCreate (d * db.DB ) (SetResponse , error )
89
90
processUpdate (d * db.DB ) (SetResponse , error )
90
91
processReplace (d * db.DB ) (SetResponse , error )
91
92
processDelete (d * db.DB ) (SetResponse , error )
92
93
processGet (dbs [db .MaxDB ]* db.DB ) (GetResponse , error )
93
94
processAction (dbs [db .MaxDB ]* db.DB ) (ActionResponse , error )
95
+ processSubscribe (req * processSubRequest ) (processSubResponse , error )
94
96
}
95
97
96
- //App modules will use this function to register with App interface during boot up
98
+ // App modules will use this function to register with App interface during boot up
97
99
func register (path string , info * appInfo ) error {
98
100
var err error
99
101
log .Info ("Registering for path =" , path )
@@ -114,7 +116,7 @@ func register(path string, info *appInfo) error {
114
116
return err
115
117
}
116
118
117
- //Adds the model information to the supported models array
119
+ // Adds the model information to the supported models array
118
120
func addModel (model * ModelData ) error {
119
121
var err error
120
122
@@ -124,7 +126,7 @@ func addModel(model *ModelData) error {
124
126
return err
125
127
}
126
128
127
- //Translib infra will use this function get the app info for a given path
129
+ // Translib infra will use this function get the app info for a given path
128
130
func getAppModuleInfo (path string ) (* appInfo , error ) {
129
131
log .Info ("getAppModule called for path =" , path )
130
132
@@ -135,23 +137,23 @@ func getAppModuleInfo(path string) (*appInfo, error) {
135
137
136
138
log .Info ("found the entry in the map for path =" , pattern )
137
139
138
- return app , nil
140
+ return app , nil
139
141
}
140
142
141
143
/* If no specific app registered fallback to default/common app */
142
144
log .Infof ("No app module registered for path %s hence fallback to default/common app" , path )
143
145
app := appMap ["*" ]
144
146
145
- return app , nil
147
+ return app , nil
146
148
}
147
149
148
- //Get all the supported models
150
+ // Get all the supported models
149
151
func getModels () []ModelData {
150
152
151
153
return models
152
154
}
153
155
154
- //Creates a new app from the appType and returns it as an appInterface
156
+ // Creates a new app from the appType and returns it as an appInterface
155
157
func getAppInterface (appType reflect.Type ) (appInterface , error ) {
156
158
var err error
157
159
appInstance := reflect .New (appType )
0 commit comments