OpenZWave Library: Utils.h Source File

| OpenZWave Library 1.6.0

Loading...
Searching...
No Matches
Utils.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2//
3// Utils.h
4//
5// Miscellaneous helper functions
6//
7// Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
8//
9// SOFTWARE NOTICE AND LICENSE
10//
11// This file is part of OpenZWave.
12//
13// OpenZWave is free software: you can redistribute it and/or modify
14// it under the terms of the GNU Lesser General Public License as published
15// by the Free Software Foundation, either version 3 of the License,
16// or (at your option) any later version.
17//
18// OpenZWave is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU Lesser General Public License for more details.
22//
23// You should have received a copy of the GNU Lesser General Public License
24// along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
25//
26//-----------------------------------------------------------------------------
27
28#ifndef _Utils_H
29#define _Utils_H
30
31#include "platform/Mutex.h"
32#include "platform/Log.h"
33
34#include <string>
35#include <locale>
36#include <algorithm>
37#include <sstream>
38#include <vector>
39
40namespace OpenZWave
41{
48 string ToUpper( string const& _str );
49
56 string ToLower( string const& _str );
57
65 void split (std::vector<std::string>& lst, const std::string& input, const std::string& separators, bool remove_empty = true);
66
72 std::string &trim ( std::string &s );
73
74
75 void PrintHex(std::string prefix, uint8_t const *data, uint32 const length);
76 string PktToString(uint8 const *data, uint32 const length);
77
78 struct LockGuard
79 {
80 LockGuard(Mutex* mutex) : _ref(mutex)
81 {
82 //std::cout << "Locking" << std::endl;
83 _ref->Lock();
84 };
85
86 ~LockGuard()
87 {
88#if 0
89 if (_ref->IsSignalled())
90 std::cout << "Already Unlocked" << std::endl;
91 else
92 std::cout << "Unlocking" << std::endl;
93#endif
94 if (!_ref->IsSignalled())
95 _ref->Unlock();
96 }
97 void Unlock()
98 {
99// std::cout << "Unlocking" << std::endl;
100 _ref->Unlock();
101 }
102 private:
103 LockGuard(const LockGuard&);
104 LockGuard& operator = ( LockGuard const& );
105
106
107 Mutex* _ref;
108 };
109
110 string ozwdirname(string);
111
112 string intToString( int x );
113
114 const char* rssi_to_string(uint8 _data);
115#if (defined _WINDOWS || defined WIN32 || defined _MSC_VER) && (!defined MINGW && !defined __MINGW32__ && !defined __MINGW64__)
116#include <ctime>
117 struct tm *localtime_r(time_t *_clock, struct tm *_result);
118#endif
119
120
121} // namespace OpenZWave
122
123#endif
124
125
126
uint32
unsigned int uint32
Definition Defs.h:95
uint8
unsigned char uint8
Definition Defs.h:89
Log.h
Mutex.h
OpenZWave::Mutex
Implements a platform-independent mutex–for serializing access to a shared resource.
Definition Mutex.h:41
OpenZWave::Mutex::IsSignalled
virtual bool IsSignalled()
Definition Mutex.cpp:98
OpenZWave::Mutex::Lock
bool Lock(bool const _bWait=true)
Definition Mutex.cpp:69
OpenZWave::Mutex::Unlock
void Unlock()
Definition Mutex.cpp:81
OpenZWave
Definition Bitfield.h:35
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::PrintHex
void PrintHex(std::string prefix, uint8_t const *data, uint32 const length)
Definition Utils.cpp:118
OpenZWave::intToString
string intToString(int x)
Definition Utils.cpp:158
OpenZWave::rssi_to_string
const char * rssi_to_string(uint8 _data)
Definition Utils.cpp:166
OpenZWave::ToUpper
string ToUpper(string const &_str)
Definition Utils.cpp:39
OpenZWave::trim
std::string & trim(std::string &s)
Definition Utils.cpp:68
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
OpenZWave::ozwdirname
string ozwdirname(string)
Definition Utils.cpp:148
OpenZWave::LockGuard
Definition Utils.h:79
OpenZWave::LockGuard::Unlock
void Unlock()
Definition Utils.h:97
OpenZWave::LockGuard::LockGuard
LockGuard(Mutex *mutex)
Definition Utils.h:80
OpenZWave::LockGuard::~LockGuard
~LockGuard()
Definition Utils.h:86