aboutsummaryrefslogtreecommitdiff
path: root/include/wesh.hpp
blob: 065088e1c8f1ac2d0a6ad2e53dcc40c19737a410 (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* ****************************************************************************
 * wesh.hpp -- bibliothèque d'interaction avec le WES Handling Daemon.
 * Copyright (C) 2018 Thomas Touhey <thomas@touhey.fr>
 *
 * This project is governed by the CeCILL license under French law and
 * abiding by the rules of distribution of free software. You can use,
 * modify and/or redistribute the software under the terms of the
 * CeCILL license as circulated by CEA, CNRS and INRIA at the
 * following URL: "http://www.cecill.info".
 *
 * As a counterpart to the access to the source code and rights to copy,
 * modify and redistribute granted by the license, users are provided only
 * with a limited warranty and the project's author, the holder of the
 * economic rights, and the successive licensors have only limited liability.
 *
 * In this respect, the user's attention is drawn to the risks associated
 * with loading, using, modifying and/or developing or reproducing the
 * software by the user in light of its specific status of free software,
 * that may mean that it is complicated to manipulate, and that also therefore
 * means that it is reserved for developers and experienced professionals
 * having in-depth computer knowledge. Users are therefore encouraged to load
 * and test the software's suitability as regards their requirements in
 * conditions enabling the security of their systems and/or data to be
 * ensured and, more generally, to use and operate it in the same conditions
 * as regards security.
 *
 * The fact that you are presently reading this means that you have had
 * knowledge of the CeCILL license and that you accept its terms.
 * ************************************************************************* */
#ifndef  WESH_HPP
# define WESH_HPP 20180311
# include <stdexcept>
# include <ostream>
# include <string>
# include <ctime>
# define BEGIN_NAMESPACE_WESH namespace wesh {
# define   END_NAMESPACE_WESH }

BEGIN_NAMESPACE_WESH

class electricity_meter;
class wes;

/* ---
 * Définition des exceptions utilisables par la classe WES.
 * --- */

/* La différence entre `already_created_exception` et
 * `already_exists_exception` est la suivante :
 * - `already_created_exception`: l'objet a déjà été initialisé avec un
 *   identifiant valide, il faut donc créer une autre instance de `wes`
 *   pour pouvoir créer un objet.
 * - `already_exists_exception`: un objet correspondant aux données
 *   d'entrées existe déjà du côté du démon. */

#if __cplusplus >= 201103L
# define WESH_NOEXCEPT noexcept
#else
# define WESH_NOEXCEPT throw()
#endif

#define WESH_EXC(NAME, MSG) \
class NAME: public std::exception { \
	virtual const char *what() const WESH_NOEXCEPT { \
		return MSG; \
	} \
};

WESH_EXC(connexion_exception, "La connexion au démon a échoué.")
WESH_EXC(daemon_exception, "Le démon a connu une erreur interne.")
WESH_EXC(not_implemented_exception,
	"L'appel correspondant n'est pas implémenté.")
WESH_EXC(not_loaded_exception, "Cet objet n'a pas été chargé.")
WESH_EXC(already_created_exception, "Cet objet a déjà été créé !")
WESH_EXC(no_exists_exception,
	"Il n'y a pas de serveur WES avec cet identifiant.")
WESH_EXC(unavailable_exception, "Le serveur WES est injoignable.")

/* ---
 * Définition de la classe correspondant à un compteur électrique
 * branché en TÉLÉINFO.
 * --- */

enum electricity_meter_mode {
	emm_conso = 0, /* Consommation */
	emm_prod  = 1  /* Production */
};

enum electricity_meter_subscription_type {
	emst_base  = 0, /* BASE (toutes heures) */
	emst_hchp  = 1, /* Heures Creuses, Heures Pleines */
	emst_ejp   = 2, /* Effacement de Jours de Pointes */
	emst_tempo = 3  /* Temporaires (jours bleus, blancs, rouges + hchp) */
};

enum electricity_meter_subscription_period {
	emsp_hn   =  0, /* Heures Normales/Toutes les Heures */
	emsp_hc   =  1, /* Heures Creuses (HCHP) */
	emsp_hp   =  2, /* Heures Pleines (HCHP) */
	emsp_pm   =  3, /* Heures de Pointe Mobile (EJP) */

	emsp_hcjb =  1, /* Heures Creuses Jours Bleus */
	emsp_hpjb =  2, /* Heures Pleines Jours Bleus */
	emsp_hcjw =  5, /* Heures Creuses Jours Blancs */
	emsp_hpjw =  6, /* Heures Pleines Jours Blancs */
	emsp_hcjr =  9, /* Heures Creuses Jours Rouges */
	emsp_hpjr = 10  /* Heures Pleines Jours Rouges */
};

struct electricity_meter_subscription {
	electricity_meter_subscription_type type;
	electricity_meter_subscription_period period;
};

enum electricity_meter_phase_mode {
	empm_none = 0, /* aucune phase */
	empm_mono = 1, /* monophasé */
	empm_tri  = 3  /* triphasé */
};

class electricity_meter {
private:
	wes *parent;
	int num;

public:
	electricity_meter(void);
	electricity_meter(wes *parent, int num);

	void gather(wes *parent, int num);
	void gather(void);

	void update(void);

	/* Configuration. */

	bool is_read;
	std::string name;
	electricity_meter_mode mode;

	/* Données. */

	electricity_meter_subscription subscription;
	electricity_meter_phase_mode phase_mode;
};

/* ---
 * Définition de la classe WES.
 * --- */

class wes {
private:
	int id;
	void *client;

public:
	wes(void);
	wes(int id);
	~wes(void);

	/* Créer et supprimer un serveur WES de la liste de gestion du démon. */

	void gather(const unsigned char ip[4]);
	void gather(const unsigned char ip[4],
		std::string username, std::string password);
	void gather(const unsigned char ip[4],
		std::string http_username, std::string http_password,
		std::string ftp_username, std::string ftp_password);
	void remove(void);

	/* Récupérer l'heure. */

	struct tm get_date(void);
	electricity_meter get_electricity_meter(int id);

	/* Destiné aux classes ayant ce serveur comme référent. */

	void *get_clnt(void);
	int get_id(void);
};

END_NAMESPACE_WESH

/* Quelques utilitaires hors du namespace pour afficher ce qu'il faut
 * de façon relativement agréable. */

extern std::ostream& operator<<(std::ostream& os,
	wesh::electricity_meter_mode md);
extern std::ostream& operator<<(std::ostream& os,
	wesh::electricity_meter_subscription_type st);
extern std::ostream& operator<<(std::ostream& os,
	wesh::electricity_meter_subscription sb);
extern std::ostream& operator<<(std::ostream& os,
	wesh::electricity_meter_subscription_period pd);
extern std::ostream& operator<<(std::ostream& os,
	wesh::electricity_meter_phase_mode pm);

#endif /* WESH_HPP */