Exemplo n.º 1
0
    nitf_PluginRegistry_loadPlugin(const char* fullName, nitf_Error * error)
{
    
    /*  For now, the key is the dll name minus the extension  */
    char keyName[NITF_MAX_PATH] = "";
    char* p;
    int ok;
    int i, begin, end;
    nitf_DLL *dll;
    char **ident;
    nitf_PluginRegistry* reg = nitf_PluginRegistry_getInstance(error);

    /*  Construct the DLL object  */
    dll = nitf_DLL_construct(error);
    if (!dll)
    {
        return NITF_FAILURE;
    }
    /*  Otherwise we can load the DLL  */
    if (!nitf_DLL_load(dll, fullName, error))
    {
        /*  
         * If the load failed, we have a set error
         *  So all we have to do is close shop, go home
         */
        return NITF_FAILURE;
    }
    nitf_Utils_baseName(keyName, fullName, NITF_DLL_EXTENSION);
    
    /* Now init the plugin!!!  */
    ident = doInit(dll, keyName, error);
    
    /*  If no ident, we have a set error and an invalid plugin  */
    if (ident)
    {
        /*  I expect to have problems with this now and then  */
        ok = insertPlugin(reg, ident, dll, error);
        
        /*  If insertion failed, take our toys and leave  */
        if (!ok)
        {
            return NITF_FAILURE;
        }
#if NITF_DEBUG_PLUGIN_REG
        printf("Successfully loaded plugin: [%s] at [%p]\n",
               keyName, dll);
#endif
        return NITF_SUCCESS;
    }
    return NITF_FAILURE;
    
}
Exemplo n.º 2
0
/*
 *  This function is a garbage-collector.
 *  It is called at exit time.  In the event that the singleton
 *  is properly returned, it destructs it.
 *
 *  Since this function is only registered in the getInstance()
 *  call in the first place, it is presumed to exist already, and
 *  thereby need destruction.
 *
 */
