void on_subscribe(const Subscriber& s) const {
   typedef state_type<values, Subscriber, EventHandlers, T> state_t;
   // take a copy of the values for each subscription
   auto state = std::make_shared<state_t>(initial_, s);
   // start the first iteration
   state->do_subscribe();
 }
Пример #2
0
            void do_subscribe() {
                auto state = this->shared_from_this();
                
                state->out.remove(state->lifetime_token);
                state->source_lifetime.unsubscribe();

                state->source_lifetime = composite_subscription();
                state->lifetime_token = state->out.add(state->source_lifetime);

                state->source.subscribe(
                    state->out,
                    state->source_lifetime,
                // on_next
                    [state](T t) {
                        state->out.on_next(t);
                    },
                // on_error
                    [state](std::exception_ptr e) {
                        state->out.on_error(e);
                    },
                // on_completed
                    [state]() {
                        if (state->repeat_infinitely || (--state->remaining > 0)) {
                            state->do_subscribe();
                        } else {
                            state->out.on_completed();
                        }
                    }
                );
            }
Пример #3
0
                        void do_subscribe() {
                            auto state = this->shared_from_this();

                            state->source_lifetime = composite_subscription();
                            state->out.add(state->source_lifetime);

                            state->source.subscribe(
                                state->out,
                                state->source_lifetime,
                                // on_next
                                [state](T t) {
                                state->out.on_next(t);
                            },
                                // on_error
                                [state](std::exception_ptr e) {
                                if (state->retry_infinitely || (--state->remaining >= 0)) {
                                    state->do_subscribe();
                                } else {
                                    state->out.on_error(e);
                                }
                            },
                                // on_completed
                                [state]() {

                                    // JEP: never appeears to be called?

                                    state->out.on_completed();
                            }
                            );
                        }
Пример #4
0
    void on_subscribe(const Subscriber& s) const {

        typedef Subscriber output_type;
        struct state_type
            : public std::enable_shared_from_this<state_type>
            , public values
        {
            state_type(const values& i, const output_type& oarg)
                : values(i)
                , source_lifetime(composite_subscription::empty())
                , out(oarg)
            {
            }
            composite_subscription source_lifetime;
            output_type out;
            composite_subscription::weak_subscription lifetime_token;

            void do_subscribe() {
                auto state = this->shared_from_this();
                
                state->out.remove(state->lifetime_token);
                state->source_lifetime.unsubscribe();

                state->source_lifetime = composite_subscription();
                state->lifetime_token = state->out.add(state->source_lifetime);

                state->source.subscribe(
                    state->out,
                    state->source_lifetime,
                // on_next
                    [state](T t) {
                        state->out.on_next(t);
                    },
                // on_error
                    [state](std::exception_ptr e) {
                        state->out.on_error(e);
                    },
                // on_completed
                    [state]() {
                        if (state->repeat_infinitely || (--state->remaining > 0)) {
                            state->do_subscribe();
                        } else {
                            state->out.on_completed();
                        }
                    }
                );
            }
        };

        // take a copy of the values for each subscription
        auto state = std::make_shared<state_type>(initial, s);

        // start the first iteration
        state->do_subscribe();
    }
 void on_subscribe(const Subscriber& s) const {
   typedef state_type<values, Subscriber, EventHandlers, T> state_t;
   // take a copy of the values for each subscription
   auto state = std::make_shared<state_t>(initial_, s);      
   if (initial_.completed_predicate()) {
     // return completed
     state->out.on_completed();
   } else {
     // start the first iteration
     state->do_subscribe();
   }
 }
