Mercurial > hg > orthanc-java
changeset 68:65c86e666eda
wrapping OrthancPluginGetKeyValue
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 20 Aug 2025 19:32:33 +0200 |
parents | 2e2363ba431b |
children | dcd69fbcc34b |
files | CodeGeneration/CodeModel.py CodeGeneration/CppNativeSDK.mustache CodeGeneration/CustomFunctions.json Plugin/Plugin.cpp |
diffstat | 4 files changed, 84 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/CodeGeneration/CodeModel.py Wed Aug 20 15:58:07 2025 +0200 +++ b/CodeGeneration/CodeModel.py Wed Aug 20 19:32:33 2025 +0200 @@ -213,6 +213,14 @@ 'java_signature' : 'Z', 'java_type' : 'boolean', } + elif f['return_sdk_type'] == "java_object": + result = { + 'c_type' : 'jobject', + 'default_value' : 'NULL', + 'is_java_object' : True, + 'java_type' : f['return_sdk_class'], + 'java_signature' : f['return_sdk_signature'], + } else: raise Exception('Unsupported return type: %s' % json.dumps(f, indent=4)) @@ -430,7 +438,8 @@ if (returnType.get('is_basic_type') == True or returnType.get('is_bytes') == True or returnType.get('is_dynamic_string') == True or - returnType.get('is_static_string') == True): + returnType.get('is_static_string') == True or + returnType.get('is_java_object') == True): result['java_return_start'] = 'return ' elif returnType.get('is_enumeration') == True:
--- a/CodeGeneration/CppNativeSDK.mustache Wed Aug 20 15:58:07 2025 +0200 +++ b/CodeGeneration/CppNativeSDK.mustache Wed Aug 20 19:32:33 2025 +0200 @@ -41,6 +41,12 @@ {{#return.is_basic_type}} extern {{return_sdk_type}} {{c_function}}(OrthancPluginContext* context{{#class_name}}, {{class_name}}* self{{/class_name}}{{#args}}, {{sdk_type}} {{name}}{{/args}}); {{/return.is_basic_type}} +{{#return.is_bytes}} +extern OrthancPluginErrorCode {{c_function}}(OrthancPluginContext* context, OrthancPluginMemoryBuffer* target{{#class_name}}, {{class_name}}* self{{/class_name}}{{#args}}, {{sdk_type}} {{name}}{{/args}}); +{{/return.is_bytes}} +{{#return.is_java_object}} +extern jobject {{c_function}}(JNIEnv* env, OrthancPluginContext* context{{#class_name}}, {{class_name}}* self{{/class_name}}{{#args}}, {{sdk_type}} {{name}}{{/args}}); +{{/return.is_java_object}} {{/is_custom}} {{/functions}} @@ -166,6 +172,12 @@ {{#class_name}}, reinterpret_cast<{{class_name}}*>(static_cast<intptr_t>(self)){{/class_name}} {{#args}}, {{c_accessor}}{{/args}}); {{/return.is_enumeration}} + +{{#return.is_java_object}} + return {{c_function}}(env, context_ + {{#class_name}}, reinterpret_cast<{{class_name}}*>(static_cast<intptr_t>(self)){{/class_name}} + {{#args}}, {{c_accessor}}{{/args}}); +{{/return.is_java_object}} } catch (std::runtime_error& e) {
--- a/CodeGeneration/CustomFunctions.json Wed Aug 20 15:58:07 2025 +0200 +++ b/CodeGeneration/CustomFunctions.json Wed Aug 20 19:32:33 2025 +0200 @@ -17,5 +17,32 @@ ], "return_sdk_type" : "uint64_t", "since_sdk" : [ 1, 12, 8 ] + }, + + { + "c_function" : "OrthancPluginCustom_GetKeyValue", + "sdk_functions" : [ "OrthancPluginGetKeyValue" ], + "documentation" : { + "description" : [ "Get the value associated with a key in the Orthanc key-value store." ], + "args" : { + "storeId" : "The key-value store.", + "key" : "The key." + }, + "return" : "The value as a byte array, or null." + }, + "args" : [ + { + "sdk_name" : "storeId", + "sdk_type" : "const char *" + }, + { + "sdk_name" : "key", + "sdk_type" : "const char *" + } + ], + "return_sdk_type" : "java_object", + "return_sdk_class" : "byte[]", + "return_sdk_signature" : "[B", + "since_sdk" : [ 1, 12, 8 ] } ]
--- a/Plugin/Plugin.cpp Wed Aug 20 15:58:07 2025 +0200 +++ b/Plugin/Plugin.cpp Wed Aug 20 19:32:33 2025 +0200 @@ -436,7 +436,8 @@ #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 8) -uint64_t OrthancPluginCustom_GetQueueSize(OrthancPluginContext* context, const char *queueId) +uint64_t OrthancPluginCustom_GetQueueSize(OrthancPluginContext* context, + const char *queueId) { uint64_t size = 0; OrthancPluginErrorCode code = OrthancPluginGetQueueSize(context, queueId, &size); @@ -454,7 +455,39 @@ #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 8) -bool OrthancPluginCustom_KeysValuesIteratorNext(OrthancPluginContext* context, OrthancPluginKeysValuesIterator* self) +jobject OrthancPluginCustom_GetKeyValue(JNIEnv* env, + OrthancPluginContext* context, + const char * storeId, + const char * key) +{ + OrthancBytes value; + uint8_t found = false; + OrthancPluginErrorCode code = OrthancPluginGetKeyValue(context, &found, value.GetMemoryBuffer(), storeId, key); + + if (code == OrthancPluginErrorCode_Success) + { + if (found) + { + JavaEnvironment java(env); + return java.ConstructByteArray(value.GetSize(), value.GetData()); + } + else + { + // The C "NULL" value results in the Java "null" value + return NULL; + } + } + else + { + throw std::runtime_error(JavaEnvironment::GetRuntimeErrorMessage(context, code)); + } +} +#endif + + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 8) +bool OrthancPluginCustom_KeysValuesIteratorNext(OrthancPluginContext* context, + OrthancPluginKeysValuesIterator* self) { uint8_t done = true; OrthancPluginErrorCode code = OrthancPluginKeysValuesIteratorNext(context, &done, self);