Created
June 3, 2014 16:50
-
-
Save tdfischer/4d8e4587ceca996ac2e2 to your computer and use it in GitHub Desktop.
server.c
This file contains 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 <graviton/client/cloud.h> | |
#include <stdlib.h> | |
static void | |
cb_browse (GravitonCloud *cloud, GravitonServiceEvent event, GravitonServiceInterface *iface, gpointer user_data) | |
{ | |
GError *error = NULL; | |
switch (event) { | |
case GRAVITON_SERVICE_NEW: | |
g_print ("Found a door. I'm opening it!\n"); | |
graviton_service_interface_call_noref (iface, "unlock", &error, NULL); | |
break; | |
case GRAVITON_SERVICE_ALL_FOR_NOW: | |
exit(0); | |
break; | |
} | |
} | |
int main(int argc, char** argv) | |
{ | |
GMainLoop *loop; | |
GravitonCloud *cloud; | |
#if !GLIB_CHECK_VERSION(2, 35, 0) | |
g_type_init (); | |
#endif | |
loop = g_main_loop_new (NULL, 0); | |
cloud = graviton_cloud_new_default_cloud (); | |
graviton_cloud_find_service_interfaces (cloud, "net:phrobo:clavis:lock", cb_browse, NULL); | |
g_main_loop_run (loop); | |
} |
This file contains 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 <geepio/pin.h> | |
#include <graviton/server/server.h> | |
#include <graviton/server/service.h> | |
static GVariant* | |
cb_unlock (GravitonService *control, GHashTable *args, GError **error, gpointer user_data) | |
{ | |
GeepioPin *pin = GEEPIO_PIN (user_data); | |
g_print ("BUZZZZ\n"); | |
geepio_pin_set_value (pin, GEEPIO_PIN_VALUE_HIGH, NULL); | |
sleep (5); | |
g_print ("Locked!\n"); | |
geepio_pin_set_value (pin, GEEPIO_PIN_VALUE_LOW, NULL); | |
return NULL; | |
} | |
int main(int argc, char** argv) | |
{ | |
GMainLoop *loop; | |
GravitonServer *server; | |
GeepioPin *pin; | |
GravitonRootService *root; | |
GravitonService *clavisService; | |
#if !GLIB_CHECK_VERSION(2, 36, 0) | |
g_type_init (); | |
#endif | |
loop = g_main_loop_new (NULL, 0); | |
server = graviton_server_new (); | |
pin = geepio_pin_new (7); | |
//geepio_pin_export (pin, NULL); | |
/*g_object_set (pin, | |
"direction", GEEPIO_PIN_DIRECTION_OUT, | |
"value", GEEPIO_PIN_VALUE_LOW, | |
"edge-mode", GEEPIO_PIN_EDGE_NONE, | |
"active-low", GEEPIO_PIN_ACTIVE_LOW_DISABLED, NULL);*/ | |
root = graviton_server_get_root_service (server); | |
clavisService = graviton_service_new ("net:phrobo:clavis:lock"); | |
graviton_service_add_subservice (GRAVITON_SERVICE (root), clavisService); | |
graviton_service_add_method (clavisService, "unlock", cb_unlock, pin, NULL); | |
graviton_server_run_async (server); | |
g_main_loop_run (loop); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment