Ejemplo n.º 1
0
int main(void)
{
  cometd			*cometd = cometd_new();
  JsonNode			*connect = json_node_new(JSON_NODE_OBJECT);
  
  /*After the new you can enable or disable the Websocket simply do this, disabled by defautl*/
  cometd->config->webSockState = true;
  
  
  if (cometd->config->webSockState)
    return(webSocketTest());
  
  cometd_configure(cometd, COMETDOPT_URL, "http://m.zpush.ovh:8080/str/strd");
  cometd_configure(cometd, COMETDOPT_MAX_BACKOFF, 5000);
  struct _cometd_ext* logger = cometd_ext_logger_new();
  cometd_ext_add(&cometd->exts, logger);
  cometd_connect(cometd);
  connect = cometd_msg_connect_new(cometd);
  cometd_transport_send(cometd, connect);


  //cometd_subscribe(cometd, "/service/GmY-HuzW/6sd0/echo", handler);
  cometd_transport_send(cometd, cometd_ping_ls(cometd, "/service/GmY-HuzW/6sd0/echo"));
  //cometd_subscribe(cometd, "/service/GmY-HuzW/6sd0/ls", handler);
  //cometd_subscribe(cometd, "service/GmY-HuzW/6sd0/updateMeta", handler);
  //cometd_subscribe(cometd, "/service/GmY-HuzW/6sd0/ls", handler);
  //cometd_subscribe(cometd, "/service/GmY-HuzW/6sd0/newFile", handler);

  
  cometd_listen(cometd);
  return 0;
}
Ejemplo n.º 2
0
int
cometd_unsubscribe(const cometd* h, cometd_subscription* s)
{
  g_return_val_if_fail(s != NULL, ECOMETD_UNKNOWN);
  g_return_val_if_fail(s->channel != NULL, ECOMETD_UNKNOWN);

  const char* channel = s->channel;
  int code = ECOMETD_UNKNOWN;
  JsonNode* node;

  /*
    We can't unsubscribe from a remote meta channel and we only
    want to remotely unsubscribe if this is the last remaining
    listener.
  */
  if (cometd_is_meta_channel(channel) == FALSE && cometd_listener_count(h, channel) == 1)
  {
    JsonNode* node = cometd_new_unsubscribe_message(h, channel);

    if (node != NULL)
    {
      code = cometd_transport_send(h, node);
      json_node_free(node);
    }
  }

  // don't remove the local listener if the remote call failed
  if (code != COMETD_SUCCESS)
    code = cometd_remove_listener(h, s);

  return code;
}
Ejemplo n.º 3
0
int
cometd_publish(const cometd* h, const char* channel, JsonNode* message)
{
  int code = COMETD_SUCCESS;

  JsonNode* node = cometd_new_publish_message(h, channel, message);
  if (node == NULL)
    goto failed_node;

  code = cometd_transport_send(h, node);
  json_node_free(node);

failed_node:
  return code;
}
Ejemplo n.º 4
0
END_TEST

START_TEST (test_cometd_transport_send_fires_outgoing_ext)
{
    cometd_conn_set_transport(g_instance->conn, &TEST_TRANSPORT);

    JsonNode* expected = cometd_json_str2node("{ \"foo\": 1}");
    gboolean ret = FALSE;

    cometd_ext* ext = cometd_ext_new();
    ext->outgoing = add_foo;
    cometd_ext_add(&g_instance->exts, ext);

    JsonNode* node = cometd_json_str2node("{}");

    cometd_transport_send(g_instance, node);
    ret = json_node_equal(expected, node, NULL);
    fail_unless(ret);

    json_node_free(node);
    json_node_free(expected);
}
Ejemplo n.º 5
0
cometd_subscription*
cometd_subscribe(const cometd* h,
                 char* channel,
                 cometd_callback handler)
{
  int code = COMETD_SUCCESS;
  cometd_subscription* s = NULL;

  if (cometd_is_meta_channel(channel) == FALSE)
  {
    JsonNode* node = cometd_new_subscribe_message(h, channel);
    if (node != NULL)
    {
      code = cometd_transport_send(h, node);
      json_node_free(node);
    }
  }

  if (code == COMETD_SUCCESS)
    s = cometd_add_listener(h, channel, handler);

  return s;
}