-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppConfigManager.h
100 lines (76 loc) · 2.51 KB
/
AppConfigManager.h
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
/*
* AppConfigManager.h
* PyRideServer
*
* Created by Xun Wang on 17/08/12.
* Copyright 2012 Galaxy Network. All rights reserved.
*
*/
#ifndef APP_CONFIG_MANAGER_H
#define APP_CONFIG_MANAGER_H
#include <openssl/sha.h>
#ifndef OLD_NAO
#include <tinyxml.h>
#else
#include <tinyxml/tinyxml.h>
#endif
#include <sys/types.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <string>
#include <vector>
#include <map>
#include <PyRideCommon.h>
#include <DeviceController.h>
#ifdef ROS_BUILD
#define DEFAULT_CONFIGURATION_FILE "pyrideconfig.xml"
#else
#define DEFAULT_CONFIGURATION_FILE "/home/nao/naoqi/preferences/pyrideconfig.xml"
#endif
namespace pyride {
typedef struct {
std::string name;
unsigned char password[SHA256_DIGEST_LENGTH];
SOCKET_T clientFD;
struct sockaddr_in clientAddr;
} UserData;
class AppConfigManager
{
public:
static AppConfigManager * instance();
void loadConfigFromFile( const char * fileName );
void saveConfig();
bool signInUserWithPassword( const unsigned char * code, SOCKET_T fd, struct sockaddr_in & addr, std::string & username );
bool signOutUser( SOCKET_T fd, std::string & username );
bool findUser( SOCKET_T fd, std::string & username );
bool addUser( const char * name, const char * password );
bool delUser( const char * name );
bool changeUserPassword( const char * name, const char * oldpassword, const char * newpassword );
bool getOnlineUserClientFD( const char * name, SOCKET_T & fd );
int listCurrentUsers( std::vector<std::string> & userNameList );
int listAllUsers( std::vector<std::string> & userNameList );
const DeviceInfoList * deviceInfoList() const { return &deviceInfoList_; }
void fini();
char clientID() { return clientID_; }
bool enablePythonConsole() { return allowPythonTelnet_; }
const RobotPose & startPosition() { return defaultPose_; }
private:
typedef std::vector< UserData *> UserDataList;
typedef std::map< SOCKET_T, UserData *> SignedInMap;
SignedInMap signedInMap_;
UserDataList userDataList_;
DeviceInfoList deviceInfoList_;
char clientID_;
bool allowPythonTelnet_;
RobotPose defaultPose_;
std::string configFileName_;
static AppConfigManager * s_instance;
AppConfigManager();
void loadUserInfo( TiXmlNode * userInfoNode );
void loadRobotInfo( TiXmlNode * robotInfoNode );
void loadDeviceInfo( TiXmlNode * devInfoNode );
UserData * parseUserRecord( TiXmlNode * userNode );
DeviceInfo * parseDeviceRecord( TiXmlNode * deviceNode );
};
} // namespace pyride
#endif // APP_CONFIG_MANAGER_H