Mercurial > hg > orthanc-python
diff CodeAnalysis/ParseOrthancSDK.py @ 63:32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 10 Jun 2021 18:19:27 +0200 |
parents | 23f3099bed47 |
children | 091fb1903bfc |
line wrap: on
line diff
--- a/CodeAnalysis/ParseOrthancSDK.py Fri May 28 10:53:18 2021 +0200 +++ b/CodeAnalysis/ParseOrthancSDK.py Thu Jun 10 18:19:27 2021 +0200 @@ -31,6 +31,42 @@ ## +## Configuration of the custom primitives that are manually +## implemented (not autogenerated) +## + +CUSTOM_FUNCTIONS = { + 'OrthancPluginCreateDicom', + 'OrthancPluginFreeMemoryBuffer', + 'OrthancPluginFreeString', + 'OrthancPluginGetFindQueryTag', + 'OrthancPluginRegisterFindCallback', + 'OrthancPluginRegisterIncomingHttpRequestFilter', # Implemented through v2 + 'OrthancPluginRegisterIncomingHttpRequestFilter2', + 'OrthancPluginRegisterMoveCallback', + 'OrthancPluginRegisterOnChangeCallback', + 'OrthancPluginRegisterOnStoredInstanceCallback', + 'OrthancPluginRegisterRestCallback', # Implemented using OrthancPlugins::RegisterRestCallback + 'OrthancPluginRegisterRestCallbackNoLock', # Implemented using OrthancPlugins::RegisterRestCallback +} + +CUSTOM_METHODS = [ + { + 'class_name' : 'OrthancPluginFindQuery', + 'method_name' : 'GetFindQueryTagGroup', + 'implementation' : 'GetFindQueryTagGroup', + 'sdk_function' : 'OrthancPluginGetFindQueryTag', + }, + { + 'class_name' : 'OrthancPluginFindQuery', + 'method_name' : 'GetFindQueryTagElement', + 'implementation' : 'GetFindQueryTagElement', + 'sdk_function' : 'OrthancPluginGetFindQueryTag', + }, +] + + +## ## Parse the command-line arguments ## @@ -40,7 +76,7 @@ help = 'manually provides the path to the libclang shared library') parser.add_argument('--source', default = os.path.join(os.path.dirname(__file__), - '../Resources/Orthanc/Sdk-1.5.7/orthanc/OrthancCPlugin.h'), + '../Resources/Orthanc/Sdk-1.8.1/orthanc/OrthancCPlugin.h'), help = 'Input C++ file') parser.add_argument('--target', default = os.path.join(os.path.dirname(__file__), @@ -383,11 +419,13 @@ CheckOnlySupportedArguments(args[1:])): className = args[0].type.get_pointee().spelling + print('Simple method of class %s: %s' % (className, node.spelling)) + if node.spelling in CUSTOM_FUNCTIONS: + raise Exception('Cannot overwrite an autogenerated method: %s()' % node.spelling) + if className.startswith('const '): className = className[len('const '):] - print('Simple method of class %s: %s' % (className, node.spelling)) - method = GenerateFunctionBodyTemplate(node.spelling, node.result_type, args[1:]) method['self'] = ', self->object_' classes[className]['methods'].append(method) @@ -397,12 +435,12 @@ IsTargetMemoryBufferType(args[0].type) and IsClassType(args[1].type) and CheckOnlySupportedArguments(args[2:])): - print('Simple method of class %s, returning bytes: %s' % ( - args[1].type.get_pointee().spelling, - node.spelling)) - className = args[1].type.get_pointee().spelling + print('Simple method of class %s, returning bytes: %s' % (className, node.spelling)) + if node.spelling in CUSTOM_FUNCTIONS: + raise Exception('Cannot overwrite an autogenerated method: %s()' % node.spelling) + if className.startswith('const '): className = className[len('const '):] @@ -410,6 +448,10 @@ method['self'] = ', self->object_' classes[className]['methods'].append(method) countSupportedFunctions += 1 + + elif node.spelling in CUSTOM_FUNCTIONS: + print('Ignoring custom function that is manually implemented: %s()' % node.spelling) + countSupportedFunctions += 1 else: print('*** UNSUPPORTED INPUT: %s' % node.spelling) @@ -424,7 +466,8 @@ classes[name] = { 'class_name' : name, 'short_name' : name[len('OrthancPlugin'):], - 'methods' : [ ] + 'methods' : [ ], + 'custom_methods' : [ ], } @@ -443,6 +486,9 @@ with open(os.path.join(ROOT, 'Class.mustache'), 'r') as f: template = f.read() + for method in CUSTOM_METHODS: + classes[method['class_name']]['custom_methods'].append(method) + for (key, value) in classes.items(): with open(os.path.join(TARGET, 'sdk_%s.impl.h' % value['class_name']), 'w') as h: h.write(renderer.render(template, value))