Utils.h
Go to the documentation of this file.
//-----------------------------------------------------------------------------
//
// Utils.h
//
// Miscellaneous helper functions
//
// Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
//
// SOFTWARE NOTICE AND LICENSE
//
// This file is part of OpenZWave.
//
// OpenZWave is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// OpenZWave is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
#ifndef _Utils_H
#define _Utils_H
#include "platform/Mutex.h"
#include "platform/Log.h"
#include <string>
#include <locale>
#include <algorithm>
#include <sstream>
#include <vector>
namespace OpenZWave
{
string ToUpper( string const& _str );
string ToLower( string const& _str );
void split (std::vector<std::string>& lst, const std::string& input, const std::string& separators, bool remove_empty = true);
std::string &trim ( std::string &s );
void PrintHex(std::string prefix, uint8_t const *data, uint32 const length);
string PktToString(uint8 const *data, uint32 const length);
struct LockGuard
{
LockGuard(Mutex* mutex) : _ref(mutex)
{
//std::cout << "Locking" << std::endl;
_ref->Lock();
};
~LockGuard()
{
#if 0
if (_ref->IsSignalled())
std::cout << "Already Unlocked" << std::endl;
else
std::cout << "Unlocking" << std::endl;
#endif
if (!_ref->IsSignalled())
_ref->Unlock();
}
void Unlock()
{
// std::cout << "Unlocking" << std::endl;
_ref->Unlock();
}
private:
LockGuard(const LockGuard&);
LockGuard& operator = ( LockGuard const& );
Mutex* _ref;
};
} // namespace OpenZWave
#endif
OpenZWave::LockGuard::Unlock
void Unlock()
Definition: Utils.h:97
OpenZWave
Definition: Bitfield.h:34
OpenZWave::Mutex::Unlock
void Unlock()
Definition: Mutex.cpp:81
s
#define s(x, c)
Definition: aesopt.h:483
OpenZWave::LockGuard
Definition: Utils.h:78
OpenZWave::Mutex::Lock
bool Lock(bool const _bWait=true)
Definition: Mutex.cpp:69
Log.h
OpenZWave::PktToString
string PktToString(uint8 const *data, uint32 const length)
Definition: Utils.cpp:122
OpenZWave::ToLower
string ToLower(string const &_str)
Definition: Utils.cpp:53
uint32
unsigned int uint32
Definition: Defs.h:80
OpenZWave::PrintHex
void PrintHex(std::string prefix, uint8_t const *data, uint32 const length)
Definition: Utils.cpp:118
Mutex.h
OpenZWave::LockGuard::LockGuard
LockGuard(Mutex *mutex)
Definition: Utils.h:80
OpenZWave::split
void split(std::vector< std::string > &lst, const std::string &input, const std::string &separators, bool remove_empty=true)
Definition: Utils.cpp:95
OpenZWave::trim
std::string & trim(std::string &s)
Definition: Utils.cpp:68
OpenZWave::LockGuard::~LockGuard
~LockGuard()
Definition: Utils.h:86
OpenZWave::ToUpper
string ToUpper(string const &_str)
Definition: Utils.cpp:39
OpenZWave::Mutex
Implements a platform-independent mutex–for serializing access to a shared resource.
Definition: Mutex.h:39
OpenZWave::Mutex::IsSignalled
virtual bool IsSignalled()
Definition: Mutex.cpp:98
uint8
unsigned char uint8
Definition: Defs.h:74