File indexing completed on 2024-05-19 05:42:15
0001 import sys 0002 from hooks import HOOKS 0003 0004 0005 if __name__ == "__main__": 0006 # Note: Please don't use JINJA for code generation, since some users don't have it installed. 0007 output_path = sys.argv[1] 0008 filename = 'basicpluginhooks.h' 0009 fwd_declaration_types = list(set(hook.handler for hook in HOOKS)) 0010 0011 contents = [] 0012 contents.append("// This file is automatically generated. Do not modify it directly - Use the generator file instead.") 0013 contents.append('') 0014 contents.append('') 0015 0016 contents.append(f"// ct_lvtplg_{filename}.h -*-C++-*-") 0017 contents.append('') 0018 contents.append('// Copyright 2023 Codethink Ltd <codethink@codethink.co.uk>') 0019 contents.append('// SPDX-License-Identifier: Apache-2.0') 0020 contents.append('//') 0021 contents.append('// Licensed under the Apache License, Version 2.0 (the "License");') 0022 contents.append('// you may not use this file except in compliance with the License.') 0023 contents.append('// You may obtain a copy of the License at') 0024 contents.append('//') 0025 contents.append('// http://www.apache.org/licenses/LICENSE-2.0') 0026 contents.append('//') 0027 contents.append('// Unless required by applicable law or agreed to in writing, software') 0028 contents.append('// distributed under the License is distributed on an "AS IS" BASIS,') 0029 contents.append('// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.') 0030 contents.append('// See the License for the specific language governing permissions and') 0031 contents.append('// limitations under the License.') 0032 0033 contents.append("#ifndef DIAGRAM_SERVER_CT_LVTPLG_BASICPLUGINHOOKS_H") 0034 contents.append("#define DIAGRAM_SERVER_CT_LVTPLG_BASICPLUGINHOOKS_H") 0035 contents.append('') 0036 contents.append('#ifdef _WIN32') 0037 contents.append('#define _EXPORT_AS_C extern "C" __declspec(dllexport)') 0038 contents.append('#else') 0039 contents.append('#define _EXPORT_AS_C extern "C"') 0040 contents.append('#endif') 0041 contents.append('') 0042 0043 contents.append('// Forward declarations of data types') 0044 for fwd_decl_type in fwd_declaration_types: 0045 contents.append(f'struct {fwd_decl_type};') 0046 contents.append('') 0047 0048 contents.append('// Available plugin hooks') 0049 for hook_info in HOOKS: 0050 contents.append(f'// {hook_info.docs}') 0051 contents.append(f'typedef {hook_info.return_type} (*hook{hook_info.name}_f)({hook_info.handler} *);') 0052 contents.append(f'_EXPORT_AS_C {hook_info.return_type} hook{hook_info.name}({hook_info.handler} *);') 0053 contents.append('') 0054 contents.append('') 0055 0056 contents.append('#undef _EXPORT_AS_C') 0057 contents.append('') 0058 0059 contents.append("#endif") 0060 0061 plugin_hook_header = output_path + "/ct_lvtplg_" + filename 0062 with open(plugin_hook_header, 'w') as f: 0063 f.write('\n'.join(contents))