1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/* -*- c++ -*-
*
* (C) Copyright Pigeon Point Systems. 2011
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTUTILSLITY or FITNESS FOR A PARTICULAR PURPOSE. This
* file and program are licensed under a BSD style license. See
* the Copying file included with the OpenHPI distribution for
* full licensing terms.
*
* Author(s):
* Anton Pak <anton.pak@pigeonpoint.com>
*/
#ifndef UTILS_H_FB2B5DD5_4E7D_49F5_9397_C2FEC21B4010
#define UTILS_H_FB2B5DD5_4E7D_49F5_9397_C2FEC21B4010
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <SaHpi.h>
namespace TA {
/**************************************************************
* uint16_t <-> uint8_t
*************************************************************/
inline uint16_t MakeUint16T( uint8_t high, uint8_t low )
{
return ( ( (uint16_t)high ) << 8 ) | ( (uint16_t)low );
}
inline uint8_t GetHighByte( uint16_t x ) {
return (uint8_t)( x >> 8 );
}
inline uint8_t GetLowByte( uint16_t x ) {
return (uint8_t)( x & 0xFFU );
}
/**************************************************************
* Cast Templates
*************************************************************/
template <typename T>
static inline const T * ConstPtr( const void * ptr )
{
return reinterpret_cast<const T *>(ptr);
}
template <typename T>
static inline T * Ptr( void * ptr )
{
return reinterpret_cast<T *>(ptr);
}
template <typename T>
static inline const T& ConstRef( const void * ptr )
{
return *ConstPtr<T>( ptr );
}
template <typename T>
static inline T& Ref( void * ptr )
{
return *Ptr<T>( ptr );
}
/**************************************************************
* cLocker: class for for locking object while in scope
*************************************************************/
template <class T>
class cLocker
{
public:
explicit cLocker( T * t )
: m_t( t )
{
m_t->Lock();
}
~cLocker()
{
m_t->Unlock();
}
private:
cLocker( const cLocker& );
cLocker& operator =( const cLocker& );
private: // data
T * m_t;
};
/**************************************************************
* Entity Path Helpers
*************************************************************/
void MakeUnspecifiedHpiEntityPath( SaHpiEntityPathT& ep );
/**************************************************************
* Text Buffer Helpers
*************************************************************/
void MakeHpiTextBuffer( SaHpiTextBufferT& tb, const char * s );
void MakeHpiTextBuffer( SaHpiTextBufferT& tb, const char * s, size_t size );
void MakeHpiTextBuffer( SaHpiTextBufferT& tb, char c, size_t size );
void FormatHpiTextBuffer( SaHpiTextBufferT& tb, const char * fmt, ... );
void vFormatHpiTextBuffer( SaHpiTextBufferT& tb, const char * fmt, va_list ap );
void AppendToTextBuffer( SaHpiTextBufferT& tb, const SaHpiTextBufferT& appendix );
}; // namespace TA
#endif // UTILS_H_FB2B5DD5_4E7D_49F5_9397_C2FEC21B4010
|