blob: 5ce3e964f8a585a5e5a9352c53178c7426930ad7 [file] [log] [blame]
Rich Lane99d9a8d2014-06-13 14:05:10 -07001:: # Copyright 2014, Big Switch Networks, Inc.
2:: #
3:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
4:: # the following special exception:
5:: #
6:: # LOXI Exception
7:: #
8:: # As a special exception to the terms of the EPL, you may distribute libraries
9:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
10:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
11:: # from the LoxiGen Libraries and the notice provided below is (i) included in
12:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
13:: # documentation for the LoxiGen Libraries, if distributed in binary form.
14:: #
15:: # Notice: "Copyright 2014, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
16:: #
17:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
18:: # a copy of the EPL at:
19:: #
20:: # http://www.eclipse.org/legal/epl-v10.html
21:: #
22:: # Unless required by applicable law or agreed to in writing, software
23:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25:: # EPL for the specific language governing permissions and limitations
26:: # under the EPL.
27::
28:: include('_copyright.c')
29:: include('_pragmas.c')
30
31#include "loci_log.h"
32#include "loci_int.h"
33
34/**
35 * Associate an iterator with a list
36 * @param list The list to iterate over
37 * @param obj The list entry iteration pointer
38 * @return OF_ERROR_RANGE if the list is empty (end of list)
39 *
40 * The obj instance is completely initialized. The caller is responsible
41 * for cleaning up any wire buffers associated with obj before this call
42 */
43
44int
45${cls}_first(${cls}_t *list, ${e_cls}_t *_obj)
46{
47 int rv;
48 of_object_t *obj = (of_object_t *)_obj;
49
50 ${e_cls}_init(_obj, list->version, 0, 1);
51
52 if ((rv = of_list_first(list, obj)) < 0) {
53 return rv;
54 }
55
Rich Lane83f958d2014-06-13 15:01:40 -070056:: if e_uclass.virtual:
57 ${e_cls}_wire_object_id_get(obj, &obj->object_id);
58:: #endif
59
Rich Lanebbf5e1d2014-06-13 15:34:21 -070060:: if wire_length_get != 'NULL':
61 ${wire_length_get}(obj, &obj->length);
Rich Lane83f958d2014-06-13 15:01:40 -070062:: else:
63 obj->length = of_object_fixed_len[obj->version][obj->object_id];
64:: #endif
Rich Lane99d9a8d2014-06-13 14:05:10 -070065
66 return rv;
67}
68
69/**
70 * Advance an iterator to the next element in a list
71 * @param list The list being iterated
72 * @param obj The list entry iteration pointer
73 * @return OF_ERROR_RANGE if already at the last entry on the list
74 *
75 */
76
77int
78${cls}_next(${cls}_t *list, ${e_cls}_t *_obj)
79{
80 int rv;
81 of_object_t *obj = (of_object_t *)_obj;
82
83 if ((rv = of_list_next(list, obj)) < 0) {
84 return rv;
85 }
86
Rich Lane83f958d2014-06-13 15:01:40 -070087:: if e_uclass.virtual:
88 ${e_cls}_wire_object_id_get(obj, &obj->object_id);
89:: #endif
Rich Lane99d9a8d2014-06-13 14:05:10 -070090
Rich Lanebbf5e1d2014-06-13 15:34:21 -070091:: if wire_length_get != 'NULL':
92 ${wire_length_get}(obj, &obj->length);
Rich Lane83f958d2014-06-13 15:01:40 -070093:: else:
94 obj->length = of_object_fixed_len[obj->version][obj->object_id];
95:: #endif
Rich Lane99d9a8d2014-06-13 14:05:10 -070096
97 return rv;
98}
99
100/**
101 * Set up to append an object of type ${e_cls} to an ${cls}.
102 * @param list The list that is prepared for append
103 * @param obj Pointer to object to hold data to append
104 *
105 * The obj instance is completely initialized. The caller is responsible
106 * for cleaning up any wire buffers associated with obj before this call.
107 *
108 * See the generic documentation for of_list_append_bind.
109 */
110
111int
112${cls}_append_bind(${cls}_t *list, ${e_cls}_t *obj)
113{
114 return of_list_append_bind(list, (of_object_t *)obj);
115}
116
117/**
118 * Append an object to a ${cls} list.
119 *
120 * This copies data from obj and leaves item untouched.
121 *
122 * See the generic documentation for of_list_append.
123 */
124
125int
126${cls}_append(${cls}_t *list, ${e_cls}_t *obj)
127{
128 return of_list_append(list, (of_object_t *)obj);
129}