File: misc.h

package info (click to toggle)
pgagent 4.2.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 476 kB
  • sloc: cpp: 1,913; sql: 1,739; xml: 100; ansic: 58; makefile: 31; sh: 18
file content (64 lines) | stat: -rw-r--r-- 1,539 bytes parent folder | download | duplicates (2)
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
//////////////////////////////////////////////////////////////////////////
//
// pgAgent - PostgreSQL Tools
//
// Copyright (C) 2002 - 2024, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// misc.h - misc functions
//
//////////////////////////////////////////////////////////////////////////


#ifndef MISC_H
#define MISC_H

void          WaitAWhile(const bool waitLong = false);
void          setOptions(int argc, char **argv, const std::string &executable);
std::string   getArg(int &argc, char **&argv);
std::string   NumToStr(const long l);
void          printVersion();
#if BOOST_OS_WINDOWS
std::wstring  s2ws(const std::string &str);
std::string   ws2s(const std::wstring &wstr);
#endif
std::string   generateRandomString(size_t length);
bool          createUniqueTemporaryDirectory(const std::string &prefix, boost::filesystem::path &tempDir);

class MutexLocker
{
public:
	MutexLocker(boost::mutex *lock): m_lock(lock)
	{
		if (m_lock != NULL)
			m_lock->lock();
	}

	~MutexLocker()
	{
		if (m_lock != NULL)
			m_lock->unlock();
		m_lock = NULL;
	}

	// When the exit(code) is being called, static object is being released
	// earlier. Hence - it is a good idea to set the current mutex object to
	// NULL to avoid ASSERTION in debug mode (specifically on OSX).
	MutexLocker& operator =(boost::mutex *lock)
	{
		if (m_lock != NULL)
			m_lock->unlock();
		m_lock = lock;

		if (m_lock != NULL)
			m_lock->lock();

		return *this;
	}

private:
	boost::mutex *m_lock;
};

#endif // MISC_H