aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-04-07 00:13:21 +0200
committerThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-04-07 00:13:21 +0200
commitf43fd8b7265ca1e00b6f72f31e6ea498a21c7d80 (patch)
treea93e133647fc7d15a600986be21c404b9b3fe3cf
parent18c64b5d71ce4570a42a02be1aa31fa98bf23437 (diff)
Ajouté de quoi faire quelques diagrammes de classe des familles.
-rw-r--r--client/main.cpp20
-rw-r--r--daemon/server.c12
-rw-r--r--include/wesh.hpp68
-rw-r--r--lib/dummy_wes.cpp50
-rw-r--r--lib/electricity_meter.cpp4
-rw-r--r--lib/internals.hpp10
-rw-r--r--lib/wes.cpp165
-rw-r--r--lib/wes_base.cpp160
-rw-r--r--weshd.x40
9 files changed, 338 insertions, 191 deletions
diff --git a/client/main.cpp b/client/main.cpp
index 9a1eccf..87e1182 100644
--- a/client/main.cpp
+++ b/client/main.cpp
@@ -40,12 +40,9 @@ static void display_electricity_meter(int id, wesh::electricity_meter& em)
<< std::endl;
}
-static void tests(void)
+static void testwes(wesh::wes_base& wes)
{
- const unsigned char ip[4] = {192, 168, 1, 111};
- wesh::wes wes; struct tm dt;
-
- wes.gather(ip);
+ struct tm dt;
dt = wes.get_date();
std::cout << std::endl
@@ -64,8 +61,19 @@ static void tests(void)
em.gather(&wes, 1);
display_electricity_meter(1, em);
}
+}
+
+static void tests(void)
+{
+ const unsigned char ip[4] = {192, 168, 1, 111};
+ wesh::dummy_wes dummy_wes;
+ wesh::wes real_wes;
+
+ dummy_wes.gather();
+ testwes(dummy_wes);
- wes.remove();
+ real_wes.gather(ip);
+ testwes(real_wes);
}
int main(void)
diff --git a/daemon/server.c b/daemon/server.c
index f89f238..c6078c9 100644
--- a/daemon/server.c
+++ b/daemon/server.c
@@ -288,6 +288,10 @@ wespret_with_datetime_t *get_date_time_1_svc(wespid_t *id, struct svc_req *req)
case WROK:
break;
+ case WRNOHOST:
+ resp.ret = WESPRET_CON;
+ return (&resp);
+
default:
resp.ret = WESPRET_INT;
return (&resp);
@@ -354,6 +358,10 @@ wespret_with_net_t *get_network_1_svc(wespid_t *id, struct svc_req *req)
case WROK:
break;
+ case WRNOHOST:
+ resp.ret = WESPRET_CON;
+ return (&resp);
+
default:
msg((wlerror, "if error occurred: %s", error_string(err)));
resp.ret = WESPRET_INT;
@@ -422,6 +430,10 @@ wespret_with_tic_t *get_tic_1_svc(wespid_with_tic_id_t *args,
case WROK:
break;
+ case WRNOHOST:
+ resp.ret = WESPRET_CON;
+ return (&resp);
+
default:
msg((wlerror, "tic error: %s", error_string(err)));
return (&resp);
diff --git a/include/wesh.hpp b/include/wesh.hpp
index 065088e..316aa2b 100644
--- a/include/wesh.hpp
+++ b/include/wesh.hpp
@@ -39,7 +39,7 @@
BEGIN_NAMESPACE_WESH
class electricity_meter;
-class wes;
+class wes_base;
/* ---
* Définition des exceptions utilisables par la classe WES.
@@ -120,14 +120,14 @@ enum electricity_meter_phase_mode {
class electricity_meter {
private:
- wes *parent;
+ wes_base *parent;
int num;
public:
electricity_meter(void);
- electricity_meter(wes *parent, int num);
+ electricity_meter(wes_base *parent, int num);
- void gather(wes *parent, int num);
+ void gather(wes_base *parent, int num);
void gather(void);
void update(void);
@@ -145,27 +145,34 @@ public:
};
/* ---
- * Définition de la classe WES.
+ * Définition des classes WES.
* --- */
-class wes {
-private:
+# ifndef WESH_CLIENT_TYPE
+# define WESH_CLIENT_TYPE void
+# endif
+# ifndef WESH_GATHER_TYPE
+# define WESH_GATHER_TYPE void
+# endif
+
+/* Classe de base, pour toutes les interfaces derrière. */
+
+class wes_base {
+protected:
int id;
- void *client;
+ WESH_CLIENT_TYPE *client;
+
+ /* Récupération de la ressource, version privée. */
+
+ void gather_(WESH_GATHER_TYPE *args);
public:
- wes(void);
- wes(int id);
- ~wes(void);
+ wes_base(void);
+ wes_base(int id);
+ ~wes_base(void);
- /* Créer et supprimer un serveur WES de la liste de gestion du démon. */
+ /* Gestion de la ressource. */
- 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. */
@@ -175,10 +182,33 @@ public:
/* Destiné aux classes ayant ce serveur comme référent. */
- void *get_clnt(void);
+ WESH_CLIENT_TYPE *get_clnt(void);
int get_id(void);
};
+/* Classe fille pour le serveur WES de base connecté via IP. */
+
+class wes: public wes_base {
+public:
+ /* Récupération du serveur WES. */
+
+ 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);
+};
+
+/* Classe fille pour le serveur WES factice. */
+
+class dummy_wes: public wes_base {
+public:
+ /* Récupération du serveur WES. */
+
+ void gather(void);
+};
+
END_NAMESPACE_WESH
/* Quelques utilitaires hors du namespace pour afficher ce qu'il faut
diff --git a/lib/dummy_wes.cpp b/lib/dummy_wes.cpp
new file mode 100644
index 0000000..d6d7e1c
--- /dev/null
+++ b/lib/dummy_wes.cpp
@@ -0,0 +1,50 @@
+/* ****************************************************************************
+ * dummy_wes.cpp -- méthodes de la classe `dummy_wes`.
+ * 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.
+ * ************************************************************************* */
+#include "internals.hpp"
+
+using namespace wesh;
+
+/* ---
+ * Récupération de la ressource.
+ * --- */
+
+void dummy_wes::gather(void)
+{
+ wespregopts_t args;
+
+ args.type = WESPREGTYPE_DUMMY;
+ args.ip.type = WESPIPTYPE_NONE;
+ args.http_username = "";
+ args.http_password = "";
+ args.ftp_username = "";
+ args.ftp_password = "";
+
+ this->gather_(&args);
+}
diff --git a/lib/electricity_meter.cpp b/lib/electricity_meter.cpp
index eede36d..01f5b76 100644
--- a/lib/electricity_meter.cpp
+++ b/lib/electricity_meter.cpp
@@ -204,7 +204,7 @@ electricity_meter::electricity_meter(void)
this->num = -1;
}
-electricity_meter::electricity_meter(wes *parent_to_use, int num_to_use)
+electricity_meter::electricity_meter(wes_base *parent_to_use, int num_to_use)
{
/* FIXME: Vérifier si les arguments sont valides. */
@@ -330,7 +330,7 @@ void electricity_meter::gather(void)
/* TODO: other values */
}
-void electricity_meter::gather(wes *parent_now, int num_now)
+void electricity_meter::gather(wes_base *parent_now, int num_now)
{
if (this->num >= 0)
throw not_loaded_exception();
diff --git a/lib/internals.hpp b/lib/internals.hpp
index 679ab03..fb6b572 100644
--- a/lib/internals.hpp
+++ b/lib/internals.hpp
@@ -29,9 +29,7 @@
* ************************************************************************* */
#ifndef INTERNALS_HPP
# define INTERNALS_HPP 2018022001
-# include <wesh.hpp>
# include <iostream>
-# define clnt(WES) (static_cast<CLIENT*>((WES)->get_clnt()))
/* Inclusion des mécanismes de RPC. */
@@ -40,6 +38,14 @@ extern "C" {
# undef gather
}
+/* Inclusion du header public, en redéfinissant ce qu'il faut. */
+
+# define WESH_CLIENT_TYPE CLIENT
+# define WESH_GATHER_TYPE wespregopts_t
+
+# include <wesh.hpp>
+# define clnt(WES) ((WES)->get_clnt())
+
/* Utilitaires. */
[[noreturn]] extern void throw_exception_using_ret(wespret_t ret);
diff --git a/lib/wes.cpp b/lib/wes.cpp
index 09819a9..9104d65 100644
--- a/lib/wes.cpp
+++ b/lib/wes.cpp
@@ -32,49 +32,7 @@
using namespace wesh;
/* ---
- * Constructeur, destructeur.
- * --- */
-
-wes::wes(void)
-{
- this->id = 0;
- this->client = nullptr;
-}
-
-wes::wes(int given_id)
-{
- this->id = given_id;
- this->client = nullptr;
-}
-
-wes::~wes(void)
-{
- if (this->client)
- clnt_destroy(static_cast<CLIENT*>(this->client));
-}
-
-/* ---
- * Utilitaires pour les méthodes de cette classe et les objets qui
- * en dépendent.
- * --- */
-
-void *wes::get_clnt(void)
-{
- if (this->client)
- return (this->client);
- this->client = clnt_create("localhost", WESHD_PROG, WESHD_VERS1, "tcp");
- if (!this->client)
- throw connexion_exception();
- return (this->client);
-}
-
-int wes::get_id(void)
-{
- return (this->id);
-}
-
-/* ---
- * Création et suppression de la ressource.
+ * Récupération de la ressource.
* --- */
void wes::gather(const unsigned char ip[4],
@@ -82,44 +40,28 @@ void wes::gather(const unsigned char ip[4],
std::string ftp_username, std::string ftp_password)
{
wespregopts_t args;
- wespret_with_id_t *resp;
- wespret_t ret;
-
- if (this->id != 0)
- throw already_created_exception();
-
- {
- char hu[http_username.length() + 1],
- hp[http_password.length() + 1],
- fu[ftp_username.length() + 1],
- fp[ftp_password.length() + 1];
-
- strcpy(hu, http_username.c_str());
- strcpy(hp, http_password.c_str());
- strcpy(fu, ftp_username.c_str());
- strcpy(fp, ftp_password.c_str());
-
- args.type = WESPREGTYPE_DUMMY /* FIXME: WESPREGTYPE_IP */;
- args.ip.type = WESPIPTYPE_4;
- args.ip.ipv4[0] = ip[0];
- args.ip.ipv4[1] = ip[1];
- args.ip.ipv4[2] = ip[2];
- args.ip.ipv4[3] = ip[3];
- args.http_username = hu;
- args.http_password = hp;
- args.ftp_username = fu;
- args.ftp_password = fp;
-
- resp = gather_1(&args, clnt(this));
- if (!resp)
- throw connexion_exception();
- }
-
- ret = resp->ret;
- if (ret != WESPRET_OK)
- throw_exception_using_ret(ret);
-
- this->id = resp->id;
+ char hu[http_username.length() + 1],
+ hp[http_password.length() + 1],
+ fu[ftp_username.length() + 1],
+ fp[ftp_password.length() + 1];
+
+ strcpy(hu, http_username.c_str());
+ strcpy(hp, http_password.c_str());
+ strcpy(fu, ftp_username.c_str());
+ strcpy(fp, ftp_password.c_str());
+
+ args.type = WESPREGTYPE_IP;
+ args.ip.type = WESPIPTYPE_4;
+ args.ip.ipv4[0] = ip[0];
+ args.ip.ipv4[1] = ip[1];
+ args.ip.ipv4[2] = ip[2];
+ args.ip.ipv4[3] = ip[3];
+ args.http_username = hu;
+ args.http_password = hp;
+ args.ftp_username = fu;
+ args.ftp_password = fp;
+
+ this->gather_(&args);
}
void wes::gather(const unsigned char ip[4],
@@ -132,64 +74,3 @@ void wes::gather(const unsigned char ip[4])
{
this->gather(ip, "admin", "wes", "adminftp", "wesftp");
}
-
-void wes::remove(void)
-{
- wespid_t wid;
- wespret_t ret, *retp;
-
- if (this->id == 0)
- throw not_loaded_exception();
-
- wid = static_cast<wespid_t>(this->id);
- retp = unregister_1(&wid, clnt(this));
- if (!retp)
- throw connexion_exception();
-
- ret = *retp;
- if (ret != WESPRET_OK)
- throw_exception_using_ret(ret);
-
- this->id = 0;
-}
-
-/* ---
- * Récupération d'éléments.
- * --- */
-
-struct tm wes::get_date(void)
-{
- wespid_t wid;
- wespret_with_datetime_t *resp;
- wespdatetime_t *dt;
- struct tm tm;
-
- if (this->id == 0)
- throw not_loaded_exception();
-
- wid = this->id;
- resp = get_date_time_1(&wid, clnt(this));
- if (!resp)
- throw connexion_exception();
-
- if (resp->ret != WESPRET_OK)
- throw_exception_using_ret(resp->ret);
-
- dt = &resp->dt;
- tm.tm_year = dt->year - 1900;
- tm.tm_mon = dt->mon - 1;
- tm.tm_mday = dt->dom;
- tm.tm_hour = dt->hour;
- tm.tm_min = dt->min;
- tm.tm_sec = dt->sec;
-
- mktime(&tm);
- return (tm);
-}
-
-electricity_meter wes::get_electricity_meter(int em_id)
-{
- electricity_meter em(this, em_id);
-
- return (em);
-}
diff --git a/lib/wes_base.cpp b/lib/wes_base.cpp
new file mode 100644
index 0000000..f8550a4
--- /dev/null
+++ b/lib/wes_base.cpp
@@ -0,0 +1,160 @@
+/* ****************************************************************************
+ * wes_base.cpp -- méthodes de la classe `wes_base`.
+ * 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.
+ * ************************************************************************* */
+#include "internals.hpp"
+
+using namespace wesh;
+
+/* ---
+ * Constructeur, destructeur.
+ * --- */
+
+wes_base::wes_base(void)
+{
+ this->id = 0;
+ this->client = nullptr;
+}
+
+wes_base::wes_base(int given_id)
+{
+ this->id = given_id;
+ this->client = nullptr;
+}
+
+wes_base::~wes_base(void)
+{
+ if (this->client)
+ clnt_destroy(static_cast<CLIENT*>(this->client));
+}
+
+/* ---
+ * Utilitaires pour les méthodes de cette classe et les objets qui
+ * en dépendent.
+ * --- */
+
+CLIENT *wes_base::get_clnt(void)
+{
+ if (this->client)
+ return (this->client);
+
+ this->client = clnt_create("localhost", WESHD_PROG, WESHD_VERS1, "tcp");
+ if (!this->client)
+ throw connexion_exception();
+
+ return (this->client);
+}
+
+int wes_base::get_id(void)
+{
+ return (this->id);
+}
+
+/* ---
+ * Récupération et suppression de la ressource.
+ * --- */
+
+void wes_base::gather_(wespregopts_t *args)
+{
+ wespret_with_id_t *resp;
+ wespret_t ret;
+
+ if (this->id != 0)
+ throw already_created_exception();
+
+ resp = gather_1(args, clnt(this));
+ if (!resp)
+ throw connexion_exception();
+
+ ret = resp->ret;
+ if (ret != WESPRET_OK)
+ throw_exception_using_ret(ret);
+
+ this->id = resp->id;
+}
+
+void wes_base::remove(void)
+{
+ wespid_t wid;
+ wespret_t ret, *retp;
+
+ if (this->id == 0)
+ throw not_loaded_exception();
+
+ wid = static_cast<wespid_t>(this->id);
+ retp = unregister_1(&wid, clnt(this));
+ if (!retp)
+ throw connexion_exception();
+
+ ret = *retp;
+ if (ret != WESPRET_OK)
+ throw_exception_using_ret(ret);
+
+ this->id = 0;
+}
+
+/* ---
+ * Récupération d'éléments.
+ * --- */
+
+struct tm wes_base::get_date(void)
+{
+ wespid_t wid;
+ wespret_with_datetime_t *resp;
+ wespdatetime_t *dt;
+ struct tm tm;
+
+ if (this->id == 0)
+ throw not_loaded_exception();
+
+ wid = this->id;
+ resp = get_date_time_1(&wid, clnt(this));
+ if (!resp)
+ throw connexion_exception();
+
+ if (resp->ret != WESPRET_OK)
+ throw_exception_using_ret(resp->ret);
+
+ dt = &resp->dt;
+ tm.tm_year = dt->year - 1900;
+ tm.tm_mon = dt->mon - 1;
+ tm.tm_mday = dt->dom;
+ tm.tm_hour = dt->hour;
+ tm.tm_min = dt->min;
+ tm.tm_sec = dt->sec;
+
+ mktime(&tm);
+ return (tm);
+}
+
+electricity_meter wes_base::get_electricity_meter(int em_id)
+{
+ electricity_meter em(this, em_id);
+
+ return (em);
+}
diff --git a/weshd.x b/weshd.x
index 219d402..352751f 100644
--- a/weshd.x
+++ b/weshd.x
@@ -66,6 +66,26 @@ struct wespip_t {
unsigned char ipv6[16];
};
+/* Les données relatives à la création d'une ressource de type serveur WES.
+ * - `WESPREGTYPE_DUMMY` : faire comme si un serveur WES existait, pour
+ * développer une bibliothèque ou un client sans serveur WES sous la main
+ * par exemple ;
+ * - `WESPREGTYPE_IP` : se connecter au serveur WES via IP. */
+
+enum wespregtype_t {
+ WESPREGTYPE_DUMMY = 0,
+ WESPREGTYPE_IP = 1
+};
+
+struct wespregopts_t {
+ wespregtype_t type;
+ wespip_t ip;
+ string http_username<>;
+ string http_password<>;
+ string ftp_username<>;
+ string ftp_password<>;
+};
+
/* Une date, version protocole. */
struct wespdatetime_t {
@@ -224,26 +244,6 @@ struct wespticdat_t {
unsigned long index_ejp_pm; /* Pointe Mobile */
};
-/* Les données relatives à la création d'une ressource de type serveur WES.
- * - `WESPREGTYPE_DUMMY` : faire comme si un serveur WES existait, pour
- * développer une bibliothèque ou un client sans serveur WES sous la main
- * par exemple ;
- * - `WESPREGTYPE_IP` : se connecter au serveur WES via IP. */
-
-enum wespregtype_t {
- WESPREGTYPE_DUMMY = 0,
- WESPREGTYPE_IP = 1
-};
-
-struct wespregopts_t {
- wespregtype_t type;
- wespip_t ip;
- string http_username<>;
- string http_password<>;
- string ftp_username<>;
- string ftp_password<>;
-};
-
/* Structures utiles aux appels serveur. */
struct wespret_with_id_t {