1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# Copyright (c) 2024 Huawei Device Co., Ltd. 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17from __future__ import absolute_import 18 19import os 20import file_parser 21import make_file_base 22 23# pylint:disable=huawei-redefined-outer-name 24 25# ------------------------------------------------------------------------------------------------------# 26 27def make_cpptoc_header_file(header, dir_path, dir_name, class_name): 28 cls = header.get_class(class_name) 29 if cls is None: 30 raise Exception('Class does not exist: ' + class_name) 31 32 content = make_file_base.get_copyright() 33 content += '\n' 34 35 content += \ 36""" 37#ifndef $GUARD$ 38#define $GUARD$ 39#pragma once 40""" 41 content += '\n' 42 43 result = make_file_base.make_include_file(cls, 'CppToC', header, dir_name, class_name) 44 content += result['content'] 45 content += '\n' 46 47 content += 'namespace OHOS::ArkWeb {\n\n' 48 49 content += '// Wrap a C++ class with a C structure.\n' 50 content += '// This class may be instantiated and accessed DLL-side only.\n' 51 content += make_file_base.make_class_define(cls, 'CppToC', result['base_name'], class_name, '') 52 content += '\n' 53 54 content += '} // OHOS::ArkWeb\n\n' 55 56 content += \ 57""" 58#endif // $GUARD$ 59""" 60 61 # add the guard string 62 def_name = make_file_base.make_def_file(cls, class_name) 63 guard = def_name.upper() + '_CPPTOC_H_' 64 content = content.replace('$GUARD$', guard) 65 66 absolute_dir = os.path.join(os.path.join(dir_path, dir_name), 'cpptoc') 67 absolute_path = os.path.join(absolute_dir, file_parser.get_capi_name(class_name, False) + '_cpptoc.h') 68 69 return (content, absolute_path) 70