libmapper: format code using c++ clang-format
Remove libmapper/.clang-fromat and format code using c++ clang-format
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
Change-Id: I62781743b03fa1e806f51f4844c93aaf4cdfac4f
diff --git a/libmapper/.clang-format b/libmapper/.clang-format
deleted file mode 100644
index 4662692..0000000
--- a/libmapper/.clang-format
+++ /dev/null
@@ -1,2 +0,0 @@
----
-DisableFormat: true
diff --git a/libmapper/app.c b/libmapper/app.c
index b8639f8..485a507 100644
--- a/libmapper/app.c
+++ b/libmapper/app.c
@@ -13,6 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "mapper.h"
+
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -20,8 +22,6 @@
#include <systemd/sd-event.h>
#include <unistd.h>
-#include "mapper.h"
-
static void quit(int r, void* loop)
{
sd_event_exit((sd_event*)loop, r);
@@ -253,11 +253,19 @@
}
if (!strcmp(argv[1], "wait"))
+ {
wait_main(argc, argv);
+ }
+
if (!strcmp(argv[1], "subtree-remove"))
+ {
subtree_main(argc, argv);
+ }
+
if (!strcmp(argv[1], "get-service"))
+ {
get_service_main(argc, argv);
+ }
fprintf(stderr, usage, argv[0]);
exit(EXIT_FAILURE);
diff --git a/libmapper/internal.h b/libmapper/internal.h
index 836a5ec..1e9ded9 100644
--- a/libmapper/internal.h
+++ b/libmapper/internal.h
@@ -1,7 +1,8 @@
#pragma once
#include <stddef.h>
#ifdef __cplusplus
-extern "C" {
+extern "C"
+{
#endif
size_t sarraylen(char* array[]);
void sarrayfree(char* array[]);
diff --git a/libmapper/mapper.c b/libmapper/mapper.c
index 4a38790..28ad314 100644
--- a/libmapper/mapper.c
+++ b/libmapper/mapper.c
@@ -15,6 +15,8 @@
*/
#include "mapper.h"
+#include "internal.h"
+
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
@@ -26,8 +28,6 @@
#include <systemd/sd-event.h>
#include <unistd.h>
-#include "internal.h"
-
#define _public_ __attribute__((__visibility__("default")))
#define _unused_ __attribute__((unused))
@@ -134,13 +134,17 @@
ret = calloc(count + 1, sizeof(*ret));
if (!ret)
+ {
return NULL;
+ }
for (i = 0; i < count; ++i)
{
ret[i] = strdup(array[i]);
if (!ret[i])
+ {
goto error;
+ }
}
return ret;
@@ -182,11 +186,15 @@
uint64_t next_retry;
if (wait->finished)
+ {
goto exit;
+ }
if (sd_bus_message_is_method_error(
m, "xyz.openbmc_project.Common.Error.ResourceNotFound"))
+ {
goto exit;
+ }
r = sd_bus_message_get_errno(m);
@@ -227,7 +235,9 @@
}
if (async_wait_check_done(wait))
+ {
async_wait_done(0, wait);
+ }
exit:
free(data);
@@ -243,7 +253,9 @@
for (i = 0; i < wait->count; ++i)
{
if (wait->status[i])
+ {
continue;
+ }
data = malloc(sizeof(*data));
data->wait = wait;
data->path = wait->objs[i];
@@ -265,19 +277,22 @@
return 0;
}
-static int async_wait_match_introspection_complete(_unused_ sd_bus_message* m,
- void* w,
- _unused_ sd_bus_error* e)
+static int async_wait_match_introspection_complete(
+ _unused_ sd_bus_message* m, void* w, _unused_ sd_bus_error* e)
{
int r;
mapper_async_wait* wait = w;
if (wait->finished)
+ {
return 0;
+ }
r = async_wait_get_objects(wait);
if (r < 0)
+ {
async_wait_done(r, wait);
+ }
return 0;
}
@@ -285,14 +300,18 @@
static void async_wait_done(int r, mapper_async_wait* w)
{
if (w->finished)
+ {
return;
+ }
w->finished = 1;
sd_bus_slot_unref(w->introspection_slot);
sd_bus_slot_unref(w->intf_slot);
if (w->callback)
+ {
w->callback(r, w->userdata);
+ }
}
static int async_wait_check_done(mapper_async_wait* w)
@@ -300,11 +319,17 @@
size_t i;
if (w->finished)
+ {
return 1;
+ }
for (i = 0; i < w->count; ++i)
+ {
if (!w->status[i])
+ {
return 0;
+ }
+ }
return 1;
}
@@ -325,7 +350,9 @@
wait = malloc(sizeof(*wait));
if (!wait)
+ {
return -ENOMEM;
+ }
memset(wait, 0, sizeof(*wait));
wait->conn = conn;
@@ -397,9 +424,8 @@
return r;
}
-static int async_subtree_timeout_callback(_unused_ sd_event_source* s,
- _unused_ uint64_t usec,
- void* userdata)
+static int async_subtree_timeout_callback(
+ _unused_ sd_event_source* s, _unused_ uint64_t usec, void* userdata)
{
int r;
struct mapper_async_subtree* subtree = userdata;
@@ -412,7 +438,9 @@
async_subtree_getpaths_callback, subtree, "sias", subtree->namespace, 0,
1, subtree->interface);
if (r < 0)
+ {
async_subtree_done(r, subtree);
+ }
return 0;
}
@@ -425,7 +453,9 @@
uint64_t next_retry;
if (subtree->finished)
+ {
goto exit;
+ }
r = sd_bus_message_get_errno(m);
@@ -433,9 +463,13 @@
m, "xyz.openbmc_project.Common.Error.ResourceNotFound"))
{
if (subtree->op == MAPPER_OP_REMOVE)
+ {
r = 0;
+ }
else
+ {
goto exit;
+ }
}
if ((r == EBUSY || r == ENOBUFS) && subtree->retry < mapper_busy_retries)
@@ -522,11 +556,15 @@
mapper_async_subtree* subtree = t;
if (subtree->finished)
+ {
return 0;
+ }
r = async_subtree_getpaths(subtree);
if (r < 0)
+ {
async_subtree_done(r, subtree);
+ }
return 0;
}
@@ -534,13 +572,17 @@
static void async_subtree_done(int r, mapper_async_subtree* t)
{
if (t->finished)
+ {
return;
+ }
t->finished = 1;
sd_bus_slot_unref(t->slot);
if (t->callback)
+ {
t->callback(r, t->userdata);
+ }
}
_public_ int mapper_subtree_async(sd_bus* conn, sd_event* loop, char* namespace,
@@ -553,7 +595,9 @@
subtree = malloc(sizeof(*subtree));
if (!subtree)
+ {
return -ENOMEM;
+ }
memset(subtree, 0, sizeof(*subtree));
subtree->conn = conn;
@@ -611,14 +655,20 @@
"/xyz/openbmc_project/object_mapper",
"xyz.openbmc_project.ObjectMapper", "GetObject");
if (r < 0)
+ {
goto exit;
+ }
r = sd_bus_message_append(request, "s", obj);
if (r < 0)
+ {
goto exit;
+ }
r = sd_bus_message_append(request, "as", 0, NULL);
if (r < 0)
+ {
goto exit;
+ }
while (true)
{
@@ -636,7 +686,9 @@
}
if (r < 0)
+ {
goto exit;
+ }
exit:
sd_bus_message_unref(request);
@@ -652,19 +704,27 @@
r = mapper_get_object(conn, obj, &reply);
if (r < 0)
+ {
goto exit;
+ }
r = sd_bus_message_enter_container(reply, 0, NULL);
if (r < 0)
+ {
goto exit;
+ }
r = sd_bus_message_enter_container(reply, 0, NULL);
if (r < 0)
+ {
goto exit;
+ }
r = sd_bus_message_read(reply, "s", &tmp);
if (r < 0)
+ {
goto exit;
+ }
*service = strdup(tmp);
diff --git a/libmapper/mapper.h b/libmapper/mapper.h
index 3f86fa6..b3c1284 100644
--- a/libmapper/mapper.h
+++ b/libmapper/mapper.h
@@ -3,7 +3,8 @@
#include <systemd/sd-event.h>
#ifdef __cplusplus
-extern "C" {
+extern "C"
+{
#endif
typedef enum mapper_operation
{
diff --git a/libmapper/test/utils.c b/libmapper/test/utils.c
index b3c7ae1..67f3eab 100644
--- a/libmapper/test/utils.c
+++ b/libmapper/test/utils.c
@@ -9,13 +9,17 @@
size_t i;
char** ret = calloc(len + 1, sizeof(*ret));
if (!ret)
+ {
return NULL;
+ }
for (i = 0; i < len; ++i)
{
ret[i] = strdup(testString);
if (!ret[i])
+ {
goto error;
+ }
}
return ret;
diff --git a/libmapper/test/utils.h b/libmapper/test/utils.h
index 73162cb..61bd35b 100644
--- a/libmapper/test/utils.h
+++ b/libmapper/test/utils.h
@@ -1,7 +1,8 @@
#pragma once
#include <stddef.h>
#ifdef __cplusplus
-extern "C" {
+extern "C"
+{
#endif
char** generate_test_sarray(size_t);
#ifdef __cplusplus