Skip to content

Commit

Permalink
infrastructure for "preloading" TREs (#593)
Browse files Browse the repository at this point in the history
* merge develop/preload-TREs

* fix build errors

* #including some TREs

* "export" TRE routines as "static"

* struct for pre-loaded TREs rather than "void*"

* start working on resolving preloaded TREs

* retrievePreloadedTREHandler() to match nitf_PluginRegistry_retrieveTREHandler()

* preload a TRE

* preload several TREs

* fix duplicate defs

* fix compiler warning

* use macros to remove multiple-defined symbols

* keep a few TREs as plugins for testing

* preloaded TRE stuff needs to be in PluginHandler so that nitf_PluginRegistry_retrieveTREHandler() "just works"

* remove another multiple-defined symbols

* assume plug-in that fails is "preloaded"

* remove VCXPROJ for TREs that are preloaded

* don't preload ANY TREs to preserve existing behavior

* be sure all nrt_DLL fields are initialized

* revert whitespace changes
  • Loading branch information
J. Daniel Smith authored Nov 13, 2023
1 parent 0342b59 commit 205bf8e
Show file tree
Hide file tree
Showing 31 changed files with 329 additions and 130 deletions.
30 changes: 0 additions & 30 deletions UnitTest/UnitTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -258,39 +258,9 @@
<ProjectReference Include="..\modules\c\nitf-c.vcxproj">
<Project>{f06550ad-cfc7-40b8-8727-6c82c69a8982}</Project>
</ProjectReference>
<ProjectReference Include="..\modules\c\nitf\ACCHZB.vcxproj">
<Project>{53f9f908-c678-4dee-9309-e71c1d03a45f}</Project>
</ProjectReference>
<ProjectReference Include="..\modules\c\nitf\ACCPOB.vcxproj">
<Project>{730b1e6e-2469-4f9e-b093-d0c6262453c9}</Project>
</ProjectReference>
<ProjectReference Include="..\modules\c\nitf\ACFTA.vcxproj">
<Project>{51d7b426-899e-428d-9f69-5ddac9e403fb}</Project>
</ProjectReference>
<ProjectReference Include="..\modules\c\nitf\AIMIDB.vcxproj">
<Project>{12aa0752-4ee3-4e0a-85af-0e5deadbf343}</Project>
</ProjectReference>
<ProjectReference Include="..\modules\c\nitf\CSCRNA.vcxproj">
<Project>{023de06d-3967-4406-b1b8-032118bb2552}</Project>
</ProjectReference>
<ProjectReference Include="..\modules\c\nitf\CSEXRB.vcxproj">
<Project>{0a9bda26-092f-4a2c-bbef-00c64bf0c65e}</Project>
</ProjectReference>
<ProjectReference Include="..\modules\c\nitf\ENGRDA.vcxproj">
<Project>{53f9f908-c678-4dee-9309-e71c1e03a45f}</Project>
</ProjectReference>
<ProjectReference Include="..\modules\c\nitf\HISTOA.vcxproj">
<Project>{d749aa73-4c9a-473d-96bb-070a6d9caa54}</Project>
</ProjectReference>
<ProjectReference Include="..\modules\c\nitf\JITCID.vcxproj">
<Project>{d1d7fcd3-6130-4504-9da0-9d80506be55e}</Project>
</ProjectReference>
<ProjectReference Include="..\modules\c\nitf\PTPRAA.vcxproj">
<Project>{2baaaca9-a5a4-412c-ae52-b16c2d107f55}</Project>
</ProjectReference>
<ProjectReference Include="..\modules\c\nitf\RPFHDR.vcxproj">
<Project>{cf5b4f02-364d-4117-9fb9-6c9c7938e412}</Project>
</ProjectReference>
<ProjectReference Include="..\modules\c\nitf\XML_DATA_CONTENT.vcxproj">
<Project>{78849481-d356-4cc7-b182-31c21f857ed1}</Project>
</ProjectReference>
Expand Down
7 changes: 4 additions & 3 deletions modules/c++/nitf/unittests/test_load_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TEST_CASE(test_load_all_TREs)

for (const auto& tre : all_TREs())
{
// TREs are quite the same thing as an arbitrary "plug in;" the underlying
// TREs aren't quite the same thing as an arbitrary "plug in;" the underlying
// infrastructure is all built on shared-libraries/DLLs, but details differ.
//
// As a result, we can't expect loadPlugin() will "just work" on a TRE name.
Expand All @@ -103,9 +103,10 @@ TEST_CASE(test_load_all_TREs)
{
nitf::PluginRegistry::loadPlugin(tre);
}
catch (const nitf::NITFException& ex)
catch (const nitf::NITFException&)
{
TEST_FAIL_MSG(ex.toString());
// assume this is a pre-loaded plugin
retrieveTREHandler(testName, tre.c_str());
}
#endif // _WIN32

Expand Down
9 changes: 9 additions & 0 deletions modules/c/nitf-c.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@
<ClCompile Include="j2k\source\SimpleComponentImpl.c" />
<ClCompile Include="j2k\source\SimpleContainerImpl.c" />
<ClCompile Include="jpeg\source\LibjpegDecompress.c" />
<ClCompile Include="nitf\shared\ACCHZB.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="nitf\shared\HISTOA.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="nitf\source\BandInfo.c" />
<ClCompile Include="nitf\source\BandSource.c" />
<ClCompile Include="nitf\source\ComplexityLevel.c" />
Expand Down Expand Up @@ -303,6 +311,7 @@
<ClCompile Include="nitf\source\TRE.c" />
<ClCompile Include="nitf\source\TRECursor.c" />
<ClCompile Include="nitf\source\TREPrivateData.c" />
<ClCompile Include="nitf\source\TREs.c" />
<ClCompile Include="nitf\source\TREUtils.c" />
<ClCompile Include="nitf\source\WriteHandler.c" />
<ClCompile Include="nrt\source\DateTime.c" />
Expand Down
12 changes: 12 additions & 0 deletions modules/c/nitf-c.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<Filter Include="nrt">
<UniqueIdentifier>{2e28e7c0-ed75-4c97-84b1-cb70b635b60e}</UniqueIdentifier>
</Filter>
<Filter Include="nitf\shared">
<UniqueIdentifier>{e0402428-7ec8-4079-8b39-48d8db79bf50}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="cgm\include\cgm\BasicTypes.h">
Expand Down Expand Up @@ -673,5 +676,14 @@
<ClCompile Include="j2k\source\TileWriter.c">
<Filter>j2k</Filter>
</ClCompile>
<ClCompile Include="nitf\shared\HISTOA.c">
<Filter>nitf\shared</Filter>
</ClCompile>
<ClCompile Include="nitf\source\TREs.c">
<Filter>nitf</Filter>
</ClCompile>
<ClCompile Include="nitf\shared\ACCHZB.c">
<Filter>nitf\shared</Filter>
</ClCompile>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions modules/c/nitf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ coda_add_module(
source/StreamIOWriteHandler.c
source/SubWindow.c
source/TRE.c
source/TREs.c
source/TRECursor.c
source/TREPrivateData.c
source/TREUtils.c
Expand Down
21 changes: 12 additions & 9 deletions modules/c/nitf/include/nitf/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@
*
* _Tre the name of the input TRE
*/
#ifndef NITF_PLUGIN_FUNCTION_EXPORT
#define NITF_PLUGIN_FUNCTION_EXPORT(retval_) NITFAPI(retval_)
#endif
#define NITF_DECLARE_PLUGIN(_Tre) \
static const char *ident[] = { \
static const char* _Tre##Ident[] = { \
NITF_PLUGIN_TRE_KEY, \
#_Tre, \
NULL \
}; \
static nitf_TREHandler _Tre##Handler; \
NITFAPI(const char**) _Tre##_init(nitf_Error* error){ \
if (!nitf_TREUtils_createBasicHandler(&descriptionSet,\
&_Tre##Handler,error)) \
return NULL; return ident; \
} \
NITFAPI(nitf_TREHandler*) _Tre##_handler(nitf_Error* error) { \
NITF_PLUGIN_FUNCTION_EXPORT(const char**) _Tre##_init(nitf_Error* error){ \
if (!nitf_TREUtils_createBasicHandler(&_Tre##DescriptionSet, &_Tre##Handler,error)) return NULL; \
return _Tre##Ident; } \
NITF_PLUGIN_FUNCTION_EXPORT(nitf_TREHandler*) _Tre##_handler(nitf_Error* error) { \
(void)error; \
return &_Tre##Handler; \
}
Expand All @@ -55,13 +56,15 @@
* _Description the description to use
*/
#define NITF_DECLARE_SINGLE_PLUGIN(_Tre, _Description) \
static nitf_TREDescriptionInfo descriptions[] = { \
static nitf_TREDescriptionInfo _Tre##Descriptions[] = { \
{ #_Tre, _Description, NITF_TRE_DESC_NO_LENGTH }, \
{ NULL, NULL, NITF_TRE_DESC_NO_LENGTH } \
}; \
static nitf_TREDescriptionSet descriptionSet = { 0, descriptions }; \
static nitf_TREDescriptionSet _Tre##DescriptionSet = { 0, _Tre##Descriptions }; \
NITF_DECLARE_PLUGIN(_Tre)

#define NITF_DECLARE_SINGLE_PLUGIN_SIMPLE(_Tre) \
NITF_DECLARE_SINGLE_PLUGIN(_Tre, _Tre##_description)
/**
* Reference a TRE that has been statically compiled inside of a library
*
Expand Down
7 changes: 7 additions & 0 deletions modules/c/nitf/include/nitf/PluginIdentifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ typedef int (*NITF_PLUGIN_TRE_HANDLER_FUNCTION)

typedef nitf_TREHandler* (*NITF_PLUGIN_TRE_HANDLER_FUNCTION)(nitf_Error * error);

// These are TREs which are linked into NITF rather than loaded at run-time.
typedef struct _nitf_TREPreloaded
{
const char* name;
NITF_PLUGIN_INIT_FUNCTION init;
NITF_PLUGIN_TRE_HANDLER_FUNCTION handler;
} nitf_TREPreloaded;

/*
\brief NITF_PLUGIN_COMPRESSION_HANDLER_FUNCTION - Function pointer for
Expand Down
2 changes: 2 additions & 0 deletions modules/c/nitf/include/nitf/PluginRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ NITFAPI(NITF_BOOL)
nitf_PluginRegistry_loadDir(const char* dirName, nitf_Error * error);


NITFAPI(NITF_BOOL)
nitf_PluginRegistry_insertPlugin_(const char* msg, nitf_PluginRegistry* reg, const char** ident, nitf_DLL* dll, nitf_Error* error);
NITFAPI(NITF_BOOL)
nitf_PluginRegistry_loadPlugin(const char* fullPathName, nitf_Error* error);

Expand Down
4 changes: 2 additions & 2 deletions modules/c/nitf/shared/ACCHZB.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

NITF_CXX_GUARD

static nitf_TREDescription description[] = {
static nitf_TREDescription ACCHZB_description[] = {
{NITF_BCS_N, 2, "Number of horizontal accuracy regions", "NUMACHZ", },
{NITF_LOOP, 0, NULL, "NUMACHZ"},
{NITF_BCS_A, 3, "Unit of Measure for AAH", "UNIAAH" },
Expand All @@ -44,6 +44,6 @@ static nitf_TREDescription description[] = {
{NITF_END, 0, NULL, NULL}
};

NITF_DECLARE_SINGLE_PLUGIN(ACCHZB, description)
NITF_DECLARE_SINGLE_PLUGIN_SIMPLE(ACCHZB)

NITF_CXX_ENDGUARD
4 changes: 2 additions & 2 deletions modules/c/nitf/shared/ACFTA.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ static nitf_TREDescription descrip_00199[] = {
};

/* Define the available descriptions and the default one */
static nitf_TREDescriptionInfo descriptions[] = {
static nitf_TREDescriptionInfo ACFTADescriptions[] = {
{ "ACFTA_132", descrip_00132, 132 },
{ "ACFTA_154", descrip_00154, 154 },
{ "ACFTA_199", descrip_00199, 199 },
{ NULL, NULL, NITF_TRE_DESC_NO_LENGTH }
};
static nitf_TREDescriptionSet descriptionSet = { 0, descriptions };
static nitf_TREDescriptionSet ACFTADescriptionSet = { 0, ACFTADescriptions };


#if 1
Expand Down
2 changes: 1 addition & 1 deletion modules/c/nitf/shared/AIMIDA.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static nitf_TREDescriptionInfo descriptions[] = {
{ "AIMIDA_89", descrip_00089, 89 },
{ NULL, NULL, NITF_TRE_DESC_NO_LENGTH }
};
static nitf_TREDescriptionSet descriptionSet = { 0, descriptions };
static nitf_TREDescriptionSet AIMIDADescriptionSet = { 0, descriptions };

NITF_DECLARE_PLUGIN(AIMIDA)

Expand Down
4 changes: 2 additions & 2 deletions modules/c/nitf/shared/AIMIDB.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

NITF_CXX_GUARD

static nitf_TREDescription description[] = {
static nitf_TREDescription AIMIDB_description[] = {
{NITF_BCS_A, 14, "Acquisition Date/Time", "ACQUISITION_DATE" },
{NITF_BCS_A, 4, "Mission Number", "MISSION_NO" },
{NITF_BCS_A, 10, "Mission ID (ATO)", "MISSION_IDENTIFICATION" },
Expand All @@ -52,6 +52,6 @@ static nitf_TREDescription description[] = {
{NITF_END, 0, NULL, NULL}
};

NITF_DECLARE_SINGLE_PLUGIN(AIMIDB, description)
NITF_DECLARE_SINGLE_PLUGIN_SIMPLE(AIMIDB)

NITF_CXX_ENDGUARD
4 changes: 2 additions & 2 deletions modules/c/nitf/shared/CSCRNA.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

NITF_CXX_GUARD

static nitf_TREDescription description[] = {
static nitf_TREDescription CSCRNA_description[] = {
{NITF_BCS_A, 1, "predicted corners flag", "PREDICT_CORNERS" },
{NITF_BCS_N, 9, "lat UL", "ULCNR_LAT" },
{NITF_BCS_N, 10, "long UL", "ULCNR_LONG" },
Expand All @@ -47,6 +47,6 @@ static nitf_TREDescription description[] = {
{NITF_END, 0, NULL, NULL}
};

NITF_DECLARE_SINGLE_PLUGIN(CSCRNA, description)
NITF_DECLARE_SINGLE_PLUGIN_SIMPLE(CSCRNA)

NITF_CXX_ENDGUARD
4 changes: 2 additions & 2 deletions modules/c/nitf/shared/CSEXRB.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

NITF_CXX_GUARD

static nitf_TREDescription description[] = {
static nitf_TREDescription CSEXRB_description[] = {
{NITF_BCS_A, 36, "UUID Assigned to the Current Image Plane", "IMAGE_UUID"},
{NITF_BCS_N, 3, "Number of GLAS/GFM DES Associated with this Image", "NUM_ASSOC_DES"},
{NITF_IF, 0, "> 0", "NUM_ASSOC_DES"},
Expand Down Expand Up @@ -144,6 +144,6 @@ static nitf_TREDescription description[] = {
{NITF_END, 0, NULL, NULL}
};

NITF_DECLARE_SINGLE_PLUGIN(CSEXRB, description)
NITF_DECLARE_SINGLE_PLUGIN_SIMPLE(CSEXRB)

NITF_CXX_ENDGUARD
14 changes: 7 additions & 7 deletions modules/c/nitf/shared/ENGRDA.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

NITF_CXX_GUARD

static nitf_TREDescription description[] = {
static nitf_TREDescription ENGRDA_description[] = {
{NITF_BCS_A, 20, "Unique Source System Name", "RESRC" },
{NITF_BCS_N, 3, "Record Entry Count", "RECNT" },
{NITF_LOOP, 0, NULL, "RECNT"},
Expand All @@ -57,12 +57,12 @@ static nitf_TREDescription description[] = {
{NITF_END, 0, NULL, NULL}
};

static nitf_TREDescriptionInfo descriptions[] = {
{ "ENGRDA", description, NITF_TRE_DESC_NO_LENGTH },
static nitf_TREDescriptionInfo ENGRDA_descriptions[] = {
{ "ENGRDA", ENGRDA_description, NITF_TRE_DESC_NO_LENGTH },
{ NULL, NULL, NITF_TRE_DESC_NO_LENGTH }
};

static nitf_TREDescriptionSet descriptionSet = { 0, descriptions };
static nitf_TREDescriptionSet ENGRDA_descriptionSet = { 0, ENGRDA_descriptions };

static const char *ident[] = { NITF_PLUGIN_TRE_KEY, "ENGRDA", NULL };

Expand Down Expand Up @@ -294,9 +294,9 @@ NITFPRIV(NITF_BOOL) ENGRDA_read(nitf_IOInterface* io,
return ok;
}

NITFAPI(const char**) ENGRDA_init(nitf_Error* error)
NITF_PLUGIN_FUNCTION_EXPORT(const char**) ENGRDA_init(nitf_Error* error)
{
if (!nitf_TREUtils_createBasicHandler(&descriptionSet,
if (!nitf_TREUtils_createBasicHandler(&ENGRDA_descriptionSet,
&engrdaHandler,
error))
{
Expand All @@ -310,7 +310,7 @@ NITFAPI(const char**) ENGRDA_init(nitf_Error* error)
return ident;
}

NITFAPI(nitf_TREHandler*) ENGRDA_handler(nitf_Error* error)
NITF_PLUGIN_FUNCTION_EXPORT(nitf_TREHandler*) ENGRDA_handler(nitf_Error* error)
{
(void)error;
return &engrdaHandler;
Expand Down
2 changes: 1 addition & 1 deletion modules/c/nitf/shared/EXPLTA.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static nitf_TREDescriptionInfo descriptions[] = {
{ "EXPLTA_101", descrip_00101, 101 },
{ NULL, NULL, NITF_TRE_DESC_NO_LENGTH }
};
static nitf_TREDescriptionSet descriptionSet = { 0, descriptions };
static nitf_TREDescriptionSet EXPLTADescriptionSet = { 0, descriptions };

NITF_DECLARE_PLUGIN(EXPLTA)

Expand Down
4 changes: 2 additions & 2 deletions modules/c/nitf/shared/HISTOA.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

NITF_CXX_GUARD

static nitf_TREDescription description[] = {
static nitf_TREDescription HISTOA_description[] = {
{NITF_BCS_A, 20, "System Type", "SYSTYPE" },
{NITF_BCS_A, 12, "Prior Compression", "PC" },
{NITF_BCS_A, 4, "Prior Enhancements", "PE" },
Expand Down Expand Up @@ -124,6 +124,6 @@ static nitf_TREDescription description[] = {
{NITF_END, 0, NULL, NULL}
};

NITF_DECLARE_SINGLE_PLUGIN(HISTOA, description)
NITF_DECLARE_SINGLE_PLUGIN_SIMPLE(HISTOA)

NITF_CXX_ENDGUARD
2 changes: 1 addition & 1 deletion modules/c/nitf/shared/IOMAPA.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static nitf_TREDescriptionInfo descriptions[] = {
{ "IOMAPA_91", descrip_00091, 91 },
{ NULL, NULL, NITF_TRE_DESC_NO_LENGTH }
};
static nitf_TREDescriptionSet descriptionSet = { 0, descriptions };
static nitf_TREDescriptionSet IOMAPADescriptionSet = { 0, descriptions };

NITF_DECLARE_PLUGIN(IOMAPA)

Expand Down
4 changes: 2 additions & 2 deletions modules/c/nitf/shared/JITCID.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

NITF_CXX_GUARD

static nitf_TREDescription description[] = {
static nitf_TREDescription JITCID_description[] = {
{NITF_BCS_A, NITF_TRE_GOBBLE, "File Comment", "FILCMT" },
{NITF_END, 0, NULL, NULL}
};
NITF_DECLARE_SINGLE_PLUGIN(JITCID, description)
NITF_DECLARE_SINGLE_PLUGIN_SIMPLE(JITCID)


NITF_CXX_ENDGUARD
2 changes: 1 addition & 1 deletion modules/c/nitf/shared/MENSRA.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static nitf_TREDescriptionInfo descriptions[] = {
{ "MENSRA_185", descrip_00185, 185 },
{ NULL, NULL, NITF_TRE_DESC_NO_LENGTH }
};
static nitf_TREDescriptionSet descriptionSet = { 0, descriptions };
static nitf_TREDescriptionSet MENSRADescriptionSet = { 0, descriptions };

NITF_DECLARE_PLUGIN(MENSRA)

Expand Down
2 changes: 1 addition & 1 deletion modules/c/nitf/shared/PATCHA.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static nitf_TREDescriptionInfo descriptions[] = {
{ NULL, NULL, NITF_TRE_DESC_NO_LENGTH }
};

static nitf_TREDescriptionSet descriptionSet = { 0, descriptions };
static nitf_TREDescriptionSet PATCHADescriptionSet = { 0, descriptions };

NITF_DECLARE_PLUGIN(PATCHA)

Expand Down
Loading

0 comments on commit 205bf8e

Please sign in to comment.