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 |
| 30 | //:: include('_copyright.java') |
| 31 | |
| 32 | //:: include('_autogen.java') |
| 33 | |
| 34 | package ${factory.package}; |
| 35 | |
| 36 | //:: include("_imports.java") |
| 37 | |
| 38 | public class ${factory.name} implements ${factory.interface.name} { |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 39 | public final static ${factory.name} INSTANCE = new ${factory.name}(); |
| 40 | private ${factory.name}() {} |
| 41 | |
| 42 | //:: for name, clazz in factory.interface.sub_factories.items(): |
| 43 | public ${clazz} ${name}() { |
| 44 | return ${clazz}Ver${factory.version.of_version}.INSTANCE; |
| 45 | } |
| 46 | //:: #endfor |
| 47 | |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 48 | //:: for i in factory.interface.members: |
| 49 | //:: if i.is_virtual: |
| 50 | //:: continue |
| 51 | //:: #endif |
| 52 | |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 53 | //:: if len(i.writeable_members) > 0: |
| 54 | public ${i.name}.Builder ${factory.interface.method_name(i, builder=True)}() { |
| 55 | //:: 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] | 56 | return new ${i.versioned_class(factory.version).name}.Builder(); |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 57 | //:: else: |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 58 | throw new UnsupportedOperationException("${i.name} not supported in version ${factory.version}"); |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 59 | //:: #endif |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 60 | } |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 61 | //:: #endif |
| 62 | //:: if len(i.writeable_members) <= 2: |
| 63 | 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)}) { |
| 64 | //:: if i.has_version(factory.version) and model.generate_class(i.versioned_class(factory.version)): |
| 65 | //:: if len(i.writeable_members) > 0: |
| 66 | return new ${i.versioned_class(factory.version).name}( |
| 67 | ${",\n ".join( |
| 68 | [ prop.name for prop in i.versioned_class(factory.version).data_members])} |
| 69 | ); |
| 70 | //:: else: |
| 71 | return ${i.versioned_class(factory.version).name}.INSTANCE; |
| 72 | //:: #endif |
| 73 | //:: else: |
| 74 | throw new UnsupportedOperationException("${i.name} not supported in version ${factory.version}"); |
| 75 | //:: #endif |
| 76 | } |
| 77 | //:: #endif |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 78 | //:: #endfor |
| 79 | |
Andreas Wundsam | e0d52be | 2013-08-22 07:52:13 -0700 | [diff] [blame] | 80 | public OFMessageReader<${factory.base_class}> getReader() { |
| 81 | //:: if factory.versioned_base_class: |
| 82 | return ${factory.versioned_base_class.name}.READER; |
| 83 | //:: else: |
| 84 | throw new UnsupportedOperationException("Reader<${factory.base_class}> not supported in version ${factory.version}"); |
| 85 | //:: #endif |
Andreas Wundsam | 3ad9816 | 2013-08-15 11:08:56 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 88 | //:: if factory.interface.name == 'OFOxms': |
| 89 | @SuppressWarnings("unchecked") |
| 90 | public <F extends OFValueType<F>> OFOxm<F> fromValue(F value, MatchField<F> field) { |
| 91 | switch (field.id) { |
| 92 | //:: for oxm_name in model.oxm_map: |
| 93 | //:: type_name, value, masked = model.oxm_map[oxm_name] |
| 94 | //:: if masked: |
| 95 | //:: continue |
| 96 | //:: #endif |
| 97 | //:: method_name = oxm_name.replace('OFOxm', '') |
| 98 | //:: method_name = method_name[0].lower() + method_name[1:] |
| 99 | case ${value}: |
| 100 | return (OFOxm<F>)${method_name}((${type_name})value); |
| 101 | //:: #endfor |
| 102 | default: |
| 103 | return null; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | @SuppressWarnings("unchecked") |
| 108 | public <F extends OFValueType<F>> OFOxm<F> fromValueAndMask(F value, F mask, MatchField<F> field) { |
| 109 | switch (field.id) { |
| 110 | //:: for oxm_name in model.oxm_map: |
| 111 | //:: type_name, value, masked = model.oxm_map[oxm_name] |
| 112 | //:: if not masked: |
| 113 | //:: continue |
| 114 | //:: #endif |
| 115 | //:: method_name = oxm_name.replace('OFOxm', '') |
| 116 | //:: method_name = method_name[0].lower() + method_name[1:] |
| 117 | case ${value}: |
| 118 | return (OFOxm<F>)${method_name}((${type_name})value, (${type_name})mask); |
| 119 | //:: #endfor |
| 120 | default: |
| 121 | return null; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | @SuppressWarnings("unchecked") |
| 126 | public <F extends OFValueType<F>> OFOxm<F> fromMasked(Masked<F> masked, MatchField<F> field) { |
| 127 | switch (field.id) { |
| 128 | //:: for oxm_name in model.oxm_map: |
| 129 | //:: type_name, value, masked = model.oxm_map[oxm_name] |
| 130 | //:: if not masked: |
| 131 | //:: continue |
| 132 | //:: #endif |
| 133 | //:: method_name = oxm_name.replace('OFOxm', '') |
| 134 | //:: method_name = method_name[0].lower() + method_name[1:] |
| 135 | case ${value}: |
| 136 | return (OFOxm<F>)${method_name}((${type_name})(masked.getValue()), (${type_name})(masked.getMask())); |
| 137 | //:: #endfor |
| 138 | default: |
| 139 | return null; |
| 140 | } |
| 141 | } |
| 142 | //:: #endif |
| 143 | |
Andreas Wundsam | 5204de2 | 2013-07-30 11:34:45 -0700 | [diff] [blame] | 144 | } |