Skip to content

Commit

Permalink
Format C code using clang-format, add .clang-format file to the project
Browse files Browse the repository at this point in the history
Changelog: none

Signed-off-by: Fabio Tranchitella <fabio.tranchitella@northern.tech>
  • Loading branch information
tranchitella committed Nov 3, 2020
1 parent a4f6d8a commit 6a0b990
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 59 deletions.
26 changes: 26 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
BasedOnStyle: Google
Language: Cpp
ColumnLimit: 78
IndentWidth: 4
TabWidth: 4
UseTab: Never
MaxEmptyLinesToKeep: 3
AlignTrailingComments: true
SpacesBeforeTrailingComments: 1
SortIncludes: false
DerivePointerAlignment: false
PointerAlignment: Right
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
BreakStringLiterals: false
BinPackArguments: false
BinPackParameters: false
AlignAfterOpenBracket: AlwaysBreak
AllowAllParametersOfDeclarationOnNextLine: true
IndentCaseLabels: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
BreakBeforeBraces: Allman
107 changes: 50 additions & 57 deletions dbus/dbus_libgio.go.h
Original file line number Diff line number Diff line change
@@ -1,92 +1,85 @@
// exported by golang, see dbus_libgio.go
GVariant *
handle_method_call_callback(gchar *objectPath,
gchar *interfaceName,
gchar *methodName);
GVariant *handle_method_call_callback(
gchar *objectPath, gchar *interfaceName, gchar *methodName);

// convert an unsafe pointer to a GDBusConnection structure
static GDBusConnection*
to_gdbusconnection(void* ptr)
static GDBusConnection *to_gdbusconnection(void *ptr)
{
return (GDBusConnection*)ptr;
return (GDBusConnection *)ptr;
}

// convert an unsafe pointer to a GMainLoop structure
static GMainLoop*
to_gmainloop(void* ptr)
static GMainLoop *to_gmainloop(void *ptr)
{
return (GMainLoop*)ptr;
return (GMainLoop *)ptr;
}

// create a new GVariant from a string value
static GVariant *g_variant_new_from_string(gchar *value)
{
return g_variant_new("(s)", value);
return g_variant_new("(s)", value);
}

// create a new GVariant from a boolean valule
static GVariant *g_variant_new_from_boolean(gboolean value)
{
return g_variant_new("(b)", value);
return g_variant_new("(b)", value);
}

// handle method call events on registered objects
static void
handle_method_call (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *method_name,
GVariant *parameters,
GDBusMethodInvocation *invocation,
gpointer user_data)
static void handle_method_call(
GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *method_name,
GVariant *parameters,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
GVariant *response = handle_method_call_callback((char *)object_path,
(char *)interface_name,
(char *)method_name);
if (response != NULL) {
g_dbus_method_invocation_return_value(invocation, response);
}
GVariant *response = handle_method_call_callback(
(char *)object_path, (char *)interface_name, (char *)method_name);
if (response != NULL)
{
g_dbus_method_invocation_return_value(invocation, response);
}
}

// handle get property events on registered objects
static GVariant *
handle_get_property (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *property_name,
GError **error,
gpointer user_data)
static GVariant *handle_get_property(
GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *property_name,
GError **error,
gpointer user_data)
{
return NULL;
return NULL;
}

// handle set property events on registered objects
static gboolean
handle_set_property (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *property_name,
GVariant *value,
GError **error,
gpointer user_data)
static gboolean handle_set_property(
GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *property_name,
GVariant *value,
GError **error,
gpointer user_data)
{
return FALSE;
return FALSE;
}

// global static interface vtable to hook the call method, get and set property callbacks
static GDBusInterfaceVTable interface_vtable =
{
handle_method_call,
handle_get_property,
handle_set_property
};
// global static interface vtable to hook the call method, get and set
// property callbacks
static GDBusInterfaceVTable interface_vtable = {
handle_method_call, handle_get_property, handle_set_property};

// return the static interface vtable above, as golang cannot access statics from C
static GDBusInterfaceVTable *
get_interface_vtable()
// return the static interface vtable above, as golang cannot access statics
// from C
static GDBusInterfaceVTable *get_interface_vtable()
{
return (GDBusInterfaceVTable*)&interface_vtable;
return (GDBusInterfaceVTable *)&interface_vtable;
}
5 changes: 3 additions & 2 deletions dbus/error.go.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
static GError* to_error(void* err) {
return (GError*)err;
static GError *to_error(void *err)
{
return (GError *)err;
}

0 comments on commit 6a0b990

Please sign in to comment.