diff options
Diffstat (limited to 'src/usr/hwpf/fapi')
-rw-r--r-- | src/usr/hwpf/fapi/fapiAttributeService.C | 187 | ||||
-rwxr-xr-x | src/usr/hwpf/fapi/fapiParseAttributeInfo.pl | 144 | ||||
-rwxr-xr-x | src/usr/hwpf/fapi/fapiParseErrorInfo.pl | 79 | ||||
-rw-r--r-- | src/usr/hwpf/fapi/fapiReturnCode.C | 192 | ||||
-rw-r--r-- | src/usr/hwpf/fapi/fapiReturnCodeDataRef.C | 85 | ||||
-rw-r--r-- | src/usr/hwpf/fapi/fapiTarget.C | 118 | ||||
-rw-r--r-- | src/usr/hwpf/fapi/makefile | 13 |
7 files changed, 818 insertions, 0 deletions
diff --git a/src/usr/hwpf/fapi/fapiAttributeService.C b/src/usr/hwpf/fapi/fapiAttributeService.C new file mode 100644 index 000000000..c48557398 --- /dev/null +++ b/src/usr/hwpf/fapi/fapiAttributeService.C @@ -0,0 +1,187 @@ +/** + * @file fapiAttributeService.C + * + * @brief Implements the AttributeService functions. + */ + +#include <stdio.h> +#include <fapiAttributeService.H> +#include <fapiPlatTrace.H> + +namespace fapi +{ + +namespace AttributeService +{ + +//****************************************************************************** +// Get string +//****************************************************************************** +template<> +ReturnCode _get<char *> (const AttributeId i_id, + const Target * const i_pTarget, + char * & o_value) +{ + FAPI_ERR("Get string attribute not implemented"); + return FAPI_RC_NOT_IMPLEMENTED; +} + +//****************************************************************************** +// Get uint8_t +//****************************************************************************** +template<> +ReturnCode _get<uint8_t> (const AttributeId i_id, + const Target * const i_pTarget, + uint8_t & o_value) +{ + FAPI_ERR("Get uint8 attribute not implemented"); + return FAPI_RC_NOT_IMPLEMENTED; +} + +//****************************************************************************** +// Get uint32_t +//****************************************************************************** +template<> +ReturnCode _get<uint32_t> (const AttributeId i_id, + const Target * const i_pTarget, + uint32_t & o_value) +{ + FAPI_ERR("Get uint32 attribute not implemented"); + return FAPI_RC_NOT_IMPLEMENTED; +} + +//****************************************************************************** +// Get uint64_t +//****************************************************************************** +template<> +ReturnCode _get<uint64_t> (const AttributeId i_id, + const Target * const i_pTarget, + uint64_t & o_value) +{ + FAPI_ERR("Get uint64 attribute not implemented"); + return FAPI_RC_NOT_IMPLEMENTED; +} + +//****************************************************************************** +// Get uint8_t array +//****************************************************************************** +template<> +ReturnCode _get<uint8_t *> (const AttributeId i_id, + const Target * const i_pTarget, + uint8_t * const o_pValues) +{ + FAPI_ERR("Get uint8 array attribute not implemented"); + return FAPI_RC_NOT_IMPLEMENTED; +} + +//****************************************************************************** +// Get uint32_t array +//****************************************************************************** +template<> +ReturnCode _get<uint32_t *> (const AttributeId i_id, + const Target * const i_pTarget, + uint32_t * const o_pValues) +{ + FAPI_ERR("Get uint32 array attribute not implemented"); + return FAPI_RC_NOT_IMPLEMENTED; +} + +//****************************************************************************** +// Get uint64_t array +//****************************************************************************** +template<> +ReturnCode _get<uint64_t *> (const AttributeId i_id, + const Target * const i_pTarget, + uint64_t * const o_pValues) +{ + FAPI_ERR("Get uint64 array attribute not implemented"); + return FAPI_RC_NOT_IMPLEMENTED; +} + +//****************************************************************************** +// Set string +//****************************************************************************** +template<> +ReturnCode _set<char *> (const AttributeId i_id, + const Target * const i_pTarget, + const char * const i_pValue) +{ + FAPI_ERR("Set string attribute not implemented"); + return FAPI_RC_NOT_IMPLEMENTED; +} + +//****************************************************************************** +// Set uint8_t +//****************************************************************************** +template<> +ReturnCode _set<uint8_t> (const AttributeId i_id, + const Target * const i_pTarget, + const uint8_t i_value) +{ + FAPI_ERR("Set uint8 attribute not implemented"); + return FAPI_RC_NOT_IMPLEMENTED; +} + +//****************************************************************************** +// Set uint32_t +//****************************************************************************** +template<> +ReturnCode _set<uint32_t> (const AttributeId i_id, + const Target * const i_pTarget, + const uint32_t i_value) +{ + FAPI_ERR("Set uint32 attribute not implemented"); + return FAPI_RC_NOT_IMPLEMENTED; +} + +//****************************************************************************** +// Set uint64_t +//****************************************************************************** +template<> +ReturnCode _set<uint64_t> (const AttributeId i_id, + const Target * const i_pTarget, + const uint64_t i_value) +{ + FAPI_ERR("Set uint64 attribute not implemented"); + return FAPI_RC_NOT_IMPLEMENTED; +} + +//****************************************************************************** +// Set uint8_t array +//****************************************************************************** +template<> +ReturnCode _set<uint8_t *> (const AttributeId i_id, + const Target * const i_pTarget, + const uint8_t * const i_pValues) +{ + FAPI_ERR("Set uint8 array attribute not implemented"); + return FAPI_RC_NOT_IMPLEMENTED; +} + +//****************************************************************************** +// Set uint32_t array +//****************************************************************************** +template<> +ReturnCode _set<uint32_t *> (const AttributeId i_id, + const Target * const i_pTarget, + const uint32_t * const i_pValues) +{ + FAPI_ERR("Set uint32 array attribute not implemented"); + return FAPI_RC_NOT_IMPLEMENTED; +} + +//****************************************************************************** +// Set uint64_t array +//****************************************************************************** +template<> +ReturnCode _set<uint64_t *> (const AttributeId i_id, + const Target * const i_pTarget, + const uint64_t * const i_pValues) +{ + FAPI_ERR("Set uint64 array attribute not implemented"); + return FAPI_RC_NOT_IMPLEMENTED; +} + +} // namespace AttributeService + +} // namespace fapi diff --git a/src/usr/hwpf/fapi/fapiParseAttributeInfo.pl b/src/usr/hwpf/fapi/fapiParseAttributeInfo.pl new file mode 100755 index 000000000..8151b0ef6 --- /dev/null +++ b/src/usr/hwpf/fapi/fapiParseAttributeInfo.pl @@ -0,0 +1,144 @@ +#!/usr/bin/perl + +# +# Usage: +# fapiParseAttributeInfo.pl <filename1> <filename2> .... <filenameN> + +use strict; + +my $numArgs = $#ARGV + 1; +#print $numArgs, "\n"; + +if ($numArgs < 1) +{ + print ("Usage: fapiParseAttributeInfo.pl <filename1> <filename2> .... <filenameN>\n"); + print (" This perl script will parse attribute XML files,\n"); + print (" pull out the attribute IDs/types and create a header file\n"); + print (" fapiAttributeIds.H containing the information.\n"); + exit(1); +} + + + +# use module +use XML::Simple; +#use Data::Dumper; + +#open output file for writing +open(OUTFILE, ">fapiAttributeIds.H"); +print OUTFILE "// fapiAttributeIds.H\n"; +print OUTFILE "// This file is generated by perl script fapiParseAttributeInfo.pl\n\n"; +print OUTFILE "#ifndef FAPIATTRIBUTEIDS_H_\n"; +print OUTFILE "#define FAPIATTRIBUTEIDS_H_\n\n"; +print OUTFILE "namespace fapi\n"; +print OUTFILE "{\n\n"; +print OUTFILE "\/**\n"; +print OUTFILE " * \@brief Enumeration of attribute IDs\n"; +print OUTFILE " *\/\n"; +print OUTFILE "enum AttributeId\n"; +print OUTFILE "{\n"; + +# create object +my $xml = new XML::Simple (KeyAttr=>[]); + +#for each Hwp Attribute XML file +my $infile; +foreach $infile(@ARGV) +{ + #print filename + #print $ifile, "\n\n"; + + # read XML file + my $attributes = $xml->XMLin($infile); + + # print output + #print Dumper($attributes); + #print "\n"; + + # print attribute id to file + my $attr; + foreach $attr (@{$attributes->{attribute}}) + { + if ($attr->{id}) + { + print OUTFILE " ", $attr->{id}, ",\n"; + } + else + { + print ("fapiParseAttributeInfo.pl ERROR. Attribute ID missing\n"); + exit(1); + } + }; +} + +print OUTFILE "};\n\n"; + +print OUTFILE "\/**\n"; +print OUTFILE " * \@brief Typedefs for the attribute value types\n"; +print OUTFILE " *\/\n"; + +#for each Hwp Attribute XML file +foreach $infile(@ARGV) +{ + # read XML file + my $attributes = $xml->XMLin($infile); + + # print attribute id to file + my $attr; + foreach $attr (@{$attributes->{attribute}}) + { + print OUTFILE "typedef "; + + if ($attr->{valueType} eq 'uint8') + { + if ($attr->{array}) + { + print OUTFILE "uint8_t * "; + } + else + { + print OUTFILE "uint8_t "; + } + } + elsif ($attr->{valueType} eq 'uint32') + { + if ($attr->{array}) + { + print OUTFILE "uint32_t * "; + } + else + { + print OUTFILE "uint32_t "; + } + } + elsif ($attr->{valueType} eq 'uint64') + { + if ($attr->{array}) + { + print OUTFILE "uint64_t * "; + } + else + { + print OUTFILE "uint64_t "; + } + } + elsif ($attr->{valueType} eq 'string') + { + print OUTFILE "char * "; + } + else + { + print ("fapiParseAttributeInfo.pl ERROR. valueType not recognized: "); + print $attr->{valueType}, "\n"; + exit(1); + } + + print OUTFILE $attr->{id}, "_Type;\n"; + }; +} + +print OUTFILE "\n}\n\n"; +print OUTFILE "#endif\n"; + +#close output file +close(OUTFILE); diff --git a/src/usr/hwpf/fapi/fapiParseErrorInfo.pl b/src/usr/hwpf/fapi/fapiParseErrorInfo.pl new file mode 100755 index 000000000..e0dc8b652 --- /dev/null +++ b/src/usr/hwpf/fapi/fapiParseErrorInfo.pl @@ -0,0 +1,79 @@ +#!/usr/bin/perl + +# +# Usage: +# fapiParseErrorInfo.pl <filename1> <filename2> .... <filenameN> + +use strict; + +my $numArgs = $#ARGV + 1; +#print $numArgs, "\n"; + +if ($numArgs < 1) +{ + print ("Usage: fapiParseErrorInfo.pl <filename1> <filename2> .... <filenameN>\n"); + print (" This perl script will parse HWP Error XML files,\n"); + print (" pull out the error Return Codes and create a header file\n"); + print (" hwp/fapiHwpReturnCodes.H containing an enumeration of them.\n"); + exit(1); +} + + + +# use module +use XML::Simple; +#use Data::Dumper; + +#open output file for writing +open(OUTFILE, ">fapiHwpReturnCodes.H"); +print OUTFILE "// fapiHwpReturnCodes.H\n"; +print OUTFILE "// This file is generated by perl script fapiParseErrorInfo.pl\n\n"; +print OUTFILE "#ifndef FAPIHWPRETURNCODES_H_\n"; +print OUTFILE "#define FAPIHWPRETURNCODES_H_\n\n"; +print OUTFILE "namespace fapi\n"; +print OUTFILE "{\n\n"; +print OUTFILE "/**\n"; +print OUTFILE " * \@brief Enumeration of HWP return codes\n"; +print OUTFILE " *\/\n"; +print OUTFILE "enum HwpReturnCode\n"; +print OUTFILE "{\n"; + +# create object +my $xml = new XML::Simple (KeyAttr=>[]); +my $infile; + +#for each Hwp Attribute XML file +foreach $infile(@ARGV) +{ + #print filename + #print $ifile, "\n\n"; + + # read XML file + my $errors = $xml->XMLin($infile); + + # print output + #print Dumper($errors); + #print "\n"; + + # print return code to file + my $err; + foreach $err (@{$errors->{hwpError}}) + { + if ($err->{id}) + { + print OUTFILE " ", $err->{id}, ",\n"; + } + else + { + print ("fapiParseErrorInfo.pl ERROR. ID missing\n"); + exit(1); + } + }; +} + +print OUTFILE "};\n\n"; +print OUTFILE "}\n\n"; +print OUTFILE "#endif\n"; + +#close output file +close(OUTFILE); diff --git a/src/usr/hwpf/fapi/fapiReturnCode.C b/src/usr/hwpf/fapi/fapiReturnCode.C new file mode 100644 index 000000000..b32ae0f2f --- /dev/null +++ b/src/usr/hwpf/fapi/fapiReturnCode.C @@ -0,0 +1,192 @@ +/** + * @file fapiReturnCode.C + * + * @brief Implements the ReturnCode class. + */ + +#include <fapiReturnCode.H> +#include <fapiReturnCodeDataRef.H> + +namespace fapi +{ + +//****************************************************************************** +// Default Constructor +//****************************************************************************** +ReturnCode::ReturnCode() : + iv_rcValue(FAPI_RC_SUCCESS), iv_pDataRef(NULL) +{ + +} + +//****************************************************************************** +// Constructor +//****************************************************************************** +ReturnCode::ReturnCode(const uint32_t i_rcValue) : + iv_rcValue(i_rcValue), iv_pDataRef(NULL) +{ + +} + +//****************************************************************************** +// Copy Constructor +//****************************************************************************** +ReturnCode::ReturnCode(const ReturnCode & i_right) : + iv_rcValue(i_right.iv_rcValue), iv_pDataRef(i_right.iv_pDataRef) +{ + // Note shallow copy (in initializer list) of iv_pDataRef pointer. Both + // ReturnCodes now points to the same ReturnCodeDataRef + + if (iv_pDataRef) + { + // Increase the ReturnCodeDataRef reference count + (void) iv_pDataRef->incRefCount(); + } +} + +//****************************************************************************** +// Destructor +//****************************************************************************** +ReturnCode::~ReturnCode() +{ + // Remove interest in any pointed to ReturnCodeDataRef + (void) removeData(); +} + +//****************************************************************************** +// Assignment Operator +//****************************************************************************** +ReturnCode & ReturnCode::operator=(const ReturnCode & i_right) +{ + // Test for self assignment + if (this != &i_right) + { + // Remove interest in any pointed to ReturnCodeDataRef + (void) removeData(); + + // Copy instance variables. Note shallow copy of iv_pDataRef pointer. + // Both ReturnCodes now points to the same ReturnCodeDataRef + iv_rcValue = i_right.iv_rcValue; + iv_pDataRef = i_right.iv_pDataRef; + + if (iv_pDataRef) + { + // Increase the ReturnCodeDataRef reference count + (void) iv_pDataRef->incRefCount(); + } + } + return *this; +} + +//****************************************************************************** +// Assignment Operator +//****************************************************************************** +ReturnCode & ReturnCode::operator=(const uint32_t i_rcValue) +{ + iv_rcValue = i_rcValue; + return *this; +} + +//****************************************************************************** +// ok function +//****************************************************************************** +bool ReturnCode::ok() const +{ + return (iv_rcValue == FAPI_RC_SUCCESS); +} + +//****************************************************************************** +// returnCode_t cast +//****************************************************************************** +ReturnCode::operator uint32_t() const +{ + return iv_rcValue; +} + +//****************************************************************************** +// getData function +//****************************************************************************** +void * ReturnCode::getData() const +{ + const void * l_pData = NULL; + + if (iv_pDataRef) + { + // Get the data + l_pData = iv_pDataRef->getData(); + } + + // Remove the constness and return + return const_cast<void *>(l_pData); +} + +//****************************************************************************** +// releaseData function +//****************************************************************************** +void * ReturnCode::releaseData() +{ + const void * l_pData = NULL; + + if (iv_pDataRef) + { + // Release the data + l_pData = iv_pDataRef->releaseData(); + + // Remove interest in pointed to ReturnCodeDataRef + (void) removeData(); + } + + // Remove the constness and return + return const_cast<void *>(l_pData); +} + +//****************************************************************************** +// setData function +//****************************************************************************** +void ReturnCode::setData(const void * i_pData) +{ + // Remove interest in pointed to ReturnCodeDataRef + (void) removeData(); + + // Create new ReturnCodeDataRef which points to the data + iv_pDataRef = new ReturnCodeDataRef(i_pData); +} + +//****************************************************************************** +// getCreator function +//****************************************************************************** +ReturnCode::returnCodeCreator ReturnCode::getCreator() const +{ + returnCodeCreator l_creator = CREATOR_HWP; + + if ((iv_rcValue & FAPI_RC_FAPI_MASK) || (iv_rcValue & FAPI_RC_ECMD_MASK)) + { + l_creator = CREATOR_FAPI; + } + else if (iv_rcValue & FAPI_RC_PLAT_MASK) + { + l_creator = CREATOR_PLAT; + } + + return l_creator; +} + +//****************************************************************************** +// removeData function +//****************************************************************************** +void ReturnCode::removeData() +{ + if (iv_pDataRef) + { + // Decrement the ReturnCodeDataRef refcount + if (iv_pDataRef->decRefCountCheckZero()) + { + // Refcount decremented to zero. No other ReturnCode points to the + // ReturnCodeDataRef object, delete it + delete iv_pDataRef; + } + iv_pDataRef = NULL; + } +} + +} diff --git a/src/usr/hwpf/fapi/fapiReturnCodeDataRef.C b/src/usr/hwpf/fapi/fapiReturnCodeDataRef.C new file mode 100644 index 000000000..910d1653e --- /dev/null +++ b/src/usr/hwpf/fapi/fapiReturnCodeDataRef.C @@ -0,0 +1,85 @@ +/** + * @file fapiReturnCodeDataRef.C + * + * @brief Implements the FAPI part of the ReturnCodeDataRef class. + */ + +#include <fapiReturnCodeDataRef.H> +#include <fapiUtil.H> + +namespace fapi +{ + +//****************************************************************************** +// Constructor +//****************************************************************************** +ReturnCodeDataRef::ReturnCodeDataRef(const void * i_pData) : + iv_refCount(1), iv_pData(i_pData) +{ + +} + +//****************************************************************************** +// Destructor +//****************************************************************************** +ReturnCodeDataRef::~ReturnCodeDataRef() +{ + if (iv_refCount != 0) + { + FAPI_ERR("ReturnCodeDataRef. Bug. Destruct with refcount"); + fapiAssert(false); + } + else + { + // Call platform implemented deleteData + (void) deleteData(); + } +} + +//****************************************************************************** +// incRefCount function +//****************************************************************************** +void ReturnCodeDataRef::incRefCount() +{ + FAPI_DBG("ReturnCodeDataRef::incRefCount: iv_refCount = %i on entry", iv_refCount); + iv_refCount++; +} + +//****************************************************************************** +// decRefCountCheckZero function +//****************************************************************************** +bool ReturnCodeDataRef::decRefCountCheckZero() +{ + FAPI_DBG("ReturnCodeDataRef::decRefCountCheckZero: iv_refCount = %i on entry", iv_refCount); + + if (iv_refCount == 0) + { + FAPI_ERR("ReturnCodeDataRef. Bug. Dec with zero refcount"); + fapiAssert(false); + } + else + { + iv_refCount--; + } + return (iv_refCount == 0); +} + +//****************************************************************************** +// getData function +//****************************************************************************** +const void * ReturnCodeDataRef::getData() const +{ + return iv_pData; +} + +//****************************************************************************** +// releaseData function +//****************************************************************************** +const void * ReturnCodeDataRef::releaseData() +{ + const void * l_pData = iv_pData; + iv_pData = NULL; + return l_pData; +} + +} diff --git a/src/usr/hwpf/fapi/fapiTarget.C b/src/usr/hwpf/fapi/fapiTarget.C new file mode 100644 index 000000000..463a13ed3 --- /dev/null +++ b/src/usr/hwpf/fapi/fapiTarget.C @@ -0,0 +1,118 @@ +/** + * @file fapiTarget.C + * + * @brief Implements the FAPI part of the Target class. + */ + +#include <fapiTarget.H> + +namespace fapi +{ + +//****************************************************************************** +// Default Constructor +//****************************************************************************** +Target::Target() : + iv_type(TARGET_TYPE_NONE), iv_pHandle(NULL) +{ + +} + +//****************************************************************************** +// Constructor. +//****************************************************************************** +Target::Target(const TargetType i_type, + const void * i_pHandle) : + iv_type(i_type), iv_pHandle(i_pHandle) +{ + +} + +//****************************************************************************** +// Copy Constructor +//****************************************************************************** +Target::Target(const Target & i_right) : + iv_type(i_right.iv_type) +{ + (void) copyHandle(i_right); +} + +//****************************************************************************** +// Destructor +//****************************************************************************** +Target::~Target() +{ + (void) deleteHandle(); +} + +//****************************************************************************** +// Assignment Operator +//****************************************************************************** +Target & Target::operator=(const Target & i_right) +{ + // Test for self assignment + if (this != &i_right) + { + iv_type = i_right.iv_type; + (void) copyHandle(i_right); + } + return *this; +} + +//****************************************************************************** +// Equality Comparison Operator +//****************************************************************************** +bool Target::operator==(const Target & i_right) const +{ + bool l_equal = false; + + if (iv_type == i_right.iv_type) + { + l_equal = compareHandle(i_right); + } + + return l_equal; +} + +//****************************************************************************** +// Inequality Comparison Operator +//****************************************************************************** +bool Target::operator!=(const Target & i_right) const +{ + // Determine inequality by calling the equality comparison operator + return (!(*this == i_right)); +} + +//****************************************************************************** +// Get the handle. +//****************************************************************************** +void * Target::get() const +{ + return const_cast<void *>(iv_pHandle); +} + +//****************************************************************************** +// Set the handle. +//****************************************************************************** +void Target::set(const void * i_pHandle) +{ + iv_pHandle = i_pHandle; +} + +//****************************************************************************** +// Get the target type +//****************************************************************************** +TargetType Target::getType() const +{ + return iv_type; +} + +//****************************************************************************** +// Set the target type +//****************************************************************************** +void Target::setType(const TargetType i_type) +{ + iv_type = i_type; +} + +} diff --git a/src/usr/hwpf/fapi/makefile b/src/usr/hwpf/fapi/makefile new file mode 100644 index 000000000..59df28b20 --- /dev/null +++ b/src/usr/hwpf/fapi/makefile @@ -0,0 +1,13 @@ +ROOTPATH = ../../../.. +MODULE = fapi + +EXTRAINCDIR += ${ROOTPATH}/src/include/usr/ecmddatabuffer +EXTRAINCDIR += ${ROOTPATH}/src/include/usr/hwpf/fapi +EXTRAINCDIR += ${ROOTPATH}/src/include/usr/hwpf/plat + +OBJS = fapiAttributeService.o \ + fapiReturnCode.o \ + fapiReturnCodeDataRef.o \ + fapiTarget.o + +include ${ROOTPATH}/config.mk |