Пример #6
0
int main(int argc, char **argv)
{
	check_for_root_maybe_die();

	if (argc <= 1)
		usage();
	argc--;	argv++;
	if (!strncmp("help", argv[0], strlen("help")))
		usage();
	else if (!strncmp("version", argv[0], strlen("version")))
		version();
	else if (!strncmp("preload", argv[0], strlen("preload")))
		do_preload(--argc, ++argv);
	else if (!strncmp("add", argv[0], strlen("add")))
		do_add(--argc, ++argv);
	else if (!strncmp("set", argv[0], strlen("set")))
		do_set(--argc, ++argv);
	else if (!strncmp("rm", argv[0], strlen("rm")))
		do_rm(--argc, ++argv);
	else if (!strncmp("flag", argv[0], strlen("flag")))
		do_flag(--argc, ++argv);
	else if (!strncmp("unflag", argv[0], strlen("unflag")))
		do_unflag(--argc, ++argv);
	else if (!strncmp("bind-e", argv[0], strlen("bind-e")))
		do_bind(--argc, ++argv, BIND_TYPE_EGR);
	else if (!strncmp("bind-i", argv[0], strlen("bind-i")))
		do_bind(--argc, ++argv, BIND_TYPE_INGR);
	else if (!strncmp("bind", argv[0], strlen("bind")))
		do_bind(--argc, ++argv, BIND_TYPE_NORM);
	else if (!strncmp("unbind-e", argv[0], strlen("unbind-e")))
		do_unbind(--argc, ++argv, BIND_TYPE_EGR);
	else if (!strncmp("unbind-i", argv[0], strlen("unbind-i")))
		do_unbind(--argc, ++argv, BIND_TYPE_INGR);
	else if (!strncmp("unbind", argv[0], strlen("unbind")))
		do_unbind(--argc, ++argv, BIND_TYPE_NORM);
	else if (!strncmp("replace", argv[0], strlen("replace")))
		do_replace(--argc, ++argv, 0);
	else if (!strncmp("replace-drop", argv[0], strlen("replace-drop")))
		do_replace(--argc, ++argv, 1);
	else if (!strncmp("subscribe", argv[0], strlen("subscribe")))
		do_subscribe(--argc, ++argv);
	else if (!strncmp("unsubscribe", argv[0], strlen("unsubscribe")))
		do_unsubscribe(--argc, ++argv);
	else
		usage();

	return 0;
}
Пример #7
0
/*===========================================================================*
 *				main                                         *
 *===========================================================================*/
PUBLIC int main(int argc, char **argv)
{
/* This is the main routine of this service. The main loop consists of 
 * three major activities: getting new work, processing the work, and
 * sending the reply. The loop never terminates, unless a panic occurs.
 */
  message m;
  int result;                 
  sigset_t sigset;

  /* Initialize the server, then go to work. */
  init_server(argc, argv);

  /* Main loop - get work and do it, forever. */         
  while (TRUE) {              

      /* Wait for incoming message, sets 'callnr' and 'who'. */
      get_work(&m);

      switch (callnr) {
      case PROC_EVENT:
	  sig_handler();
          continue;
      case DS_PUBLISH:
          result = do_publish(&m);
          break;
      case DS_RETRIEVE:
	  result = do_retrieve(&m);
	  break;
      case DS_SUBSCRIBE:
	  result = do_subscribe(&m);
	  break;
      case GETSYSINFO:
	  result = do_getsysinfo(&m);
	  break;
      default: 
          report("DS","warning, got illegal request from:", m.m_source);
          result = EINVAL;
      }

      /* Finally send reply message, unless disabled. */
      if (result != EDONTREPLY) {
          m.m_type = result;  		/* build reply message */
	  reply(who_e, &m);		/* send it away */
      }
  }
  return(OK);				/* shouldn't come here */
}
Пример #8
0
/*===========================================================================*
 *				main                                         *
 *===========================================================================*/
