Ivan Folgueira Bande 44716dfe23 Refactoring of libwaku to export only C types (#1845)
* Simplifying libwaku.nim by extracting config parser to config.nim
* Adding json_base_event.nim
* Starting to control-version the libwaku.h

  We are creating this libwaku.h inspired by the one that is automatically
  generated by the nim compiler when `make libwaku` is invoked. Therefore,
  the self-generated header is then placed in:

  nimcache/release/libwaku/libwaku.h

* Better waku_example.c organization
* libwaku.nim: better memory management

  We need to create a 'cstring' internally from the 'const char*' passed
  from outside the library.

  We invoke 'allocShared' in order to create the internal 'cstring',
  and invoke 'deallocShared' in order to manually free the memory.
2023-07-07 10:53:00 +02:00

62 lines
1.9 KiB
C

// Generated manually and inspired by the one generated by the Nim Compiler.
// In order to see the header file generated by Nim just run `make libwaku`
// from the root repo folder and the header should be created in
// nimcache/release/libwaku/libwaku.h
#ifndef __libwaku__
#define __libwaku__
// The possible returned values for the functions that return int
#define RET_OK 0
#define RET_ERR 1
#define RET_MISSING_CALLBACK 2
typedef void (*WakuCallBack) (char* msg, size_t len_0);
// This should only be called once.
// It initializes the nim runtime and GC.
void waku_init_lib(void);
// Creates a new instance of the waku node.
// Sets up the waku node from the given configuration.
int waku_new(const char* configJson, WakuCallBack onErrCb);
void waku_start(void);
void waku_stop(void);
int waku_version(WakuCallBack onOkCb);
void waku_set_relay_callback(WakuCallBack callback);
int waku_content_topic(const char* appName,
unsigned int appVersion,
const char* contentTopicName,
const char* encoding,
WakuCallBack onOkCb);
int waku_pubsub_topic(const char* topicName,
WakuCallBack onOkCb);
int waku_default_pubsub_topic(WakuCallBack onOkCb);
int waku_relay_publish(const char* pubSubTopic,
const char* jsonWakuMessage,
unsigned int timeoutMs,
WakuCallBack onOkCb,
WakuCallBack onErrCb);
int waku_relay_subscribe(const char* pubSubTopic,
WakuCallBack onErrCb);
int waku_relay_unsubscribe(const char* pubSubTopic,
WakuCallBack onErrCb);
int waku_connect(const char* peerMultiAddr,
unsigned int timeoutMs,
WakuCallBack onErrCb);
void waku_poll(void);
#endif /* __libwaku__ */