mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-07 03:29:15 +00:00
Generic trigger functions "trigger.h"
This commit is contained in:
parent
a3de276999
commit
008f296026
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (C) 2014 Serval Project Inc.
|
Copyright (C) 2014,2015 Serval Project Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
@ -19,39 +19,30 @@
|
|||||||
#ifndef __SERVAL_DNA__COMMANDLINE_H
|
#ifndef __SERVAL_DNA__COMMANDLINE_H
|
||||||
#define __SERVAL_DNA__COMMANDLINE_H
|
#define __SERVAL_DNA__COMMANDLINE_H
|
||||||
|
|
||||||
|
#include "section.h"
|
||||||
|
|
||||||
#define KEYRING_PIN_OPTION ,"[--keyring-pin=<pin>]"
|
#define KEYRING_PIN_OPTION ,"[--keyring-pin=<pin>]"
|
||||||
#define KEYRING_ENTRY_PIN_OPTION ,"[--entry-pin=<pin>]"
|
#define KEYRING_ENTRY_PIN_OPTION ,"[--entry-pin=<pin>]"
|
||||||
#define KEYRING_PIN_OPTIONS KEYRING_PIN_OPTION KEYRING_ENTRY_PIN_OPTION "..."
|
#define KEYRING_PIN_OPTIONS KEYRING_PIN_OPTION KEYRING_ENTRY_PIN_OPTION "..."
|
||||||
|
|
||||||
// macros are weird sometimes ....
|
|
||||||
#define _APPEND(X,Y) X ## Y
|
|
||||||
#define _APPEND2(X,Y) _APPEND(X,Y)
|
|
||||||
|
|
||||||
struct cli_schema;
|
struct cli_schema;
|
||||||
struct cli_context;
|
struct cli_context;
|
||||||
|
|
||||||
#ifdef __APPLE__
|
// macros are weird sometimes ....
|
||||||
#define SECTION(X) section("__DATA,__" X )
|
#define __APPEND_(X,Y) X ## Y
|
||||||
#define SECTION_START(X) __asm("section$start$__DATA$__" X)
|
#define _APPEND(X,Y) __APPEND_(X,Y)
|
||||||
#define SECTION_END(X) __asm("section$end$__DATA$__" X)
|
|
||||||
#else
|
|
||||||
#define SECTION(X) section(X)
|
|
||||||
#define SECTION_START(X)
|
|
||||||
#define SECTION_END(X)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define DEFINE_CMD(FUNC, FLAGS, HELP, WORD1, ...) \
|
#define DEFINE_CMD(FUNC, FLAGS, HELP, WORD1, ...) \
|
||||||
static int FUNC(const struct cli_parsed *parsed, struct cli_context *context); \
|
static int FUNC(const struct cli_parsed *parsed, struct cli_context *context); \
|
||||||
struct cli_schema _APPEND2(FUNC, __LINE__) \
|
static struct cli_schema _APPEND(FUNC, __LINE__) IN_SECTION(commands) = {\
|
||||||
__attribute__((used,aligned(sizeof(void *)),SECTION("commands"))) = {\
|
.function = FUNC, \
|
||||||
.function = FUNC, \
|
.words = {WORD1, ##__VA_ARGS__, NULL}, \
|
||||||
.words = {WORD1, ##__VA_ARGS__, NULL}, \
|
.flags = FLAGS, \
|
||||||
.flags = FLAGS, \
|
.description = HELP \
|
||||||
.description = HELP\
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern struct cli_schema __start_commands[] SECTION_START("commands");
|
extern struct cli_schema __start_commands[] SECTION_START(commands);
|
||||||
extern struct cli_schema __stop_commands[] SECTION_END("commands");
|
extern struct cli_schema __stop_commands[] SECTION_STOP(commands);
|
||||||
|
|
||||||
#define CMD_COUNT (__stop_commands - __start_commands)
|
#define CMD_COUNT (__stop_commands - __start_commands)
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ HDRS= fifo.h \
|
|||||||
overlay_address.h \
|
overlay_address.h \
|
||||||
overlay_packet.h \
|
overlay_packet.h \
|
||||||
overlay_interface.h \
|
overlay_interface.h \
|
||||||
|
section.h \
|
||||||
|
trigger.h \
|
||||||
commandline.h \
|
commandline.h \
|
||||||
limit.h \
|
limit.h \
|
||||||
rhizome_types.h \
|
rhizome_types.h \
|
||||||
|
@ -31,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
|
#include "trigger.h"
|
||||||
|
|
||||||
#ifndef __RHIZOME_INLINE
|
#ifndef __RHIZOME_INLINE
|
||||||
# if __GNUC__ && !__GNUC_STDC_INLINE__
|
# if __GNUC__ && !__GNUC_STDC_INLINE__
|
||||||
@ -880,7 +881,7 @@ int rhizome_any_fetch_queued();
|
|||||||
int rhizome_fetch_status_html(struct strbuf *b);
|
int rhizome_fetch_status_html(struct strbuf *b);
|
||||||
int rhizome_fetch_has_queue_space(unsigned char log2_size);
|
int rhizome_fetch_has_queue_space(unsigned char log2_size);
|
||||||
|
|
||||||
/* rhizome storage methods */
|
/* Rhizome storage methods */
|
||||||
|
|
||||||
int rhizome_exists(const rhizome_filehash_t *hashp);
|
int rhizome_exists(const rhizome_filehash_t *hashp);
|
||||||
enum rhizome_payload_status rhizome_open_write(struct rhizome_write *write, const rhizome_filehash_t *expectedHashp, uint64_t file_length);
|
enum rhizome_payload_status rhizome_open_write(struct rhizome_write *write, const rhizome_filehash_t *expectedHashp, uint64_t file_length);
|
||||||
@ -921,4 +922,9 @@ int overlay_mdp_service_rhizome_sync(struct internal_mdp_header *header, struct
|
|||||||
void rhizome_sync_status();
|
void rhizome_sync_status();
|
||||||
|
|
||||||
DECLARE_ALARM(rhizome_fetch_status);
|
DECLARE_ALARM(rhizome_fetch_status);
|
||||||
|
|
||||||
|
/* Rhizome triggers */
|
||||||
|
|
||||||
|
DECLARE_TRIGGER(rhizome_bundle_added, rhizome_manifest*)
|
||||||
|
|
||||||
#endif //__SERVAL_DNA__RHIZOME_H
|
#endif //__SERVAL_DNA__RHIZOME_H
|
||||||
|
@ -1357,6 +1357,7 @@ int rhizome_store_manifest(rhizome_manifest *m)
|
|||||||
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic),
|
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic),
|
||||||
m->version
|
m->version
|
||||||
);
|
);
|
||||||
|
CALL_TRIGGER(rhizome_bundle_added, m);
|
||||||
monitor_announce_bundle(m);
|
monitor_announce_bundle(m);
|
||||||
if (serverMode){
|
if (serverMode){
|
||||||
time_ms_t now = gettime_ms();
|
time_ms_t now = gettime_ms();
|
||||||
@ -1372,6 +1373,18 @@ rollback:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void trigger_rhizome_bundle_added_debug(rhizome_manifest *m)
|
||||||
|
{
|
||||||
|
if (config.debug.rhizome)
|
||||||
|
DEBUGF("TRIGGER rhizome_bundle_added service=%s bid=%s version=%"PRIu64,
|
||||||
|
m->service ? m->service : "NULL",
|
||||||
|
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic),
|
||||||
|
m->version
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_TRIGGER(rhizome_bundle_added, trigger_rhizome_bundle_added_debug)
|
||||||
|
|
||||||
/* The cursor struct must be zerofilled and the query parameters optionally filled in prior to
|
/* The cursor struct must be zerofilled and the query parameters optionally filled in prior to
|
||||||
* calling this function.
|
* calling this function.
|
||||||
*
|
*
|
||||||
|
38
section.h
Normal file
38
section.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2015 Serval Project Inc.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SERVAL_DNA__SECTION_H
|
||||||
|
#define __SERVAL_DNA__SECTION_H
|
||||||
|
|
||||||
|
/* Macros for creating named linkage sections.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#define _SECTION_ATTRIBUTE(X) section("__DATA,__" #X )
|
||||||
|
#define SECTION_START(X) __asm("section$start$__DATA$__" #X)
|
||||||
|
#define SECTION_STOP(X) __asm("section$end$__DATA$__" #X)
|
||||||
|
#else
|
||||||
|
#define _SECTION_ATTRIBUTE(X) section(#X)
|
||||||
|
#define SECTION_START(X)
|
||||||
|
#define SECTION_STOP(X)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define IN_SECTION(name) __attribute__((used,aligned(sizeof(void *)),_SECTION_ATTRIBUTE(name)))
|
||||||
|
|
||||||
|
#endif // __SERVAL_DNA__SECTION_H
|
||||||
|
|
42
trigger.h
Normal file
42
trigger.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2015 Serval Project Inc.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SERVAL_DNA__TRIGGER_H
|
||||||
|
#define __SERVAL_DNA__TRIGGER_H
|
||||||
|
|
||||||
|
#include "section.h"
|
||||||
|
|
||||||
|
/* Macros for triggers
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define DECLARE_TRIGGER(TRIG, ...) \
|
||||||
|
typedef void TRIGGER_FUNC_##TRIG (__VA_ARGS__); \
|
||||||
|
extern TRIGGER_FUNC_##TRIG *__start___trigger_section_##TRIG[] SECTION_START(trigger_##TRIG); \
|
||||||
|
extern TRIGGER_FUNC_##TRIG *__stop___trigger_section_##TRIG[] SECTION_STOP(trigger_##TRIG);
|
||||||
|
|
||||||
|
#define DEFINE_TRIGGER(TRIG, FUNC) \
|
||||||
|
TRIGGER_FUNC_##TRIG * __trigger_##FUNC IN_SECTION(__trigger_section_##TRIG) = FUNC;
|
||||||
|
|
||||||
|
#define CALL_TRIGGER(TRIG, ...) \
|
||||||
|
do { \
|
||||||
|
TRIGGER_FUNC_##TRIG **__trig; \
|
||||||
|
for (__trig = __start___trigger_section_##TRIG; __trig < __stop___trigger_section_##TRIG; ++__trig) \
|
||||||
|
(**__trig)(__VA_ARGS__); \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
#endif // __SERVAL_DNA__TRIGGER_H
|
Loading…
x
Reference in New Issue
Block a user