Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 1 | //:: # Copyright 2013, 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 2013, 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 | //:: import itertools |
| 29 | //:: import of_g |
Yotam Harchol | a86e425 | 2013-09-06 15:36:28 -0700 | [diff] [blame] | 30 | //:: import re |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 31 | //:: include('_copyright.java') |
| 32 | |
| 33 | //:: include('_autogen.java') |
| 34 | |
| 35 | package ${factory.package}; |
| 36 | |
Yotam Harchol | a86e425 | 2013-09-06 15:36:28 -0700 | [diff] [blame] | 37 | import org.projectfloodlight.openflow.protocol.OFOxmList; |
| 38 | |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 39 | //:: include("_imports.java") |
| 40 | |
| 41 | public class ${factory.name} implements ${factory.interface.name} { |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 42 | public final static ${factory.name} INSTANCE = new ${factory.name}(); |
Andreas Wundsam | cb17b23 | 2013-09-28 19:05:36 -0700 | [diff] [blame] | 43 | |
| 44 | //:: if factory.interface.xid_generator: |
| 45 | private final XidGenerator xidGenerator = XidGenerators.global(); |
| 46 | //:: #endif |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 47 | |
| 48 | //:: for name, clazz in factory.interface.sub_factories.items(): |
| 49 | public ${clazz} ${name}() { |
| 50 | return ${clazz}Ver${factory.version.of_version}.INSTANCE; |
| 51 | } |
| 52 | //:: #endfor |
| 53 | |
Yotam Harchol | a86e425 | 2013-09-06 15:36:28 -0700 | [diff] [blame] | 54 | //:: general_get_match_func_written = False |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 55 | //:: for i in factory.interface.members: |
| 56 | //:: if i.is_virtual: |
| 57 | //:: continue |
| 58 | //:: #endif |
Yotam Harchol | a86e425 | 2013-09-06 15:36:28 -0700 | [diff] [blame] | 59 | //:: is_match_object = re.match('OFMatch.*', i.name) # i.has_version(factory.version) and model.generate_class(i.versioned_class(factory.version)) and i.versioned_class(factory.version).interface.parent_interface == 'Match' |
| 60 | //:: unsupported_match_object = is_match_object and not i.has_version(factory.version) |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 61 | |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 62 | //:: if len(i.writeable_members) > 0: |
| 63 | public ${i.name}.Builder ${factory.interface.method_name(i, builder=True)}() { |
| 64 | //:: if i.has_version(factory.version) and model.generate_class(i.versioned_class(factory.version)): |
Andreas Wundsam | cb17b23 | 2013-09-28 19:05:36 -0700 | [diff] [blame] | 65 | return new ${i.versioned_class(factory.version).name}.Builder()${".setXid(nextXid())" if i.member_by_name("xid") else ""}; |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 66 | //:: else: |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 67 | throw new UnsupportedOperationException("${i.name} not supported in version ${factory.version}"); |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 68 | //:: #endif |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 69 | } |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 70 | //:: #endif |
Yotam Harchol | a86e425 | 2013-09-06 15:36:28 -0700 | [diff] [blame] | 71 | //:: if not general_get_match_func_written and is_match_object and not unsupported_match_object: |
| 72 | public Match.Builder buildMatch() { |
| 73 | return new ${i.versioned_class(factory.version).name}.Builder(); |
| 74 | } |
Andreas Wundsam | e962d37 | 2013-10-02 18:15:58 -0700 | [diff] [blame] | 75 | |
| 76 | final static Match MATCH_WILDCARD_ALL = ${i.versioned_class(factory.version).name}.DEFAULT; |
| 77 | |
| 78 | public Match matchWildcardAll() { |
| 79 | return MATCH_WILDCARD_ALL; |
| 80 | } |
Yotam Harchol | a86e425 | 2013-09-06 15:36:28 -0700 | [diff] [blame] | 81 | //:: general_get_match_func_written = True |
| 82 | //:: #endif |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 83 | //:: if len(i.writeable_members) <= 2: |
Andreas Wundsam | cb17b23 | 2013-09-28 19:05:36 -0700 | [diff] [blame] | 84 | public ${i.name} ${factory.interface.method_name(i, builder=False)}(${", ".join("%s %s" % (p.java_type.public_type, p.name) for p in i.writeable_members if p.name != "xid" )}) { |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 85 | //:: if i.has_version(factory.version) and model.generate_class(i.versioned_class(factory.version)): |
| 86 | //:: if len(i.writeable_members) > 0: |
| 87 | return new ${i.versioned_class(factory.version).name}( |
| 88 | ${",\n ".join( |
Andreas Wundsam | cb17b23 | 2013-09-28 19:05:36 -0700 | [diff] [blame] | 89 | [ prop.name if prop.name != "xid" else "nextXid()" for prop in i.versioned_class(factory.version).data_members])} |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 90 | ); |
| 91 | //:: else: |
| 92 | return ${i.versioned_class(factory.version).name}.INSTANCE; |
| 93 | //:: #endif |
| 94 | //:: else: |
| 95 | throw new UnsupportedOperationException("${i.name} not supported in version ${factory.version}"); |
| 96 | //:: #endif |
| 97 | } |
| 98 | //:: #endif |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 99 | //:: #endfor |
| 100 | |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 101 | public OFMessageReader<${factory.base_class}> getReader() { |
| 102 | //:: if factory.versioned_base_class: |
| 103 | return ${factory.versioned_base_class.name}.READER; |
| 104 | //:: else: |
| 105 | throw new UnsupportedOperationException("Reader<${factory.base_class}> not supported in version ${factory.version}"); |
| 106 | //:: #endif |
Andreas Wundsam | 3ad9816 | 2013-08-15 11:08:56 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 109 | //:: if factory.interface.name == 'OFOxms': |
| 110 | @SuppressWarnings("unchecked") |
| 111 | public <F extends OFValueType<F>> OFOxm<F> fromValue(F value, MatchField<F> field) { |
| 112 | switch (field.id) { |
| 113 | //:: for oxm_name in model.oxm_map: |
| 114 | //:: type_name, value, masked = model.oxm_map[oxm_name] |
| 115 | //:: if masked: |
| 116 | //:: continue |
| 117 | //:: #endif |
| 118 | //:: method_name = oxm_name.replace('OFOxm', '') |
| 119 | //:: method_name = method_name[0].lower() + method_name[1:] |
| 120 | case ${value}: |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 121 | //:: # The cast to Object is done to avoid some javac bug that in some versions cannot handle cast from generic type to other types but Object |
| 122 | return (OFOxm<F>)((Object)${method_name}((${type_name})((Object)value))); |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 123 | //:: #endfor |
| 124 | default: |
| 125 | return null; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | @SuppressWarnings("unchecked") |
| 130 | public <F extends OFValueType<F>> OFOxm<F> fromValueAndMask(F value, F mask, MatchField<F> field) { |
| 131 | switch (field.id) { |
| 132 | //:: for oxm_name in model.oxm_map: |
| 133 | //:: type_name, value, masked = model.oxm_map[oxm_name] |
| 134 | //:: if not masked: |
| 135 | //:: continue |
| 136 | //:: #endif |
| 137 | //:: method_name = oxm_name.replace('OFOxm', '') |
| 138 | //:: method_name = method_name[0].lower() + method_name[1:] |
| 139 | case ${value}: |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 140 | //:: # The cast to Object is done to avoid some javac bug that in some versions cannot handle cast from generic type to other types but Object |
| 141 | return (OFOxm<F>)((Object)${method_name}((${type_name})((Object)value), (${type_name})((Object)mask))); |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 142 | //:: #endfor |
| 143 | default: |
| 144 | return null; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | @SuppressWarnings("unchecked") |
| 149 | public <F extends OFValueType<F>> OFOxm<F> fromMasked(Masked<F> masked, MatchField<F> field) { |
| 150 | switch (field.id) { |
| 151 | //:: for oxm_name in model.oxm_map: |
| 152 | //:: type_name, value, masked = model.oxm_map[oxm_name] |
| 153 | //:: if not masked: |
| 154 | //:: continue |
| 155 | //:: #endif |
| 156 | //:: method_name = oxm_name.replace('OFOxm', '') |
| 157 | //:: method_name = method_name[0].lower() + method_name[1:] |
| 158 | case ${value}: |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 159 | //:: # The cast to Object is done to avoid some javac bug that in some versions cannot handle cast from generic type to other types but Object |
| 160 | return (OFOxm<F>)((Object)${method_name}((${type_name})((Object)(masked.getValue())), (${type_name})((Object)(masked.getMask())))); |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 161 | //:: #endfor |
| 162 | default: |
| 163 | return null; |
| 164 | } |
| 165 | } |
| 166 | //:: #endif |
Andreas Wundsam | cb17b23 | 2013-09-28 19:05:36 -0700 | [diff] [blame] | 167 | //:: if factory.interface.xid_generator: |
| 168 | public long nextXid() { |
| 169 | return xidGenerator.nextXid(); |
| 170 | } |
| 171 | //:: #endif |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 172 | |
Andreas Wundsam | 47e077c | 2013-10-04 15:56:51 -0700 | [diff] [blame] | 173 | public OFVersion getVersion() { |
| 174 | return OFVersion.${factory.version.constant_version}; |
| 175 | } |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 176 | } |