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}(); |
| 43 | private ${factory.name}() {} |
| 44 | |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame^] | 45 | public OFVersion getOFVersion() { |
| 46 | return OFVersion.OF_${factory.version.of_version}; |
| 47 | } |
| 48 | |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 49 | //:: for name, clazz in factory.interface.sub_factories.items(): |
| 50 | public ${clazz} ${name}() { |
| 51 | return ${clazz}Ver${factory.version.of_version}.INSTANCE; |
| 52 | } |
| 53 | //:: #endfor |
| 54 | |
Yotam Harchol | a86e425 | 2013-09-06 15:36:28 -0700 | [diff] [blame] | 55 | //:: general_get_match_func_written = False |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 56 | //:: for i in factory.interface.members: |
| 57 | //:: if i.is_virtual: |
| 58 | //:: continue |
| 59 | //:: #endif |
Yotam Harchol | a86e425 | 2013-09-06 15:36:28 -0700 | [diff] [blame] | 60 | //:: 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' |
| 61 | //:: 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] | 62 | |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 63 | //:: if len(i.writeable_members) > 0: |
| 64 | public ${i.name}.Builder ${factory.interface.method_name(i, builder=True)}() { |
| 65 | //:: if i.has_version(factory.version) and model.generate_class(i.versioned_class(factory.version)): |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 66 | return new ${i.versioned_class(factory.version).name}.Builder(); |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 67 | //:: else: |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 68 | throw new UnsupportedOperationException("${i.name} not supported in version ${factory.version}"); |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 69 | //:: #endif |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 70 | } |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 71 | //:: #endif |
Yotam Harchol | a86e425 | 2013-09-06 15:36:28 -0700 | [diff] [blame] | 72 | //:: if not general_get_match_func_written and is_match_object and not unsupported_match_object: |
| 73 | public Match.Builder buildMatch() { |
| 74 | return new ${i.versioned_class(factory.version).name}.Builder(); |
| 75 | } |
| 76 | //:: general_get_match_func_written = True |
| 77 | //:: #endif |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 78 | //:: if len(i.writeable_members) <= 2: |
| 79 | 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)}) { |
| 80 | //:: if i.has_version(factory.version) and model.generate_class(i.versioned_class(factory.version)): |
| 81 | //:: if len(i.writeable_members) > 0: |
| 82 | return new ${i.versioned_class(factory.version).name}( |
| 83 | ${",\n ".join( |
| 84 | [ prop.name for prop in i.versioned_class(factory.version).data_members])} |
| 85 | ); |
| 86 | //:: else: |
| 87 | return ${i.versioned_class(factory.version).name}.INSTANCE; |
| 88 | //:: #endif |
| 89 | //:: else: |
| 90 | throw new UnsupportedOperationException("${i.name} not supported in version ${factory.version}"); |
| 91 | //:: #endif |
| 92 | } |
| 93 | //:: #endif |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 94 | //:: #endfor |
| 95 | |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 96 | public OFMessageReader<${factory.base_class}> getReader() { |
| 97 | //:: if factory.versioned_base_class: |
| 98 | return ${factory.versioned_base_class.name}.READER; |
| 99 | //:: else: |
| 100 | throw new UnsupportedOperationException("Reader<${factory.base_class}> not supported in version ${factory.version}"); |
| 101 | //:: #endif |
Andreas Wundsam | 3ad9816 | 2013-08-15 11:08:56 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 104 | //:: if factory.interface.name == 'OFOxms': |
| 105 | @SuppressWarnings("unchecked") |
| 106 | public <F extends OFValueType<F>> OFOxm<F> fromValue(F value, MatchField<F> field) { |
| 107 | switch (field.id) { |
| 108 | //:: for oxm_name in model.oxm_map: |
| 109 | //:: type_name, value, masked = model.oxm_map[oxm_name] |
| 110 | //:: if masked: |
| 111 | //:: continue |
| 112 | //:: #endif |
| 113 | //:: method_name = oxm_name.replace('OFOxm', '') |
| 114 | //:: method_name = method_name[0].lower() + method_name[1:] |
| 115 | case ${value}: |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 116 | //:: # 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 |
| 117 | return (OFOxm<F>)((Object)${method_name}((${type_name})((Object)value))); |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 118 | //:: #endfor |
| 119 | default: |
| 120 | return null; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | @SuppressWarnings("unchecked") |
| 125 | public <F extends OFValueType<F>> OFOxm<F> fromValueAndMask(F value, F mask, MatchField<F> field) { |
| 126 | switch (field.id) { |
| 127 | //:: for oxm_name in model.oxm_map: |
| 128 | //:: type_name, value, masked = model.oxm_map[oxm_name] |
| 129 | //:: if not masked: |
| 130 | //:: continue |
| 131 | //:: #endif |
| 132 | //:: method_name = oxm_name.replace('OFOxm', '') |
| 133 | //:: method_name = method_name[0].lower() + method_name[1:] |
| 134 | case ${value}: |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 135 | //:: # 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 |
| 136 | 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] | 137 | //:: #endfor |
| 138 | default: |
| 139 | return null; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | @SuppressWarnings("unchecked") |
| 144 | public <F extends OFValueType<F>> OFOxm<F> fromMasked(Masked<F> masked, MatchField<F> field) { |
| 145 | switch (field.id) { |
| 146 | //:: for oxm_name in model.oxm_map: |
| 147 | //:: type_name, value, masked = model.oxm_map[oxm_name] |
| 148 | //:: if not masked: |
| 149 | //:: continue |
| 150 | //:: #endif |
| 151 | //:: method_name = oxm_name.replace('OFOxm', '') |
| 152 | //:: method_name = method_name[0].lower() + method_name[1:] |
| 153 | case ${value}: |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 154 | //:: # 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 |
| 155 | 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] | 156 | //:: #endfor |
| 157 | default: |
| 158 | return null; |
| 159 | } |
| 160 | } |
| 161 | //:: #endif |
| 162 | |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 163 | } |