OpenASIP  2.0
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
OperationBehaviorLoader Class Reference

#include <OperationBehaviorLoader.hh>

Collaboration diagram for OperationBehaviorLoader:
Collaboration graph

Public Member Functions

 OperationBehaviorLoader (OperationIndex &index)
 
virtual ~OperationBehaviorLoader ()
 
OperationBehaviorimportBehavior (const Operation &parent)
 
void freeBehavior ()
 

Private Types

typedef std::map< std::string, OperationBehavior * > BehaviorMap
 Contains operation behavior models indexed by operation names. More...
 
typedef std::map< OperationBehavior *, void(*)(OperationBehavior *)> DestructionMap
 Contains all deletion function of operation behavior models. More...
 

Private Member Functions

 OperationBehaviorLoader (const OperationBehaviorLoader &)
 Copying not allowed. More...
 
OperationBehaviorLoaderoperator= (const OperationBehaviorLoader &)
 Assignment not allowed. More...
 

Private Attributes

OperationIndexindex_
 Indexed table of all modules and operations accessible for this loader. More...
 
PluginTools tools_
 PluginTools for loading dynamic modules. More...
 
BehaviorMap behaviors_
 Container of all loaded operation behavior models. More...
 
DestructionMap destructors_
 Container of all destruction functions of behavioral models. More...
 

Static Private Attributes

static const std::string CREATE_FUNC = "createOpBehavior_"
 The name of the creation function in dynamic module. More...
 
static const std::string DELETE_FUNC = "deleteOpBehavior_"
 The name of the deletion function in dynamic module. More...
 

Detailed Description

The purpose of this class is to import operation behavior models from dynamic modules.

PluginTools is used to import the operation behavior modules. OperationIndex is used to obtain modules in which certain operation belongs to.

Definition at line 54 of file OperationBehaviorLoader.hh.

Member Typedef Documentation

◆ BehaviorMap

typedef std::map<std::string, OperationBehavior*> OperationBehaviorLoader::BehaviorMap
private

Contains operation behavior models indexed by operation names.

Definition at line 65 of file OperationBehaviorLoader.hh.

◆ DestructionMap

Contains all deletion function of operation behavior models.

Definition at line 68 of file OperationBehaviorLoader.hh.

Constructor & Destructor Documentation

◆ OperationBehaviorLoader() [1/2]

OperationBehaviorLoader::OperationBehaviorLoader ( OperationIndex index)
explicit

Constructor.

OperationBehavior uses OperationIndex for getting the right modules.

Parameters
indexOperationIndex.
Note
The PluginTools instance should load the behavior modules in the LOCAL mode to enable overriding behavior definitions from later definitions in the search path. E.g., if base.opb defines ADD, a custom.opb can redefine it. If the symbols are made global then the latter symbol is not reloaded but the one from base.opb reused.

Definition at line 61 of file OperationBehaviorLoader.cc.

61  :
62  index_(index), tools_(false, true) {
63 }

◆ ~OperationBehaviorLoader()

OperationBehaviorLoader::~OperationBehaviorLoader ( )
virtual

Destructor.

Deletes all the loader operation behavior models.

Definition at line 70 of file OperationBehaviorLoader.cc.

70  {
71  freeBehavior();
72 }

References freeBehavior().

Here is the call graph for this function:

◆ OperationBehaviorLoader() [2/2]

OperationBehaviorLoader::OperationBehaviorLoader ( const OperationBehaviorLoader )
private

Copying not allowed.

Member Function Documentation

◆ freeBehavior()

void OperationBehaviorLoader::freeBehavior ( )

Frees all the imported behavior models of the operations.

Definition at line 136 of file OperationBehaviorLoader.cc.

136  {
137  DestructionMap::iterator iter = destructors_.begin();
138  while (iter != destructors_.end()) {
139  void (*behaviorDestructor)(OperationBehavior*) = (*iter).second;
140  behaviorDestructor((*iter).first);
141  iter++;
142  }
143  destructors_.clear();
144  behaviors_.clear();
146 }

References behaviors_, destructors_, tools_, and PluginTools::unregisterAllModules().

Referenced by OperationBehaviorProxy::uninitializeBehavior(), and ~OperationBehaviorLoader().

Here is the call graph for this function:

◆ importBehavior()

OperationBehavior & OperationBehaviorLoader::importBehavior ( const Operation parent)

Imports the behavior model of an operation.

First, the module that contains the given operation is obtained from OperationIndex. A pointer to appropriate create function is obtained and used to create OperationBehavior. Also pointer to appropriate destruction function is obtained and stored.

Parameters
parentThe operation that owns the loaded behavior.
Returns
Operation behavior model of the operation.
Exceptions
DynamicLibraryExceptionIf an error occurs while accessing the dynamic module.
FileNotFoundIf the .opb was not found.
SymbolNotFoundIf the constructor/destructor functions could not be imported from the .opb.

Definition at line 91 of file OperationBehaviorLoader.cc.

