Last active
February 9, 2016 13:56
-
-
Save gabrielschulhof/235d19629bcaaec82c1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sol-mainloop.h> | |
#include <sol-network.h> | |
#include <sol-oic-client.h> | |
static struct sol_oic_client client = { | |
#ifdef SOL_OIC_CLIENT_API_VERSION | |
SOL_OIC_CLIENT_API_VERSION, | |
#endif /* def SOL_OIC_CLIENT_API_VERSION */ | |
NULL, NULL | |
}; | |
static bool resource_found( | |
struct sol_oic_client *cli, | |
struct sol_oic_resource *res, | |
void *data) { | |
if (res) { | |
printf("Found resource with href: %.*s\n", SOL_STR_SLICE_PRINT(res->href)); | |
} else { | |
printf("null resource\n"); | |
} | |
sol_quit(); | |
return false; | |
} | |
static void startup() { | |
struct sol_network_link_addr address = { | |
.family = SOL_NETWORK_FAMILY_INET, | |
.port = 5683, | |
.addr = { .in6 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } } | |
}; | |
sol_network_addr_from_str(&address, "224.0.1.187"); | |
client.server = sol_coap_server_new(0); | |
if (!sol_oic_client_find_resource(&client, | |
&address, "", | |
resource_found, NULL)) { | |
fprintf(stderr, "Failed to search for resources"); | |
sol_quit(); | |
return; | |
} | |
} | |
static void shutdown() {} | |
SOL_MAIN_DEFAULT(startup, shutdown); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sol-mainloop.h> | |
#include <sol-oic-server.h> | |
#define HANDLER_SIGNATURE \ | |
const struct sol_network_link_addr *cliaddr, \ | |
const void *data, \ | |
const struct sol_oic_map_reader *input, \ | |
struct sol_oic_map_writer *output \ | |
static sol_coap_responsecode_t unifiedHandler(HANDLER_SIGNATURE, | |
const char *methodName) { | |
fprintf(stderr, "method: %s\n", methodName); | |
return SOL_COAP_RSPCODE_NOT_IMPLEMENTED; | |
} | |
static sol_coap_responsecode_t getHandler(HANDLER_SIGNATURE) { | |
return unifiedHandler(cliaddr, data, input, output, "get"); | |
} | |
static sol_coap_responsecode_t putHandler(HANDLER_SIGNATURE) { | |
return unifiedHandler(cliaddr, data, input, output, "put"); | |
} | |
static sol_coap_responsecode_t postHandler(HANDLER_SIGNATURE) { | |
return unifiedHandler(cliaddr, data, input, output, "post"); | |
} | |
static sol_coap_responsecode_t delHandler(HANDLER_SIGNATURE) { | |
return unifiedHandler(cliaddr, data, input, output, "del"); | |
} | |
static struct sol_oic_resource_type resourceDefinition = { | |
#ifdef SOL_OIC_RESOURCE_TYPE_API_VERSION | |
SOL_OIC_RESOURCE_TYPE_API_VERSION, | |
#endif /* def SOL_OIC_RESOURCE_TYPE_API_VERSION */ | |
{ 10, "core.light" }, | |
{ 15, "oic.if.baseline" }, | |
{ getHandler }, | |
{ putHandler }, | |
{ postHandler }, | |
{ delHandler } | |
}; | |
static struct sol_oic_server_resource *resource = NULL; | |
static void startup() { | |
if (sol_oic_server_init()) { | |
fprintf(stderr, "sol_oic_server_init() failed\n"); | |
sol_quit(); | |
return; | |
} | |
resource = sol_oic_server_add_resource(&resourceDefinition, NULL, | |
SOL_OIC_FLAG_DISCOVERABLE | SOL_OIC_FLAG_OBSERVABLE); | |
} | |
static void shutdown() { | |
sol_oic_server_shutdown(); | |
} | |
SOL_MAIN_DEFAULT(startup, shutdown); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cc -g -Wall -O0 -I$(pwd)/build/soletta_sysroot/usr/include/soletta -L$(pwd)/build/soletta_sysroot/usr/lib -lsoletta -Wl,-R$(pwd)/build/soletta_sysroot/usr/lib -o client client.c
cc -g -Wall -O0 -I$(pwd)/build/soletta_sysroot/usr/include/soletta -L$(pwd)/build/soletta_sysroot/usr/lib -lsoletta -Wl,-R$(pwd)/build/soletta_sysroot/usr/lib -o server server.c