PUBLIC int main(int argc, char **argv)
{
/* This is the main routine of this service. The main loop consists of 
 * three major activities: getting new work, processing the work, and
 * sending the reply. The loop never terminates, unless a panic occurs.
 */
  message m;
  int result;                 

  /* SEF local startup. */
  env_setargs(argc, argv);
  sef_local_startup();

  /* Main loop - get work and do it, forever. */         
  while (TRUE) {              

      /* Wait for incoming message, sets 'callnr' and 'who'. */
      get_work(&m);

      if (is_notify(callnr)) {
          printf("DS: warning, got illegal notify from: %d\n", m.m_source);
          result = EINVAL;
          goto send_reply;
      }

      switch (callnr) {
      case DS_PUBLISH:
          result = do_publish(&m);
          break;
      case DS_RETRIEVE:
	  result = do_retrieve(&m);
	  break;
      case DS_RETRIEVE_LABEL:
	  result = do_retrieve_label(&m);
	  break;
      case DS_DELETE:
	  result = do_delete(&m);
	  break;
      case DS_SUBSCRIBE:
	  result = do_subscribe(&m);
	  break;
      case DS_CHECK:
	  result = do_check(&m);
	  break;
      case DS_SNAPSHOT:
	  result = do_snapshot(&m);
	  break;
      case GETSYSINFO:
	  result = do_getsysinfo(&m);
	  break;
      default: 
          printf("DS: warning, got illegal request from %d\n", m.m_source);
          result = EINVAL;
      }

send_reply:
      /* Finally send reply message, unless disabled. */
      if (result != EDONTREPLY) {
          m.m_type = result;  		/* build reply message */
	  reply(who_e, &m);		/* send it away */
      }
  }
  return(OK);				/* shouldn't come here */
}
Пример #9
0
int main(int argc,char **argv)
{
  char *action;
  const char *err;
  unsigned int i;
  int act = AC_NONE;	/* desired action */
  unsigned int actlen = 0;/* str_len of above */

  (void) umask(022);
  sig_pipeignore();
  when = now();

  getconfopt(argc,argv,options,1,&dir);
  initsub(0);

  sender = get_sender();
  if (!sender) die_sender();
  action = env_get("DEFAULT");
  if (!action) strerr_die2x(100,FATAL,MSG(ERR_NODEFAULT));

  if (!*sender)
    strerr_die2x(100,FATAL,MSG(ERR_BOUNCE));
  if (!sender[str_chr(sender,'@')])
    strerr_die2x(100,FATAL,MSG(ERR_ANONYMOUS));
  if (str_equal(sender,"#@[]"))
    strerr_die2x(100,FATAL,MSG(ERR_BOUNCE));

  action = set_workdir(action);

  stralloc_copys(&target,sender);
  if (action[0]) {
    i = str_chr(action,'-');
    if (action[i]) {
      action[i] = 0;
      stralloc_copys(&target,action + i + 1);
      i = byte_rchr(target.s,target.len,'=');
      if (i < target.len)
	target.s[i] = '@';
    }
  }
  stralloc_0(&target);
  set_cptarget(target.s);	/* for copy() */
  make_verptarget();

  act = get_act_ismod(action,&actlen);

  stralloc_copy(&from,&outlocal);
  stralloc_cats(&from,"-return-@");
  stralloc_cat(&from,&outhost);
  stralloc_0(&from);

  if (qmail_open(&qq) == -1)
    strerr_die2sys(111,FATAL,MSG(ERR_QMAIL_QUEUE));
  msg_headers(act);

  if (act == AC_SUBSCRIBE)
    do_subscribe(action);
  else if (act == AC_SC)
    do_sc(action);
  else if (str_start(action,ACTION_RC))
    do_rc_tc(action,ACTION_RC);
  else if(str_start(action,ACTION_TC))
    do_rc_tc(action,ACTION_TC);
  else if (act == AC_UNSUBSCRIBE)
    do_unsubscribe(action);
  else if (str_start(action,ACTION_UC))
    do_uc(action);
  else if (str_start(action,ACTION_VC))
    do_vc_wc(action,ACTION_VC);
  else if (str_start(action,ACTION_WC))
    do_vc_wc(action,ACTION_WC);
  else if (act == AC_LIST || act == AC_LISTN) 
    do_list(act);
  else if (act == AC_LOG)
    do_log(action,actlen);
  else if (act == AC_EDIT)
    do_edit(action);
  else if (str_start(action,ACTION_ED))
    do_ed(action);
  else if (act == AC_GET)
    do_get(action);
  else if (case_starts(action,ACTION_QUERY) ||
		case_starts(action,ALT_QUERY))
    do_query();
  else if (case_starts(action,ACTION_INFO) ||
		case_starts(action,ALT_INFO))
    do_info();
  else if (case_starts(action,ACTION_FAQ) ||
		case_starts(action,ALT_FAQ))
    do_faq();
  else if (ismod && (act == AC_HELP))
    do_mod_help();
  else
    do_help();

  err = qmail_close(&qq);
  closesub();
  if (*err != '\0')
    strerr_die4x(111,FATAL,MSG(ERR_TMP_QMAIL_QUEUE),": ",err + 1);
  strnum[fmt_ulong(strnum,qmail_qp(&qq))] = 0;
  strerr_die3x(0,INFO,"qp ",strnum);
}