91  {
92  string name = parent.name();
93  // if behavior was already created, use it
94  BehaviorMap::iterator iter = behaviors_.find(name);
95  if (iter != behaviors_.end()) {
96  return *((*iter).second);
97  }
98 
99  try {
100  OperationModule& module = index_.moduleOf(name);
101  if (&module == &NullOperationModule::instance()) {
102  string msg = "Module for operation " + name + " not found";
103  throw InstanceNotFound(__FILE__, __LINE__, __func__, msg);
104  }
105 
106  string creatorName = CREATE_FUNC + StringTools::stringToUpper(name);
107  string destructorName = DELETE_FUNC + StringTools::stringToUpper(name);
108  string modName = module.behaviorModule();
109  OperationBehavior* (*behaviorCreator)(const Operation&);
110  void (*behaviorDestructor)(OperationBehavior*);
111  tools_.importSymbol(creatorName, behaviorCreator, modName);
112  tools_.importSymbol(destructorName, behaviorDestructor, modName);
113  OperationBehavior* behavior = behaviorCreator(parent);
114  behaviors_[name] = behavior;
115  destructors_[behavior] = behaviorDestructor;
116  return *behavior;
117 
118  } catch (const FileNotFound& e) {
119  throw e;
120  } catch (const SymbolNotFound& e) {
121  throw e;
122  } catch (const Exception& e) {
123  string msg =
124  std::string("Behavior definition for ") + parent.name() +
125  " could not be loaded.";
126  DynamicLibraryException error(__FILE__, __LINE__, __func__, msg);
127  error.setCause(e);
128  throw error;
129  }
130 }

References __func__, OperationModule::behaviorModule(), behaviors_, CREATE_FUNC, DELETE_FUNC, destructors_, PluginTools::importSymbol(), index_, NullOperationModule::instance(), OperationIndex::moduleOf(), Operation::name(), Exception::setCause(), StringTools::stringToUpper(), and tools_.

Referenced by OperationBehaviorProxy::initializeBehavior().

Here is the call graph for this function:

◆ operator=()

OperationBehaviorLoader& OperationBehaviorLoader::operator= ( const OperationBehaviorLoader )
private

Assignment not allowed.

Member Data Documentation

◆ behaviors_

BehaviorMap OperationBehaviorLoader::behaviors_
private

Container of all loaded operation behavior models.

Definition at line 85 of file OperationBehaviorLoader.hh.

Referenced by freeBehavior(), and importBehavior().

◆ CREATE_FUNC

const string OperationBehaviorLoader::CREATE_FUNC = "createOpBehavior_"
staticprivate

The name of the creation function in dynamic module.

Definition at line 76 of file OperationBehaviorLoader.hh.

Referenced by importBehavior().

◆ DELETE_FUNC

const string OperationBehaviorLoader::DELETE_FUNC = "deleteOpBehavior_"
staticprivate

The name of the deletion function in dynamic module.

Definition at line 78 of file OperationBehaviorLoader.hh.

Referenced by importBehavior().

◆ destructors_

DestructionMap OperationBehaviorLoader::destructors_
private

Container of all destruction functions of behavioral models.

Definition at line 87 of file OperationBehaviorLoader.hh.

Referenced by freeBehavior(), and importBehavior().

◆ index_

OperationIndex& OperationBehaviorLoader::index_
private

Indexed table of all modules and operations accessible for this loader.

Definition at line 81 of file OperationBehaviorLoader.hh.

Referenced by importBehavior().

◆ tools_

PluginTools OperationBehaviorLoader::tools_
private

PluginTools for loading dynamic modules.

Definition at line 83 of file OperationBehaviorLoader.hh.

Referenced by freeBehavior(), and importBehavior().


The documentation for this class was generated from the following files:
FileNotFound
Definition: Exception.hh:224
OperationBehaviorLoader::tools_
PluginTools tools_
PluginTools for loading dynamic modules.
Definition: OperationBehaviorLoader.hh:83
OperationBehaviorLoader::behaviors_
BehaviorMap behaviors_
Container of all loaded operation behavior models.
Definition: OperationBehaviorLoader.hh:85
OperationModule::behaviorModule
virtual std::string behaviorModule() const
Definition: OperationModule.cc:105
Operation::name
virtual TCEString name() const
Definition: Operation.cc:93
StringTools::stringToUpper
static std::string stringToUpper(const std::string &source)
Definition: StringTools.cc:143
PluginTools::importSymbol
void importSymbol(const std::string &symbolName, T *&target, const std::string &module)
SymbolNotFound
Definition: Exception.hh:623
OperationBehaviorLoader::index_
OperationIndex & index_
Indexed table of all modules and operations accessible for this loader.
Definition: OperationBehaviorLoader.hh:81
__func__
#define __func__
Definition: Application.hh:67
Exception
Definition: Exception.hh:54
Operation
Definition: Operation.hh:59
OperationBehavior
Definition: OperationBehavior.hh:53
OperationModule
Definition: OperationModule.hh:46
OperationBehaviorLoader::freeBehavior
void freeBehavior()
Definition: OperationBehaviorLoader.cc:136
OperationBehaviorLoader::CREATE_FUNC
static const std::string CREATE_FUNC
The name of the creation function in dynamic module.
Definition: OperationBehaviorLoader.hh:76
OperationBehaviorLoader::DELETE_FUNC
static const std::string DELETE_FUNC
The name of the deletion function in dynamic module.
Definition: OperationBehaviorLoader.hh:78
NullOperationModule::instance
static NullOperationModule & instance()
DynamicLibraryException
Definition: Exception.hh:588
OperationIndex::moduleOf
OperationModule & moduleOf(const std::string &name)
Definition: OperationIndex.cc:315
InstanceNotFound
Definition: Exception.hh:304
PluginTools::unregisterAllModules
void unregisterAllModules()
Definition: PluginTools.cc:236
OperationBehaviorLoader::destructors_
DestructionMap destructors_
Container of all destruction functions of behavioral models.
Definition: OperationBehaviorLoader.hh:87