Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Commit

Permalink
rename resolver to pep_plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernardo A. Rodrigues committed Jun 18, 2020
1 parent 011c581 commit 92335c2
Show file tree
Hide file tree
Showing 23 changed files with 438 additions and 214 deletions.
2 changes: 1 addition & 1 deletion access/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ set(libs
fastjson
data_acquisition_plugins
data_transactions_plugins
resolver
pep_plugin
storage_plugin)

add_library(${target} access.c)
Expand Down
6 changes: 3 additions & 3 deletions access/access.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "policy_loader.h"

#include "protocol.h"
#include "resolver.h"
#include "pep_plugin.h"
#include "storage.h"
#include "timer.h"
#include "transaction.h"
Expand All @@ -43,7 +43,7 @@ typedef struct {
dataset_state_t ddstate;
} access_ctx_t_;

void access_init(access_ctx_t *access_context, wallet_ctx_t *device_wallet, resolver_plugin_initializer_t resolver_init_fn[]) {
void access_init(access_ctx_t *access_context, wallet_ctx_t *device_wallet, pep_plugin_initializer_t pep_plugin_init_fn[]) {
if (device_wallet == NULL) {
access_context = NULL;
return;
Expand All @@ -61,7 +61,7 @@ void access_init(access_ctx_t *access_context, wallet_ctx_t *device_wallet, reso
ctx->json_mutex = datadumper_get_mutex();

for (int i = 0; i < PEP_MAX_ACT_CALLBACKS; i++){
pep_register_callback(i, resolver_init(resolver_init_fn[i], &ctx->ddstate));
pep_register_callback(i, pep_plugin_init(pep_plugin_init_fn[i], &ctx->ddstate));
}

*access_context = (access_ctx_t)ctx;
Expand Down
4 changes: 2 additions & 2 deletions access/access.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

#include "dataset.h"
#include "wallet.h"
#include "demo_resolver_wallet.h"
#include "pep_plugin.h"

typedef void *access_ctx_t;

void access_init(access_ctx_t *access_context, wallet_ctx_t *device_wallet, resolver_plugin_initializer_t resolver_init_fn[]);
void access_init(access_ctx_t *access_context, wallet_ctx_t *device_wallet, pep_plugin_initializer_t pep_plugin_init_fn[]);
void access_start(access_ctx_t access_context);
void access_deinit(access_ctx_t access_context);
void access_get_ddstate(access_ctx_t access_context, dataset_state_t **ddstate);
Expand Down
20 changes: 10 additions & 10 deletions access/pep/pep.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* \history
* 25.09.2018. Initial version.
* 18.02.2019. Added enforce_request_action from resolver module.
* 18.02.2019. Added enforce_request_action from pep_plugin module.
* 21.02.2020. Added obligations functionality.
* 11.05.2020. Refactoring
****************************************************************************/
Expand Down Expand Up @@ -185,7 +185,7 @@ static int list_to_string(pap_action_list_t *action_list, char *output_str) {
/****************************************************************************
* CALLBACK FUNCTIONS
****************************************************************************/
static resolver_fn callback_resolver[PEP_MAX_ACT_CALLBACKS] = {0};
static pep_plugin_fn callback_pep_plugin[PEP_MAX_ACT_CALLBACKS] = {0};

/****************************************************************************
* API FUNCTIONS
Expand Down Expand Up @@ -219,11 +219,11 @@ bool pep_term(void) {
return TRUE;
}

bool pep_register_callback(int actuator, resolver_fn resolver) {
bool pep_register_callback(int actuator, pep_plugin_fn pep_plugin) {
pthread_mutex_lock(&pep_mutex);

// Check input parameter
if (resolver == NULL) {
if (pep_plugin == NULL) {
printf("\n\nERROR[%s]: Invalid input parameters.\n\n", __FUNCTION__);
return PEP_ERROR;
}
Expand All @@ -235,8 +235,8 @@ bool pep_register_callback(int actuator, resolver_fn resolver) {
}

// Register callback
if (callback_resolver[actuator] == NULL) {
callback_resolver[actuator] = resolver;
if (callback_pep_plugin[actuator] == NULL) {
callback_pep_plugin[actuator] = pep_plugin;
} else {
printf("\nERROR[%s]: Callback is already registered.\n", __FUNCTION__);
pthread_mutex_unlock(&pep_mutex);
Expand All @@ -252,7 +252,7 @@ bool pep_unregister_callback(void) {
pthread_mutex_lock(&pep_mutex);

for (int i = 0; i < PEP_MAX_ACT_CALLBACKS; i++) {
callback_resolver[i] = NULL;
callback_pep_plugin[i] = NULL;
}

pthread_mutex_unlock(&pep_mutex);
Expand Down Expand Up @@ -307,9 +307,9 @@ bool pep_request_access(char *request, void *response) {
// ToDo: how to properly determine the value of actuator index????
int actuator = 0;

// Resolver callback
if (callback_resolver != NULL) {
callback_resolver[actuator](obligation, (void *)&action);
// pep_plugin callback
if (callback_pep_plugin != NULL) {
callback_pep_plugin[actuator](obligation, (void *)&action);
} else {
printf("\n\nERROR[%s]: Callback is not regostered.\n\n", __FUNCTION__);
ret = FALSE;
Expand Down
10 changes: 5 additions & 5 deletions access/pep/pep.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ typedef enum {
/****************************************************************************
* CALLBACKS
****************************************************************************/
typedef bool (*resolver_fn)(char* obligation, void* action);
typedef bool (*pep_plugin_fn)(char* obligation, void* action);

/****************************************************************************
* API FUNCTIONS
Expand Down Expand Up @@ -97,18 +97,18 @@ bool pep_term(void);
/**
* @fn PEP_register_callback
*
* @brief Register resolver callback
* @brief Register pep_plugin callback
*
* @param resolver - Resolver callback
* @param pep_plugin - pep_plugin callback
*
* @return TRUE on success, FALSE on failure
*/
bool pep_register_callback(int actuator, resolver_fn resolver);
bool pep_register_callback(int actuator, pep_plugin_fn pep_plugin);

/**
* @fn pep_unregister_callback
*
* @brief Unregister resolver callback
* @brief Unregister pep_plugin callback
*
* @param void
*
Expand Down
11 changes: 6 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
#include "network.h"
#include "timer.h"

#include "demo_resolver_relay.h"
#include "pep_plugin_relay.h"
#include "pep_plugin_wallet.h"

#define NODE_URL "nodes.comnet.thetangle.org"
#define NODE_PORT 443
Expand Down Expand Up @@ -65,12 +66,12 @@ int main(int argc, char **argv) {

device_wallet = wallet_create(NODE_URL, NODE_PORT, NULL, NODE_DEPTH, NODE_MWM, WALLET_SEED);

// note how this is where the choice of resolver plugins is made
// note how this is where the choice of pep_plugins is made
// inside main.c, part of Reference Implementation
// PEP implementation is agnostic in regards to which plugin will be used
resolver_plugin_initializer_t plugin_initializers[] = {
demorelayplugin_initializer,
demowalletplugin_initializer,
pep_plugin_initializer_t plugin_initializers[] = {
relay_pep_plugin_initializer,
wallet_pep_plugin_initializer,
};

access_init(&access_context, device_wallet, plugin_initializers);
Expand Down
2 changes: 1 addition & 1 deletion plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ cmake_minimum_required(VERSION 3.11)
add_subdirectory(data/acquisition)
add_subdirectory(data/dataset/vehicle)
add_subdirectory(data/transactions)
add_subdirectory(resolver)
add_subdirectory(pep)
add_subdirectory(storage)
4 changes: 2 additions & 2 deletions plugins/data/dataset/vehicle/vehicle_dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
#define vehicledataset_to_json dataset_to_json
#define vehicledataset_checked_count dataset_checked_count

extern char vehicledatasetdemo01_options[];
extern char vehicledatasetdemo02_options[];
extern char vehicledataset_can_01_options[];
extern char vehicledataset_can_02_options[];

typedef struct {
uint8_t DoorDrvrSts;
Expand Down
14 changes: 7 additions & 7 deletions plugins/resolver/CMakeLists.txt → plugins/pep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@

cmake_minimum_required(VERSION 3.11)

set(target resolver)
set(target pep_plugin)

set(sources
resolver.c
pep_plugin.c
platform_interface/r_pi/relay_interface.c
demos/demo_resolver_can01.c
demos/demo_resolver_can02.c
demos/demo_resolver_wallet.c
demos/demo_resolver_relay.c)
implementation/pep_plugin_can_01.c
implementation/pep_plugin_can_02.c
implementation/pep_plugin_wallet.c
implementation/pep_plugin_relay.c)

set(include_dirs
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/platform_interface/r_pi
${CMAKE_CURRENT_SOURCE_DIR}/demos
${CMAKE_CURRENT_SOURCE_DIR}/implementation
${pigpio_SOURCE_DIR}
)

Expand Down
Loading

0 comments on commit 92335c2

Please sign in to comment.