nimbus-eth1/nimbus/api/status_api.c
Jacek Sieka 3c2daa8b80
Expose simple whisper api to C / go (#331)
* dummy c lib

* go stuffz

* Compile secp

* Compile as shared library

* Build with debug info

* Prelude exposed fns with setupForeignThreadGc() (naive)

To avoid GC/thread issues causing segmentation fault when running from Go.

* Add logging, fix lib path and gomaxprocs to make debuggable

* lock to os thread

* Address basic feedback and mark TODOs

* Use normal secp (shared lib flow now)

* api: cleanup, move to api folder
2019-07-31 10:05:22 +02:00

45 lines
909 B
C

#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include "status_api.h"
void NimMain();
void print_msg(received_message* msg) {
printf("Got message! %ld\n", msg->decodedLen);
}
const char* channel = "status-test-c";
const char* msg = "testing message";
int main(int argc, char* argv[]) {
time_t lastmsg;
NimMain();
nimbus_start(30303);
nimbus_subscribe(channel, print_msg);
lastmsg = time(NULL);
while(1) {
usleep(1);
if (lastmsg + 1 <= time(NULL)) {
lastmsg = time(NULL);
char buf[4096];
snprintf(buf, 4095,
"[\"~#c4\",[\"%s\",\"text/plain\",\"~:public-group-user-message\",%ld,%ld,[\"^ \",\"~:chat-id\",\"%s\",\"~:text\",\"%s\"]]]",
msg, lastmsg * 1000 * 100, lastmsg * 1000, channel, msg);
printf("Posting %s\n", buf);
nimbus_post(channel, buf);
}
nimbus_poll();
}
}