binder: Clang format the source code

Add a ".clang-format" file which is pretty close to the rest of
wpa_supplicant code base and reformat the binder codebase.

Signed-off-by: Roshan Pius <rpius@google.com>
This commit is contained in:
Roshan Pius 2016-07-07 09:48:58 -07:00 committed by Jouni Malinen
parent fe1d0771f7
commit a1979469fd
11 changed files with 105 additions and 107 deletions

View file

@ -0,0 +1,9 @@
BasedOnStyle: LLVM
IndentWidth: 8
UseTab: Always
BreakBeforeBraces: Mozilla
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
AccessModifierOffset: -8
AlignAfterOpenBracket: AlwaysBreak
SortIncludes: false

View file

@ -8,36 +8,35 @@
*/
#include <binder/IPCThreadState.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>
#include "binder_manager.h"
extern "C" {
#include "utils/includes.h"
#include "utils/common.h"
#include "utils/eloop.h"
#include "binder.h"
#include "binder_i.h"
#include "utils/common.h"
#include "utils/eloop.h"
#include "utils/includes.h"
}
void wpas_binder_sock_handler(int sock, void *eloop_ctx, void *sock_ctx)
{
struct wpa_global *global = (wpa_global *) eloop_ctx;
struct wpas_binder_priv *priv = (wpas_binder_priv *) sock_ctx;
struct wpa_global *global = (wpa_global *)eloop_ctx;
struct wpas_binder_priv *priv = (wpas_binder_priv *)sock_ctx;
wpa_printf(MSG_DEBUG, "Processing binder events on FD %d",
priv->binder_fd);
wpa_printf(
MSG_DEBUG, "Processing binder events on FD %d", priv->binder_fd);
android::IPCThreadState::self()->handlePolledCommands();
}
struct wpas_binder_priv * wpas_binder_init(struct wpa_global *global)
struct wpas_binder_priv *wpas_binder_init(struct wpa_global *global)
{
struct wpas_binder_priv *priv;
wpa_supplicant_binder::BinderManager *binder_manager;
priv = (wpas_binder_priv *) os_zalloc(sizeof(*priv));
priv = (wpas_binder_priv *)os_zalloc(sizeof(*priv));
if (!priv)
return NULL;
priv->global = global;
@ -49,8 +48,8 @@ struct wpas_binder_priv * wpas_binder_init(struct wpa_global *global)
if (priv->binder_fd < 0)
goto err;
/* Look for read events from the binder socket in the eloop. */
if (eloop_register_read_sock(priv->binder_fd, wpas_binder_sock_handler,
global, priv) < 0)
if (eloop_register_read_sock(
priv->binder_fd, wpas_binder_sock_handler, global, priv) < 0)
goto err;
binder_manager = wpa_supplicant_binder::BinderManager::getInstance();
@ -59,7 +58,7 @@ struct wpas_binder_priv * wpas_binder_init(struct wpa_global *global)
binder_manager->registerBinderService(global);
/* We may not need to store this binder manager reference in the
* global data strucure because we've made it a singleton class. */
priv->binder_manager = (void *) binder_manager;
priv->binder_manager = (void *)binder_manager;
return priv;
@ -68,7 +67,6 @@ err:
return NULL;
}
void wpas_binder_deinit(struct wpas_binder_priv *priv)
{
if (!priv)
@ -79,28 +77,26 @@ void wpas_binder_deinit(struct wpas_binder_priv *priv)
android::IPCThreadState::shutdown();
}
int wpas_binder_register_interface(struct wpa_supplicant *wpa_s)
{
if (!wpa_s->global->binder)
return 1;
wpa_supplicant_binder::BinderManager *binder_manager =
wpa_supplicant_binder::BinderManager::getInstance();
wpa_supplicant_binder::BinderManager::getInstance();
if (!binder_manager)
return 1;
return binder_manager->registerInterface(wpa_s);
}
int wpas_binder_unregister_interface(struct wpa_supplicant *wpa_s)
{
if (!wpa_s->global->binder)
return 1;
wpa_supplicant_binder::BinderManager *binder_manager =
wpa_supplicant_binder::BinderManager::getInstance();
wpa_supplicant_binder::BinderManager::getInstance();
if (!binder_manager)
return 1;

View file

@ -7,8 +7,8 @@
* See README for more details.
*/
#ifndef BINDER_H
#define BINDER_H
#ifndef WPA_SUPPLICANT_BINDER_BINDER_H
#define WPA_SUPPLICANT_BINDER_BINDER_H
#ifdef _cplusplus
extern "C" {
@ -22,13 +22,13 @@ extern "C" {
struct wpas_binder_priv;
struct wpa_global;
struct wpas_binder_priv * wpas_binder_init(struct wpa_global *global);
struct wpas_binder_priv *wpas_binder_init(struct wpa_global *global);
void wpas_binder_deinit(struct wpas_binder_priv *priv);
#ifdef CONFIG_CTRL_IFACE_BINDER
int wpas_binder_register_interface(struct wpa_supplicant *wpa_s);
int wpas_binder_unregister_interface(struct wpa_supplicant *wpa_s);
#else /* CONFIG_CTRL_IFACE_BINDER */
#else /* CONFIG_CTRL_IFACE_BINDER */
static inline int wpas_binder_register_interface(struct wpa_supplicant *wpa_s)
{
return 0;
@ -43,4 +43,4 @@ static inline int wpas_binder_unregister_interface(struct wpa_supplicant *wpa_s)
}
#endif /* _cplusplus */
#endif /* BINDER_H */
#endif /* WPA_SUPPLICANT_BINDER_BINDER_H */

View file

@ -7,8 +7,8 @@
* See README for more details.
*/
#ifndef BINDER_CONSTANTS_H
#define BINDER_CONSTANTS_H
#ifndef WPA_SUPPLICANT_BINDER_BINDER_CONSTANTS_H
#define WPA_SUPPLICANT_BINDER_BINDER_CONSTANTS_H
namespace wpa_supplicant_binder {
namespace binder_constants {
@ -18,4 +18,4 @@ extern const char kServiceName[];
} /* namespace binder_constants */
} /* namespace wpa_supplicant_binder */
#endif /* BINDER_CONSTANTS_H */
#endif /* WPA_SUPPLICANT_BINDER_BINDER_CONSTANTS_H */

View file

@ -14,7 +14,8 @@
extern "C" {
#endif // _cplusplus
struct wpas_binder_priv {
struct wpas_binder_priv
{
int binder_fd;
struct wpa_global *global;
void *binder_manager;

View file

@ -13,22 +13,21 @@
#include "binder_manager.h"
extern "C" {
#include "utils/includes.h"
#include "utils/common.h"
#include "utils/includes.h"
}
namespace wpa_supplicant_binder {
BinderManager *BinderManager::instance_ = NULL;
BinderManager * BinderManager::getInstance()
BinderManager *BinderManager::getInstance()
{
if (!instance_)
instance_ = new BinderManager();
return instance_;
}
void BinderManager::destroyInstance()
{
if (instance_)
@ -36,7 +35,6 @@ void BinderManager::destroyInstance()
instance_ = NULL;
}
int BinderManager::registerBinderService(struct wpa_global *global)
{
/* Create the main binder service object and register with
@ -44,12 +42,10 @@ int BinderManager::registerBinderService(struct wpa_global *global)
supplicant_object_ = new Supplicant(global);
android::String16 service_name(binder_constants::kServiceName);
android::defaultServiceManager()->addService(
service_name,
android::IInterface::asBinder(supplicant_object_));
service_name, android::IInterface::asBinder(supplicant_object_));
return 0;
}
int BinderManager::registerInterface(struct wpa_supplicant *wpa_s)
{
if (!wpa_s)
@ -72,7 +68,6 @@ int BinderManager::registerInterface(struct wpa_supplicant *wpa_s)
return 0;
}
int BinderManager::unregisterInterface(struct wpa_supplicant *wpa_s)
{
if (!wpa_s || !wpa_s->binder_object_key)
@ -88,10 +83,9 @@ int BinderManager::unregisterInterface(struct wpa_supplicant *wpa_s)
return 0;
}
int BinderManager::getIfaceBinderObjectByKey(
const void *iface_object_key,
android::sp<fi::w1::wpa_supplicant::IIface> *iface_object)
const void *iface_object_key,
android::sp<fi::w1::wpa_supplicant::IIface> *iface_object)
{
if (!iface_object_key || !iface_object)
return 1;

View file

@ -7,14 +7,14 @@
* See README for more details.
*/
#ifndef BINDER_MANAGER_H
#define BINDER_MANAGER_H
#ifndef WPA_SUPPLICANT_BINDER_BINDER_MANAGER_H
#define WPA_SUPPLICANT_BINDER_BINDER_MANAGER_H
#include <map>
#include <string>
#include "supplicant.h"
#include "iface.h"
#include "supplicant.h"
struct wpa_global;
struct wpa_supplicant;
@ -27,16 +27,17 @@ namespace wpa_supplicant_binder {
* class which is created by the supplicant core and can be used
* to get references to the binder objects.
*/
class BinderManager {
class BinderManager
{
public:
static BinderManager * getInstance();
static BinderManager *getInstance();
static void destroyInstance();
int registerBinderService(struct wpa_global *global);
int registerInterface(struct wpa_supplicant *wpa_s);
int unregisterInterface(struct wpa_supplicant *wpa_s);
int getIfaceBinderObjectByKey(
const void *iface_object_key,
android::sp<fi::w1::wpa_supplicant::IIface> *iface_object);
const void *iface_object_key,
android::sp<fi::w1::wpa_supplicant::IIface> *iface_object);
private:
BinderManager() = default;
@ -54,4 +55,4 @@ private:
} /* namespace wpa_supplicant_binder */
#endif /* BINDER_MANAGER_H */
#endif /* WPA_SUPPLICANT_BINDER_BINDER_MANAGER_H */

View file

@ -11,9 +11,6 @@
namespace wpa_supplicant_binder {
Iface::Iface(struct wpa_supplicant *wpa_s)
: wpa_s_(wpa_s)
{
}
Iface::Iface(struct wpa_supplicant *wpa_s) : wpa_s_(wpa_s) {}
} /* namespace wpa_supplicant_binder */

View file

@ -7,14 +7,14 @@
* See README for more details.
*/
#ifndef IFACE_H
#define IFACE_H
#ifndef WPA_SUPPLICANT_BINDER_IFACE_H
#define WPA_SUPPLICANT_BINDER_IFACE_H
#include "fi/w1/wpa_supplicant/BnIface.h"
extern "C" {
#include "utils/includes.h"
#include "utils/common.h"
#include "utils/includes.h"
#include "../wpa_supplicant_i.h"
}
@ -39,4 +39,4 @@ private:
} /* namespace wpa_supplicant_binder */
#endif /* IFACE_H */
#endif /* WPA_SUPPLICANT_BINDER_IFACE_H */

View file

@ -7,28 +7,24 @@
* See README for more details.
*/
#include "binder_manager.h"
#include "supplicant.h"
#include "binder_manager.h"
namespace wpa_supplicant_binder {
Supplicant::Supplicant(struct wpa_global *global)
: wpa_global_(global)
{
}
Supplicant::Supplicant(struct wpa_global *global) : wpa_global_(global) {}
android::binder::Status Supplicant::CreateInterface(
const android::os::PersistableBundle &params,
android::sp<fi::w1::wpa_supplicant::IIface> *aidl_return)
const android::os::PersistableBundle &params,
android::sp<fi::w1::wpa_supplicant::IIface> *aidl_return)
{
android::String16 driver, ifname, confname, bridge_ifname;
/* Check if required Ifname argument is missing */
if (!params.getString(android::String16("Ifname"), &ifname))
return android::binder::Status::fromServiceSpecificError(
ERROR_INVALID_ARGS,
android::String8("Ifname missing in params."));
ERROR_INVALID_ARGS,
android::String8("Ifname missing in params."));
/* Retrieve the remaining params from the dictionary */
params.getString(android::String16("Driver"), &driver);
params.getString(android::String16("ConfigFile"), &confname);
@ -38,11 +34,12 @@ android::binder::Status Supplicant::CreateInterface(
* Try to get the wpa_supplicant record for this iface, return
* an error if we already control it.
*/
if (wpa_supplicant_get_iface(wpa_global_,
android::String8(ifname).string()) != NULL)
if (wpa_supplicant_get_iface(
wpa_global_, android::String8(ifname).string()) != NULL)
return android::binder::Status::fromServiceSpecificError(
ERROR_IFACE_EXISTS,
android::String8("wpa_supplicant already controls this interface."));
ERROR_IFACE_EXISTS,
android::String8("wpa_supplicant already controls this "
"interface."));
android::binder::Status status;
struct wpa_supplicant *wpa_s = NULL;
@ -52,36 +49,38 @@ android::binder::Status Supplicant::CreateInterface(
iface.driver = os_strdup(android::String8(driver).string());
iface.ifname = os_strdup(android::String8(ifname).string());
iface.confname = os_strdup(android::String8(confname).string());
iface.bridge_ifname = os_strdup(
android::String8(bridge_ifname).string());
iface.bridge_ifname =
os_strdup(android::String8(bridge_ifname).string());
/* Otherwise, have wpa_supplicant attach to it. */
wpa_s = wpa_supplicant_add_iface(wpa_global_, &iface, NULL);
/* The supplicant core creates a corresponding binder object via
* BinderManager when |wpa_supplicant_add_iface| is called. */
if (!wpa_s || !wpa_s->binder_object_key) {
status = android::binder::Status::fromServiceSpecificError(
ERROR_UNKNOWN,
android::String8("wpa_supplicant couldn't grab this interface."));
ERROR_UNKNOWN,
android::String8(
"wpa_supplicant couldn't grab this interface."));
} else {
BinderManager *binder_manager = BinderManager::getInstance();
if (!binder_manager ||
binder_manager->getIfaceBinderObjectByKey(
wpa_s->binder_object_key, aidl_return))
status = android::binder::Status::fromServiceSpecificError(
wpa_s->binder_object_key, aidl_return))
status =
android::binder::Status::fromServiceSpecificError(
ERROR_UNKNOWN,
android::String8("wpa_supplicant encountered a binder error."));
android::String8("wpa_supplicant encountered a "
"binder error."));
else
status = android::binder::Status::ok();
}
os_free((void *) iface.driver);
os_free((void *) iface.ifname);
os_free((void *) iface.confname);
os_free((void *) iface.bridge_ifname);
os_free((void *)iface.driver);
os_free((void *)iface.ifname);
os_free((void *)iface.confname);
os_free((void *)iface.bridge_ifname);
return status;
}
android::binder::Status Supplicant::RemoveInterface(const std::string &ifname)
{
struct wpa_supplicant *wpa_s;
@ -89,35 +88,38 @@ android::binder::Status Supplicant::RemoveInterface(const std::string &ifname)
wpa_s = wpa_supplicant_get_iface(wpa_global_, ifname.c_str());
if (!wpa_s || !wpa_s->binder_object_key)
return android::binder::Status::fromServiceSpecificError(
ERROR_IFACE_UNKNOWN,
android::String8("wpa_supplicant does not control this interface."));
ERROR_IFACE_UNKNOWN,
android::String8("wpa_supplicant does not control this "
"interface."));
if (wpa_supplicant_remove_iface(wpa_global_, wpa_s, 0))
return android::binder::Status::fromServiceSpecificError(
ERROR_UNKNOWN,
android::String8("wpa_supplicant couldn't remove this interface."));
ERROR_UNKNOWN,
android::String8(
"wpa_supplicant couldn't remove this interface."));
return android::binder::Status::ok();
}
android::binder::Status Supplicant::GetInterface(
const std::string &ifname,
android::sp<fi::w1::wpa_supplicant::IIface> *aidl_return)
const std::string &ifname,
android::sp<fi::w1::wpa_supplicant::IIface> *aidl_return)
{
struct wpa_supplicant *wpa_s;
wpa_s = wpa_supplicant_get_iface(wpa_global_, ifname.c_str());
if (!wpa_s || !wpa_s->binder_object_key)
return android::binder::Status::fromServiceSpecificError(
ERROR_IFACE_UNKNOWN,
android::String8("wpa_supplicant does not control this interface."));
ERROR_IFACE_UNKNOWN,
android::String8(
"wpa_supplicant does not control this interface."));
BinderManager *binder_manager = BinderManager::getInstance();
if (!binder_manager ||
binder_manager->getIfaceBinderObjectByKey(wpa_s->binder_object_key,
aidl_return))
binder_manager->getIfaceBinderObjectByKey(
wpa_s->binder_object_key, aidl_return))
return android::binder::Status::fromServiceSpecificError(
ERROR_UNKNOWN,
android::String8("wpa_supplicant encountered a binder error."));
ERROR_UNKNOWN,
android::String8(
"wpa_supplicant encountered a binder error."));
return android::binder::Status::ok();
}

