Esempio n. 1
0
void ortc_subscribe(ortc_context* context, 
		    char *channel, 
		    int subscribeOnReconnected, 
		    void (*onMessage)(ortc_context*, char*, char*)){
  if(context->state != CONNECTED){
    _ortc_exception(context, "Not connected");
  } else if(!channel || strlen(channel)==0){
    _ortc_exception(context, "Channel is null or empty");
  } else if(!_ortc_isValidInput(context, channel)) {
    _ortc_exception(context, "Channel has invalid characters");
  } else if(_ortc_is_subscribing(context, channel)){
      char *ex_msg = _ortc_ch_ex_msg("Already trying to subscribe this channel", channel);
      _ortc_exception(context, ex_msg);
      free(ex_msg);
  } else if(ortc_is_subscribed(context, channel)){
      char *ex_msg = _ortc_ch_ex_msg("Already subscribed to this channel", channel);
      _ortc_exception(context, ex_msg);
      free(ex_msg);
  } else if(strlen(channel) > ORTC_CHANNEL_MAX_SIZE){
    _ortc_exception(context, "Channel size exceeds the limit of characters");
  } else if(!onMessage){
    _ortc_exception(context, "The argument \"onMessage\" must point to a function");
  } else {
    _ortc_subscribe(context, channel, subscribeOnReconnected, 1, onMessage);
  }
}
Esempio n. 2
0
void _ortc_subscribeOnReconnected(ortc_context *context){
  ortc_dnode *ptr = (ortc_dnode*)context->channels->first;
  ortc_dnode *t;

  while(ptr != NULL){
    if(ptr->num < 3){
      t = ptr;
      ptr = (ortc_dnode*)ptr->next;
      //_ortc_dlist_free_dnode(t);
      _ortc_dlist_delete(context->channels, t->id);
    } else {
      _ortc_subscribe(context, ptr->id, 1, 0, (void(*)(ortc_context*, char*, char*))ptr->callback);
      ptr = (ortc_dnode*)ptr->next;
    }
  }
}