libqi-api  2.1.4.13
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
os.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3  * Copyright (c) 2012, 2013 Aldebaran Robotics. All rights reserved.
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the COPYING file.
6  */
7 
8 #ifndef _QI_OS_HPP_
9 #define _QI_OS_HPP_
10 
11 # include <cstdio>
12 # include <string>
13 # include <map>
14 # include <vector>
15 # include <qi/api.hpp>
16 # include <qi/types.hpp>
17 
18 struct stat;
19 
20 namespace qi {
21 
22  namespace os {
23 
24  QI_API FILE* fopen(const char *filename, const char *mode);
25  QI_API int stat(const char *filename, struct stat *pstat);
26  QI_API int checkdbg();
27  QI_API std::string home();
28  QI_API std::string mktmpdir(const char *prefix = "");
29  QI_API std::string tmp();
30  QI_API std::string gethostname();
31  QI_API int isatty(int fd = 1);
32 
36  QI_API bool fnmatch(const std::string &pattern, const std::string &string);
37 
38  // lib C
39  QI_API char* strdup(const char *src);
40  QI_API int snprintf(char *str, size_t size, const char *format, ...);
41 
42  // env
43  QI_API std::string getenv(const char *var);
44  QI_API int setenv(const char *var, const char *value);
45  QI_API std::string timezone();
46 
47  // time
48  QI_API void sleep(unsigned int seconds);
49  QI_API void msleep(unsigned int milliseconds);
50  struct QI_API timeval {
53  };
56  QI_API std::pair<int64_t, int64_t> cputime();
57 
59  const qi::os::timeval &rhs);
61  long us);
63  const qi::os::timeval &rhs);
65  long us);
66 
67  // shared library
68  QI_API void *dlopen(const char *filename, int flag = -1);
69  QI_API int dlclose(void *handle);
70  QI_API void *dlsym(void *handle, const char *symbol);
71  QI_API const char *dlerror(void);
72 
73  // process management
74  QI_API int spawnvp(char *const argv[]);
75  QI_API int spawnlp(const char* argv, ...);
76  QI_API int system(const char *command);
77  QI_API int getpid();
78  QI_API int gettid();
79  QI_API int waitpid(int pid, int* status);
80  QI_API int kill(int pid, int sig);
81 
82  QI_API unsigned short findAvailablePort(unsigned short port);
83  QI_API std::map<std::string, std::vector<std::string> > hostIPAddrs(bool ipv6Addr = false);
84 
85  QI_API void setCurrentThreadName(const std::string &name);
86  QI_API std::string currentThreadName();
87  QI_API bool setCurrentThreadCPUAffinity(const std::vector<int> &cpus);
88  QI_API long numberOfCPUs();
89  QI_API std::string getMachineId();
90  QI_API std::string generateUuid();
91  // in kB
92  QI_API size_t memoryUsage(unsigned int pid);
93 
94  //since 1.12.1
95  QI_API_DEPRECATED QI_API std::string tmpdir(const char *prefix = "");
96  }
97 }
98 
99 
100 #endif // _QI_OS_HPP_
int getpid()
Get the process identifier.
qi::int64_t tv_usec
Definition: os.hpp:52
qi::os::timeval operator+(const qi::os::timeval &lhs, const qi::os::timeval &rhs)
int gettimeofday(qi::os::timeval *tp)
The gettimeofday() function shall obtain the current time.
int checkdbg()
QI_API_DEPRECATED const char ** argv()
Deprecated, see detailed description.
QI_API_DEPRECATED std::string tmpdir(const char *prefix="")
std::string timezone()
std::string currentThreadName()
bool fnmatch(const std::string &pattern, const std::string &string)
const char * dlerror(void)
Returns a human readable string of the error code.
unsigned short findAvailablePort(unsigned short port)
Find the first available port starting at port number in parameter.
std::string gethostname()
Get the system's hostname.
std::pair< int64_t, int64_t > cputime()
long numberOfCPUs()
int system(const char *command)
int64_t int64_t
Cross-platform signed integer of length 64 bits (8 bytes).
Definition: types.hpp:33
int kill(int pid, int sig)
Send a signal to a process.
void setCurrentThreadName(const std::string &name)
Set the current thread name to the string in parameter.
FILE * fopen(const char *filename, const char *mode)
Open a file and returns and handle on it.
void msleep(unsigned int milliseconds)
Sleep for the specified number of milliseconds.
int stat(const char *filename, struct stat *pstat)
std::string getMachineId()
Returns an unique uuid for the machine.
qi::int64_t tv_sec
Definition: os.hpp:51
int snprintf(char *str, size_t size, const char *format,...)
char * strdup(const char *src)
#define QI_API_DEPRECATED
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
Definition: macro.hpp:25
std::string mktmpdir(const char *prefix="")
Return a writable temporary directory.
std::string generateUuid()
int spawnvp(char *const argv[])
size_t memoryUsage(unsigned int pid)
std::map< std::string, std::vector< std::string > > hostIPAddrs(bool ipv6Addr=false)
Find all network adapters and corresponding IPs.
bool setCurrentThreadCPUAffinity(const std::vector< int > &cpus)
void sleep(unsigned int seconds)
void * dlsym(void *handle, const char *symbol)
Get the address where the symbol is loaded into memory.
dll import/export and compiler message
int spawnlp(const char *argv,...)
qi::os::timeval operator-(const qi::os::timeval &lhs, const qi::os::timeval &rhs)
int waitpid(int pid, int *status)
int setenv(const char *var, const char *value)
std::string home()
Return path to the current user's HOME.
int dlclose(void *handle)
Decrements the reference count on the dynamic library.
int isatty(int fd=1)
#define QI_API
Definition: api.hpp:24
void * dlopen(const char *filename, int flag=-1)
Load a dynamic library.
std::string getenv(const char *var)
Get an environment variable.
int gettid()
Get the thread identifier.
qi::int64_t ustime()
std::string tmp()