From 9c8ece1538d31dba9a416c9f29f88e18510f4c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Sat, 18 May 2019 16:32:20 +0300 Subject: Whole-project: partial implementation of protocol. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit is part of ticket #31. Branch is not in a compiling state. Work is being done on utility functions and protocol implementation. To be completed later. Signed-off-by: Ramūnas Mažeikis --- src/common/utils.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/common/utils.c (limited to 'src/common/utils.c') diff --git a/src/common/utils.c b/src/common/utils.c new file mode 100644 index 0000000..7bcf767 --- /dev/null +++ b/src/common/utils.c @@ -0,0 +1,22 @@ +#include "utils.h" + +fpi1_t add(fpi1_t a, fpi1_t b) +{ + return a + b; +} + +fpi1_t sub(fpi1_t a, fpi1_t b) +{ + return a - b; +} + +fpi1_t mul(fpi1_t a, fpi1_t b) +{ + return (fpi1_t)(((long)a * (long)b) / 100); +} + +fpi1_t div(fpi1_t a, fpi1_t b) +{ + return (fpi1_t)(((long)a * 10) / ((long)b * 10)); +} + -- cgit v1.2.3 From b4165ee0b257aaa9064c5ac82200ff2569a02955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Sun, 19 May 2019 13:52:43 +0300 Subject: Protocol: more work on protocol implementation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Additional functions implemented for protocol and basic functions to work with uuid. Source is buildable but actual build files are not edited to accomodate the changes. Signed-off-by: Ramūnas Mažeikis --- src/common/utils.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/common/utils.c') diff --git a/src/common/utils.c b/src/common/utils.c index 7bcf767..7e4caa5 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -1,5 +1,22 @@ #include "utils.h" +int cmp_uuid(uuid_t *first, uuid_t *second) +{ + if (first->hi == second->hi) { + if (first->low == second->low) { + return 0; + } else if (first->low < second->low) { + return -1; + } else { + return 1; + } + } else if (first->hi < second->hi) { + return -1; + } else { + return 1; + } +} + fpi1_t add(fpi1_t a, fpi1_t b) { return a + b; -- cgit v1.2.3 From 031caaf9b7745bfc552cc86fb475de1f18d0fd6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Sun, 19 May 2019 17:50:53 +0300 Subject: Protocol: Implemented protocol error reporting. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now public functions of the protocol can return an error code. More work is done on actual logic. Protocol code has bare-bones doxygen documentation. Signed-off-by: Ramūnas Mažeikis --- src/common/utils.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'src/common/utils.c') diff --git a/src/common/utils.c b/src/common/utils.c index 7e4caa5..956ef1b 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -1,20 +1,9 @@ #include "utils.h" +#include "string.h" int cmp_uuid(uuid_t *first, uuid_t *second) { - if (first->hi == second->hi) { - if (first->low == second->low) { - return 0; - } else if (first->low < second->low) { - return -1; - } else { - return 1; - } - } else if (first->hi < second->hi) { - return -1; - } else { - return 1; - } + return memcmp(first, second, sizeof(*first)); } fpi1_t add(fpi1_t a, fpi1_t b) @@ -36,4 +25,3 @@ fpi1_t div(fpi1_t a, fpi1_t b) { return (fpi1_t)(((long)a * 10) / ((long)b * 10)); } - -- cgit v1.2.3 From cabb90c1240015ee5cd17d91573588527bcc2482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Tue, 21 May 2019 17:41:21 +0300 Subject: Protocol: changes to interface and some re-implementation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most functions exposed in protocol.h take a connection descriptor (cd_t) as first argument. This allows for multiple connections. Device gets only one connection which means that cd_t is effectively 0 all the time. Additionaly, any function that actually does anything with a connection descriptor instead of just passing it to another function must be implemented separately in device and daemon. Signed-off-by: Ramūnas Mažeikis --- src/common/utils.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/common/utils.c') diff --git a/src/common/utils.c b/src/common/utils.c index 956ef1b..0619517 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -6,22 +6,22 @@ int cmp_uuid(uuid_t *first, uuid_t *second) return memcmp(first, second, sizeof(*first)); } -fpi1_t add(fpi1_t a, fpi1_t b) +fpi1_t fpi1_add(fpi1_t a, fpi1_t b) { return a + b; } -fpi1_t sub(fpi1_t a, fpi1_t b) +fpi1_t fpi1_sub(fpi1_t a, fpi1_t b) { return a - b; } -fpi1_t mul(fpi1_t a, fpi1_t b) +fpi1_t fpi1_mul(fpi1_t a, fpi1_t b) { return (fpi1_t)(((long)a * (long)b) / 100); } -fpi1_t div(fpi1_t a, fpi1_t b) +fpi1_t fpi1_div(fpi1_t a, fpi1_t b) { return (fpi1_t)(((long)a * 10) / ((long)b * 10)); } -- cgit v1.2.3 From b25865cc827f4a6a9c31f3d92a4e443485fd5d93 Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Sun, 26 May 2019 14:46:36 +0300 Subject: common: cosmetic changes. Signed-off-by: Gediminas Jakutis --- src/common/utils.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/common/utils.c') diff --git a/src/common/utils.c b/src/common/utils.c index 0619517..7522404 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -1,3 +1,23 @@ +/* + * Usurpataion --- utility functions. + * + * Copyright (C) 2019 Ramūnas Mažeikis + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + #include "utils.h" #include "string.h" -- cgit v1.2.3