#* This is a velocity template for generating C++ header files (*.h) with AgenPro 2 Copyright (C) 2002, Frank Fock. All rights Reserved. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *# ## ## DEFINES #set($tab = " ") #set($USR_BEGIN = "//--AgentGen BEGIN=") #set($USR_END = "//--AgentGen END") #set($DEFAULT_OBJECT_NAME_LENGTH = 32) ## ## MACROS ## #macro( NAMESPACE_END ) #ifdef AGENTPP_NAMESPACE } #endif #end #macro( NAMESPACE_BEGIN ) #ifdef AGENTPP_NAMESPACE namespace Agentpp { #endif #end ## ## preserveExistingCode ## #macro( preserveExistingCode $class $method ) #set($key = $class) #if ($method.length() > 0) ${tab}${USR_BEGIN}$key::${method} #set($key = "$class::$method") #else ${USR_BEGIN}${key} #end #if ($existingCode.get($key)) $existingCode.get($key) #end #if ($method.length() > 0) ${tab}${USR_END} #else ${USR_END} #end #end ## ## genNativeRepresentation ## #macro( genNativeRepresentation $syntax ) #if ($syntax.endsWith("32") || $syntax.endsWith("TimeTicks")) #if (!$syntax.equals("SnmpInt32"))unsigned long#elselong#end #end #end ## ## genSyntax ## #macro( genSyntax $syn) #if ($syn.getSyntax().equals("INTEGER") || $syn.getSyntax().equals("Integer32")) SnmpInt32 #elseif ($syn.getSyntax().equals("Counter") || $syn.getSyntax().equals("Counter32")) Counter32 #elseif ($syn.getSyntax().equals("Unsigned32")) Gauge32 #elseif ($syn.getSyntax().equals("IpAddress") || $syn.getSyntax().equals("NetworkAddress")) IpAddress #elseif ($syn.getSyntax().equals("OCTET STRING") || $syn.getSyntax().equals("BITS")) OctetStr #elseif ($syn.getSyntax().equals("Opaque")) Opaque #elseif ($syn.getSyntax().equals("Gauge") || $syn.getSyntax().equals("Gauge32")) Gauge32 #elseif ($syn.getSyntax().equals("Counter64")) Counter64 #elseif ($syn.getSyntax().equals("TimeTicks")) TimeTicks #elseif ($syn.getSyntax().equals("OBJECT IDENTIFIER")) Oid #else $syn.syntax #end #end ## ## genObjectName ## #macro( genObjectName $object )#if($agenUtils.isDefined($object.printableOid, "withModuleName"))$moduleNameNoHyphen.toLowerCase()\_#end$object.getName()#end ## ## genComment ## #macro( genComment $obj ) /** * $obj.getName() * $obj.formatLines(" * ", $obj.getDescription()) */ #end ## ## #macro( space $len ) #foreach ( $space in [0..$len] ) #end #end #macro( getOidName $name )oid$stringUtils.capitalizeFirstLetter($name.toString())#end #macro( objectNameDefs ) // Scalars #foreach ( $leaf in $scalars ) #set( $len = $DEFAULT_OBJECT_NAME_LENGTH - $leaf.getName().length() - 3 ) #define #getOidName($leaf)#space($len) "$leaf.getPrintableOid().0" #end // Columns #foreach ( $table in $tables ) #foreach ( $col in $columns.get($table) ) #set( $len = $DEFAULT_OBJECT_NAME_LENGTH - $col.getName().length() - 3 ) #define col$stringUtils.capitalizeFirstLetter($col.toString())#space($len) "$agenStringUtils.substitute($col.getPrintableOid(), ".*([0-9]+)", '$1')" #end #end // Tables #foreach ( $table in $tables ) #set( $len = $DEFAULT_OBJECT_NAME_LENGTH - $table.getName().length() - 3 ) #define #getOidName($table)#space($len) "$table.getPrintableOid().0" #foreach ( $col in $columns.get($table) ) #set( $len = $DEFAULT_OBJECT_NAME_LENGTH - $col.getName().length() - 2 ) #set( $count = $velocityCount - 1 ) #define n$stringUtils.capitalizeFirstLetter($col.toString())#space($len) $count #define c$stringUtils.capitalizeFirstLetter($col.toString())#space($len) $col.getOid().getLastSubID() #end #end // Notifications #foreach ( $trap in $notifications ) #set( $len = $DEFAULT_OBJECT_NAME_LENGTH - $trap.getName().length() - 3 ) #define #getOidName($trap)#space($len) "$trap.getPrintableOid()" #end #end ## ## genTableSuperClass ## #macro( genTableSuperClass $table $columns ) #set( $storageTable = "MibTable" ) #foreach ($leaf in $columns ) #if ($agenUtils.isStorageType($leaf)) #set( $storageTable = "StorageTable") #end #end$storageTable #end ## ## genSuperClassName ## #macro( genSuperClassName $obj ) #if ($agenUtils.isRowStatus($obj)) snmpRowStatus #elseif ($agenUtils.isDisplayString($obj)) SnmpDisplayString #elseif ($agenUtils.isStorageType($obj)) StorageType #else MibLeaf #end #end ## ## genSharedTableSuperClass ## #macro( genSharedTableSuperClass $table ) AgentXSharedTable#end ## ## LEAF DECLARATION ## #macro( genLeafDeclaration $leaf) #genComment($leaf) class #genObjectName($leaf): public #genSuperClassName($leaf) { public: #genObjectName($leaf)(#if ($leaf.isColumnarObject())const Oidx&); #else); #end virtual ~#genObjectName($leaf)(); #if (!$leaf.isColumnarObject()) static #genObjectName($leaf)* instance; #end #set($syntax = $agenUtils.getEffectiveSyntax($leaf.getSyntax()).getSyntax() ) #if ($leaf.isColumnarObject()) virtual MibEntryPtr clone(); #end #if ($agenUtils.isDefined($leaf.getPrintableOid(), "get_request") && !$agenUtils.isRowStatus($leaf)) virtual void get_request(Request*, int); #end ## match INTEGER, Integer32, Counter, Counter32, Gauge, Gauge32, UInteger32, ## TimeTicks #if ($agenStringUtils.matches($syntax.syntax, "[GSCUIT][nNiIoa].*[esrR2]")) #if ($agenUtils.isDefined($leaf.getPrintableOid(), "get_state")) #if ($syntax.syntax.startsWith("I")) virtual long get_state(); #else virtual unsigned long get_state(); #end #end #if ($agenUtils.isDefined($leaf.getPrintableOid(), "set_state")) #if ($syntax.syntax.startsWith("I")) virtual void set_state(long); #else virtual void set_state(unsigned long); #end #end #if ($agenUtils.isDefined($leaf.getPrintableOid(), "set_state") && $syntax.equals("Counter32")) virtual unsigned long inc(); #end #elseif ($syntax.syntax.equals("OctetStr") || $syntax.syntax.equals("IpAddress") || $syntax.syntax.equals("Counter64")) #if ($agenUtils.isDefined($leaf.getPrintableOid(), "get_state")) virtual $syntax.syntax get_state(); #end #if ($agenUtils.isDefined($leaf.getPrintableOid(), "set_state")) virtual void set_state(const ${syntax.syntax}&); #end #end #if ($agenUtils.isWritable($leaf)) #if ($agenUtils.isDefined($leaf.getPrintableOid(), "set")) virtual int set(const Vbx&); #end #if ($agenUtils.isDefined($leaf.getPrintableOid(), "prepare_set_request")) virtual int prepare_set_request(Request*, int&); #end #if ($agenUtils.isDefined($leaf.getPrintableOid(), "commit_set_request")) virtual int commit_set_request(Request*, int); #end #if ($agenUtils.isDefined($leaf.getPrintableOid(), "cleanup_set_request")) virtual void cleanup_set_request(Request*, int&); #end #if ($agenUtils.isDefined($leaf.getPrintableOid(), "undo_set_request")) virtual int undo_set_request(Request*, int&); #end #if ($agenUtils.isDefined($leaf.getPrintableOid(), "value_ok") && !$agenUtils.isRowStatus($leaf)) virtual boolean value_ok(const Vbx&); #end #end #if ($effectiveSyntax.hasEnums()) enum labels { #foreach ($en in $effectiveSyntax.getEnumsVector()) e_${en.getLabelWithoutHyphen()} = $en.getLongValue()#if ($countValue < $effectiveSyntax.getEnumsVector().size()),#end #end }; #end #preserveExistingCode($leaf.getName() "" ) }; #end ## ## ## TABLE DECLARATION ## ## -tool macros #macro( genSetRowParameters $columns) #foreach ($leaf in $columns) #if (!$leaf.getAccess().equals("not-accessible")), #set( $smiSyntax = $agenUtils.getEffectiveSyntax($leaf.getSyntax()).getSyntax().getSyntax()) #if ($smiSyntax == "OCTET STRING" || $smiSyntax == "BITS")const OctetStr& p$velocityCount#elseif($smiSyntax == "Opaque")const Opaque& p$velocityCount#elseif ($smiSyntax == "IpAddress" || $smiSyntax == "OBJECT IDENTIFIER")const char* p$velocityCount#elseif ($smiSyntax == "Counter64")unsigned long p${velocityCount}hi, unsigned long p${velocityCount}lo#elseif ($smiSyntax.equals("INTEGER") || $smiSyntax.equals("Integer32"))long p$velocityCount#else unsigned long p$velocityCount#end #end #end #end #macro( genSetRow $table $columns ) #if ($columns.size() > 0) virtual void set_row(MibTableRow* r#genSetRowParameters($columns)); #end #end ## -main #macro( genTableDeclaration $table $columns ) #genComment($table) class #genObjectName($table): public #if($agenUtils.isDefined($table.printableOid, "agentXSharedTables"))#genSharedTableSuperClass($table)#else#genTableSuperClass($table $columns)#end { public: #if($agenUtils.isDefined($table.printableOid, "agentXSharedTables")) #genObjectName($table)(const OctetStr&, SubAgentXMib*); #else #genObjectName($table)(); #end virtual ~#genObjectName($table)(); static #genObjectName($table)* instance; #if (!$agenUtils.isDefined($table.printableOid, "tableAsComplexEntry") && $agenUtils.isDefined($table.printableOid, "ready_for_service")) virtual boolean ready_for_service(Vbx*, int); #end #if ($agenUtils.isDefined($table.printableOid, "tableAsComplexEntry") || $agenUtils.isDefined($table.printableOid, "get_request")) virtual void get_request(Request*, int); #end #if ($agenUtils.isDefined($table.printableOid, "tableAsComplexEntry") || $agenUtils.isDefined($table.printableOid, "get_next_request")) virtual void get_next_request(Request*, int); #end #if ($agenUtils.isDefined($table.printableOid, "tableAsComplexEntry") || $agenUtils.isDefined($table.printableOid, "commit_set_request")) virtual int commit_set_request(Request*, int); #end #if ($agenUtils.isDefined($table.printableOid, "tableAsComplexEntry") || $agenUtils.isDefined($table.printableOid, "prepare_set_request")) virtual int prepare_set_request(Request*, int&); #end #if ($agenUtils.isDefined($table.printableOid, "tableAsComplexEntry") || $agenUtils.isDefined($table.printableOid, "cleanup_set_request")) virtual void cleanup_set_request(Request*, int&); #end #if ($agenUtils.isDefined($table.printableOid, "tableAsComplexEntry") || $agenUtils.isDefined($table.printableOid, "undo_set_request")) virtual int undo_set_request(Request*, int&); #end #if (!$agenUtils.isDefined($table.printableOid, "tableAsComplexEntry")) #if ($agenUtils.isDefined($table.printableOid, "row_added")) virtual void row_added(MibTableRow*, const Oidx&, MibTable*); #end #if ($agenUtils.isDefined($table.printableOid, "row_delete")) virtual void row_delete(MibTableRow*, const Oidx&, MibTable*); #end #if ($agenUtils.isDefined($table.printableOid, "row_init")) virtual void row_init(MibTableRow*, const Oidx&, MibTable*); #end #if ($agenUtils.isDefined($table.printableOid, "row_activated")) virtual void row_activated(MibTableRow*, const Oidx&, MibTable*); #end #if ($agenUtils.isDefined($table.printableOid, "row_deactivated")) virtual void row_deactivated(MibTableRow*, const Oidx&, MibTable*); #end #if ($agenUtils.isDefined($table.printableOid, "update")) virtual void update(Request*); #end #if ($agenUtils.isDefined($table.printableOid, "is_transition_ok")) virtual int is_transition_ok(MibTable*, MibTableRow*, const Oidx&, int, int); #end #else virtual Oidx find_succ(const Oidx&, Request* req = 0); virtual MibEntry* clone(); #end #if ($agenUtils.isDefined($table.printableOid, "set_row")) #genSetRow($table $columns) #end #preserveExistingCode($table.getName() "" ) }; #end ## ## ## NOTIFICATION DECLARATION ## #macro( genNotificationDeclaration $trap ) #genComment($trap) class #genObjectName($trap): public NotificationOriginator { public: #genObjectName($trap)(); virtual ~#genObjectName($trap)(); virtual void generate(Vbx*, int, const OctetStr&); #preserveExistingCode($trap.getName() ""); }; #end ## ## ## CODE GENERATION ## #preserveExistingCode( "_BEGIN" "" ) #ifndef _$fileNameNoDot #define _$fileNameNoDot \#include \#include \#include \#include #if( $agenUtils.isDefined("simulation")) ##include #end #if( $agenUtils.isDefined("agentX")) \#include #end #if( $agenUtils.isDefined("agentXSharedTables")) #ifndef ${moduleNameNoHyphen.toUpperCase()}_SHARED_TABLES #define ${moduleNameNoHyphen.toUpperCase()}_SHARED_TABLES #endif #end ## #objectNameDefs() #preserveExistingCode( "_INCLUDE" "" ) #NAMESPACE_BEGIN() // Scalar Objects #foreach ( $leaf in $scalars ) #if (!$agenUtils.isDefined($leaf.printableOid, "skip")) #genLeafDeclaration($leaf) #end #end // Columnar Objects #foreach ( $table in $tables ) #foreach ( $leaf in $columns.get($table) ) #if (!$agenUtils.isDefined($leaf.printableOid, "skip")) #if (!$agenUtils.isDefined($leaf.printableOid, "tableAsComplexEntry") ) #if( !$agenUtils.isDefined($leaf.printableOid, "lightTables") || (!$leaf.getAccess().equals("read-only")) ) #genLeafDeclaration($leaf) #end #end #end #end #end // Tables #foreach ( $table in $tables ) #if (!$agenUtils.isDefined($table.printableOid, "skip")) #genTableDeclaration($table $columns.get($table)) #end #end // Notifications #foreach ( $trap in $notifications ) #if (!$agenUtils.isDefined($trap.printableOid, "skip")) #genNotificationDeclaration($trap) #end #end // Group class $moduleNameNoHyphen.toLowerCase(): public MibGroup { public: ${tab}${moduleNameNoHyphen.toLowerCase()}#if ($agenUtils.isDefined($module.printableOid, "agentX"))(const OctetStr&, SubAgentXMib*)#else()#end; ${tab}virtual ~${moduleNameNoHyphen.toLowerCase()}() { } #preserveExistingCode( $moduleNameNoHyphen.toLowerCase() "" ) }; #NAMESPACE_END() #preserveExistingCode( "_END" "" ) #endif