VR-Vantage 1.4.1 API Class Documentation
exampleChannelPlugin

This example shows how to register a creator function using a plugin.

In this example, a new creator function is added for creating channels, but the concept applies for adding any kind of creator with a plugin.

The files DtExampleChannel.h and DtExampleChannel.cxx declare and define, respectively, the new type of channel to be created.

   class DT_DLL_EXAMPLECHANNELPLUGIN DtExampleChannel : public DtOsgChannel
   {

   public:

      friend class DtExampleChannelCreator;

      virtual ~DtExampleChannel();

   protected:

      DtExampleChannel(DtDe& de, DtWindow* window, DtChannelConfiguration& channelConfig);

   };

   DtExampleChannel::DtExampleChannel( DtDe& de, DtWindow* window, DtChannelConfiguration& channelConfig ) 
   : DtOsgChannel(de, window, channelConfig)
   {
      // Do nothing. This is an example of registing a class using the creator pattern
      // via a plugin.
   }

   DtExampleChannel::~DtExampleChannel()
   {

   }

They also declare and define the creator function that will be registered by the plugin.

   class DT_DLL_EXAMPLECHANNELPLUGIN DtExampleChannelCreator : public DtChannelCreator
   {

   public:

      virtual DtChannel* create(DtDe& de, DtWindow* window, DtChannelConfiguration& config);

   };

   DtChannel* DtExampleChannelCreator::create( DtDe& de, DtWindow* window, DtChannelConfiguration& config )
   {
      return new DtExampleChannel(de, window, config);
   }

exampleChannelPluginInit.h declares the plugin initialization method.

      DT_DLL_EXAMPLECHANNELPLUGIN void init(DtDe& anIG);
   }

Finally, exampleChannelPluginInit.cxx performs the standard plugin initialization in its init() method and registers the creator function for DtExampleChannel.

         DT_DE_INIT_ONCE(de);

         try
         {
            // First make sure that the vrvOsg module is init'ed.
            vrvOsg::init(de);

            // Setup the channel creator.
            DtChannelCreator::registerInstance(de, new DtExampleChannelCreator);

         }
         DtCATCH_AND_PROPAGATE(DtCorruptedState)

Building the Example

VR-Vantage includes pre-built versions of the example plug-in. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.

Running the Example

This example is a plug-in. You can run it by running ./bin/exampleChannelPlugin_stealth.bat (on Windows) or ./bin/exampleChannelPlugin_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.

Example Source Files


exampleChannelPluginInit.h

/******************************************************************************
** Copyright (c) 2007 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
/******************************************************************************
** $RCSfile: exampleChannelPluginInit.h,v $ $Revision: 1.4 $ $State: Exp $
******************************************************************************/

#ifndef exampleChannelPluginInit_h_
#define exampleChannelPluginInit_h_

// Get proper local export symbol
#include "exampleChannelPlugin.h"

// Setup proper plugin export symbol
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLECHANNELPLUGIN

// Export plugging function bool initDeModule(DtDe* de);
#include <vrvCore/exportPlugin.h>

namespace makVrv
{
   class DtDe;
   namespace vrvExampleChannelPlugin
   {
      DT_DLL_EXAMPLECHANNELPLUGIN void init(DtDe& anIG);
   }
}

#endif

exampleChannelPlugin.h

/******************************************************************************
** Copyright (c) 2007 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
/******************************************************************************
** $RCSfile: exampleChannelPlugin.h,v $ $Revision: 1.2 $ $State: Exp $
******************************************************************************/


#ifndef exampleChannelPlugin_H_
#define exampleChannelPlugin_H_

#ifdef _WIN32
#ifdef EXAMPLECHANNELPLUGIN_EXPORTS
#define DT_DLL_EXAMPLECHANNELPLUGIN __declspec ( dllexport )
#else
#define DT_DLL_EXAMPLECHANNELPLUGIN __declspec ( dllimport )
#endif
#else
#define DT_DLL_EXAMPLECHANNELPLUGIN
#endif


#endif

exampleChannelPluginInit.cxx

/******************************************************************************
** Copyright (c) 2007 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
/******************************************************************************
** $RCSfile: exampleChannelPluginInit.cxx,v $ $Revision: 1.3 $ $State: Exp $
******************************************************************************/


#include "exampleChannelPlugin.h"
#include "exampleChannelPluginInit.h"
#include "DtExampleChannel.h"
#include <vrvOsg/vrvOsg.h>
#include <vrvCore/DtDe.h>
#include <vrvCore/DtChannel.h>

bool initDeModule(makVrv::DtDe* de)
{
   makVrv::vrvExampleChannelPlugin::init(*de);
   return true;
}

namespace makVrv
{
   namespace vrvExampleChannelPlugin
   {
      void init(DtDe& de)
      {
         DT_DE_INIT_ONCE(de);

         try
         {
            // First make sure that the vrvOsg module is init'ed.
            vrvOsg::init(de);

            // Setup the channel creator.
            DtChannelCreator::registerInstance(de, new DtExampleChannelCreator);

         }
         DtCATCH_AND_PROPAGATE(DtCorruptedState)
      }
   }
}


Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)