View file

@ -7,16 +7,16 @@
* See README for more details.
*/
#ifndef SUPPLICANT_H
#define SUPPLICANT_H
#ifndef WPA_SUPPLICANT_BINDER_SUPPLICANT_H
#define WPA_SUPPLICANT_BINDER_SUPPLICANT_H
#include "fi/w1/wpa_supplicant/BnSupplicant.h"
#include "fi/w1/wpa_supplicant/IIface.h"
#include "fi/w1/wpa_supplicant/ISupplicantCallbacks.h"
extern "C" {
#include "utils/includes.h"
#include "utils/common.h"
#include "utils/includes.h"
#include "../wpa_supplicant_i.h"
}
@ -34,24 +34,22 @@ public:
virtual ~Supplicant() = default;
android::binder::Status CreateInterface(
const android::os::PersistableBundle &params,
android::sp<fi::w1::wpa_supplicant::IIface> *aidl_return)
override;
android::binder::Status RemoveInterface(
const std::string &ifname) override;
const android::os::PersistableBundle &params,
android::sp<fi::w1::wpa_supplicant::IIface> *aidl_return) override;
android::binder::Status
RemoveInterface(const std::string &ifname) override;
android::binder::Status GetInterface(
const std::string &ifname,
android::sp<fi::w1::wpa_supplicant::IIface> *aidl_return)
override;
const std::string &ifname,
android::sp<fi::w1::wpa_supplicant::IIface> *aidl_return) override;
private:
/* Raw pointer to the global structure maintained by the core. */
struct wpa_global *wpa_global_;
/* All the callback objects registered by the clients. */
std::vector<android::sp<fi::w1::wpa_supplicant::ISupplicantCallbacks>>
callbacks_;
callbacks_;
};
} /* namespace wpa_supplicant_binder */
#endif /* SUPPLICANT_H */
#endif /* WPA_SUPPLICANT_BINDER_SUPPLICANT_H */