NITFPRIV(void) exitListener(void)
{
    nitf_Error error;
    nitf_Mutex* mutex = GET_MUTEX();
    nitf_PluginRegistry *single = nitf_PluginRegistry_getInstance(&error);
    if (single)
    {
        int unloadRet = nitf_PluginRegistry_unload(single, &error);
        if (unloadRet)
        {
            implicitDestruct(&single);
        }
    }
    nitf_Mutex_delete(mutex);
}
Exemplo n.º 3
0
NITFAPI(NITF_BOOL) nitf_PluginRegistry_loadDir(const char *dirName,
                                               nitf_Error * error)
{
    NITF_BOOL status;

    /* first, get the registry */
    nitf_PluginRegistry *reg = nitf_PluginRegistry_getInstance(error);

    /* must be thread safe */
    nitf_Mutex_lock( GET_MUTEX() );

    status = nitf_PluginRegistry_internalLoadDir(reg, dirName, error);

    /* unlock */
    nitf_Mutex_unlock( GET_MUTEX() );
    return status;
}
Exemplo n.º 4
0
nitf_PluginRegistry_registerTREHandler(NITF_PLUGIN_INIT_FUNCTION init,
                                       NITF_PLUGIN_TRE_HANDLER_FUNCTION handle,
                                       nitf_Error * error)
{

    nitf_PluginRegistry* reg = nitf_PluginRegistry_getInstance(error);

    const char** ident;
    int i = 1;
    int ok = 1;
    if (!reg)
    {
        return NITF_FAILURE;
    }
    if ( (ident = (*init)(error)) == NULL)
    {
        return NITF_FAILURE;
    }

    if (!ident[0] || (strcmp(ident[0], NITF_PLUGIN_TRE_KEY) != 0))
    {
        nitf_Error_initf(error,
                         NITF_CTXT,
                         NITF_ERR_INVALID_OBJECT,
                         "Expected a TRE identity");
        return NITF_FAILURE;
    }

    for (; ident[i] != NULL; ++i)
    {
#ifdef NITF_DEBUG_PLUGIN_REG
        if (nitf_HashTable_exists(reg->treHandlers, ident[i]))
        {
            printf("Warning, static handler overriding [%s] hook\n", ident[i]);
        }
#endif
        ok &= nitf_HashTable_insert(reg->treHandlers, ident[i], (NITF_DATA*)handle, error);
    }

    return ok;

}
Exemplo n.º 5
0
nitf_PluginRegistry_TREHandlerExists(const char* ident)
{
    NITF_BOOL exists;
    nitf_Error error;

    /* first, get the registry */
    nitf_PluginRegistry* const reg = nitf_PluginRegistry_getInstance(&error);
    if (reg == NULL)
    {
        return NITF_FAILURE;
    }

    /* must be thread safe */
    nitf_Mutex_lock(GET_MUTEX());

    exists = nitf_PluginRegistry_internalTREHandlerExists(reg, ident);

    /* unlock */
    nitf_Mutex_unlock(GET_MUTEX());

    return exists;
}
Exemplo n.º 6
0
nitf_PluginRegistry_retrieveCompInterface(const char *comp,
                                          nitf_Error* error)
{
    /* In all cases below, the function we're calling should populate the
     * error if one occurs. */
    nitf_PluginRegistry *reg;
    nitf_CompressionInterface *compIface;
    NITF_PLUGIN_COMPRESSION_CONSTRUCT_FUNCTION constructCompIface;
    int hadError = 0;

    /*  Find the compression interface here  */
    reg = nitf_PluginRegistry_getInstance(error);
    if (!reg)
    {
        return NULL;
    }

    /*  Now retrieve the comp iface creator  */
    constructCompIface =
        nitf_PluginRegistry_retrieveCompConstructor(reg,
                comp, &hadError, error);
    if (hadError || constructCompIface == NULL)
    {
        return NULL;
    }

    /* Now actually construct it */
    compIface =
        (nitf_CompressionInterface *) (*constructCompIface) (comp,
                error);
    if (compIface == NULL)
    {
        return NULL;
    }

    return compIface;
}
Exemplo n.º 7
0
int main(int argc, char **argv)
{
    /*  This is the reader object  */
    nitf_Reader* reader;
    nitf_Record*   record;
    /*  The IO handle  */
    nitf_IOHandle io;
    /*  Get the error object       */
    nitf_Error     error;

    /*  Check argv and make sure we are happy  */
    if ( argc != 2 )
    {
        printf("Usage: %s <nitf-file>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    io = nitf_IOHandle_create(argv[1],
                              NITF_ACCESS_READONLY,
                              NITF_OPEN_EXISTING,
                              &error);
    if ( NITF_INVALID_HANDLE( io ) )
    {
        nitf_Error_print(&error, stdout, "Exiting...");
        exit( EXIT_FAILURE );
    }

    reader = nitf_Reader_construct(&error);
    if (!reader)
    {
        nitf_Error_print(&error, stdout, "Exiting (1) ...");
        exit( EXIT_FAILURE );
    }

    printf("Here are the loaded handlers\n");
    printf("* * * * * * * * * * * * * * * *\n");
    {
        nitf_PluginRegistry* reg = nitf_PluginRegistry_getInstance(&error);
        nitf_HashTable_print( reg->treHandlers);
    }
    printf("* * * * * * * * * * * * * * * *\n");

    record = nitf_Reader_read(reader, io, &error);
    if (!record)
    {
        nitf_Error_print(&error, stderr, "Failed to read the file");
        exit(EXIT_FAILURE);

    }

    /* Now show the header */
    showFileHeader(record->header);

    /* And now show the image information */
    if (record->header->numImages)
    {

        /*  Walk each image and show  */
        nitf_ListIterator iter = nitf_List_begin(record->images);
        nitf_ListIterator end  = nitf_List_end(record->images);

        while ( nitf_ListIterator_notEqualTo(&iter, &end) )
        {
            nitf_ImageSegment* segment =
                (nitf_ImageSegment*)nitf_ListIterator_get(&iter);

            nitf_ImageSubheader* dolly =
                nitf_ImageSubheader_clone(segment->subheader, &error);
            if (!dolly)
            {
                nitf_Error_print(&error, stdout, "During cloning!");
                exit(EXIT_FAILURE);
            }

            SHOW_IMSUB(segment->subheader);
            SHOW_IMSUB(dolly);

            nitf_ImageSubheader_destruct(&dolly);

            nitf_ListIterator_increment(&iter);

        }
    }
    else
    {
        printf("No image in file!\n");
    }

    nitf_IOHandle_close(io);
    nitf_Record_destruct(&record);
    nitf_Reader_destruct(&reader);

    return 0;
}
Exemplo n.º 8
0
int main(int argc, char**argv)
{
    nitf_Error error;
    nitf_PluginRegistry* reg;
    NITF_PLUGIN_TRE_HANDLER_FUNCTION test_main;
    int bad = 0;
    if (argc != 2)
    {
        printf("Usage: %s <TRE>\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    reg = nitf_PluginRegistry_getInstance(&error);

    if (!reg)
    {
        nitf_Error_print(&error, stdout, "Exiting...");
        exit(EXIT_FAILURE);
    }
    /*  Don't need this now that it is a singleton
     *
     * if (! nitf_PluginRegistry_load(reg, &error) )
     * {
     *   nitf_Error_print(&error, stdout, "Exiting...");
     *   exit(EXIT_FAILURE);
     * }
     */

    nitf_HashTable_print(reg->treHandlers);

    test_main =
        nitf_PluginRegistry_retrieveTREHandler(reg,
                                               argv[1],
                                               &bad,
                                               &error);


    if (bad)
    {
        nitf_Error_print(&error, stderr, "Error!");
    }
    else if (test_main == (NITF_PLUGIN_TRE_HANDLER_FUNCTION)NULL)
    {
        printf("No such plugin could be found\n");
    }
    else
    {
        int ok;
        printf("Found DLL and main!!!\n");
        ok = (*test_main)(0, NULL, NULL, &error);
        if (!ok)
        {
            nitf_Error_print(&error, stderr , "");
        }

    }


    /*  Don't need this now that the registry is a singleton
     *  if (! nitf_PluginRegistry_unload(reg, &error) )
     *  {
     *    nitf_Error_print(&error, stdout, "Exiting...");
     *    exit(EXIT_FAILURE);
     *  }
     */

    /*  Don't need this now that the registry is a singleton
     *
     *  nitf_PluginRegistry_destruct(&reg);
     */
    return 0;

}