SimpleSubscriber::SimpleSubscriber(Channel::ptr_t channel, const std::string& publisher_name) :
	m_channel(channel)
{
	m_consumerQueue = "SimpleSubscriber_";
	boost::uuids::random_generator uuid_gen;
	boost::uuids::uuid guid(uuid_gen());
	m_consumerQueue += boost::lexical_cast<std::string>(guid);

	m_channel->DeclareQueue(m_consumerQueue);
	m_channel->BindQueue(m_consumerQueue, publisher_name);

	m_channel->BasicConsume(m_consumerQueue, m_consumerQueue);
}
SimplePublisher::SimplePublisher(Channel::ptr_t channel, const std::string& publisher_name) :
	m_channel(channel), m_publisherExchange(publisher_name)
{
	if (m_publisherExchange == "")
	{
		m_publisherExchange = "SimplePublisher_";
		boost::uuids::random_generator uuid_gen;
		boost::uuids::uuid guid(uuid_gen());
		m_publisherExchange += boost::lexical_cast<std::string>(guid);
	}


	m_channel->DeclareExchange(m_publisherExchange, "fanout", false, false, false);
}
Esempio n. 3
0
int set_repeat(unsigned int interval, void (*callback)(int tick_count, int arg), unsigned int repeat, ...) {
  int i = get_free_slot_index();

  if (i == -1)
    return -1;

  timers_slots[i].id = uuid_gen();
  timers_slots[i].is_running = 1;
  timers_slots[i].interval = interval;
  timers_slots[i].last_call = millis();
  timers_slots[i].repeat = repeat;
  timers_slots[i].tick_count = 0;
  timers_slots[i].callback = callback;

  // read variable list
  va_list args;
  va_start(args, repeat);
  timers_slots[i].arg = va_arg(args, int);
  va_end(args);

  return timers_slots[i].id;
}
Esempio n. 4
0
const boost::uuids::uuid World::AddPlayer(const std::string &name) {
  std::vector<std::string>::iterator iter = 
                          std::find(player_name_list_.begin(),
                                    player_name_list_.end(), name);
  std::string dup;
  if (iter != player_name_list_.end()) {
    dup = *iter;
  }
  if(dup == name) {  // player already exists
    typedef boost::unordered_map<boost::uuids::uuid, entities::Player*> umap;
    for(umap::iterator iter = player_list_.begin(); iter != player_list_.end(); iter++) {
      if (iter->second->name() == name) {
        return iter->first;
      }
    }
  }
  player_name_list_.push_back(name);
  boost::uuids::uuid uid = uuid_gen();
  entities::Player *player = new entities::Player(uid, name);
  player_list_[uid] = player;
  return uid;
}
Esempio n. 5
0
// 37 = 2 * 16 (chars) + 4 (hyphens) + 1 (\0)
SOL_API int
sol_util_uuid_gen(bool upcase,
    bool with_hyphens,
    char id[SOL_STATIC_ARRAY_SIZE(37)])
{
    static struct sol_str_slice hyphen = SOL_STR_SLICE_LITERAL("-");
    /* hyphens on positions 8, 13, 18, 23 (from 0) */
    static const int hyphens_pos[] = { 8, 13, 18, 23 };
    struct sol_uuid uuid = { { 0 } };
    unsigned i;
    int r;

    struct sol_buffer buf = { 0 };

    sol_buffer_init_flags(&buf, id, 37,
        SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED);

    r = uuid_gen(&uuid);
    SOL_INT_CHECK(r, < 0, r);

    for (i = 0; i < SOL_UTIL_ARRAY_SIZE(uuid.bytes); i++) {
        r = sol_buffer_append_printf(&buf, upcase ? "%02hhX" : "%02hhx",
            uuid.bytes[i]);
        SOL_INT_CHECK_GOTO(r, < 0, err);
    }

    if (with_hyphens) {
        for (i = 0; i < SOL_UTIL_ARRAY_SIZE(hyphens_pos); i++) {
            r = sol_buffer_insert_slice(&buf, hyphens_pos[i], hyphen);
            SOL_INT_CHECK_GOTO(r, < 0, err);
        }
    }

err:
    sol_buffer_fini(&buf);
    return r;
}
Esempio n. 6
0
int linda_out(hlinda *h, const char *s)
{
	if (!h)
		return 0;

	json *j = json_open(s);
	json *j1 = json_get_object(j);
	json *joid = json_find(j1, LINDA_OID);
	uuid u;

	if (joid)
	{
		uuid_from_string(json_get_string(joid), &u);
	}
	else
		uuid_gen(&u);

	json *jid = json_find(j1, LINDA_ID);

	if (jid)
	{
		if (json_is_integer(jid))
		{
			long long k = json_get_integer(jid);

			if (h->l->sl && !h->l->is_int)
			{
				printf("linda_out: expected integer id\n");
				return 0;
			}

			if (!h->l->sl)
			{
				h->l->sl = sb_int_uuid_create2();
				h->l->is_int = 1;
			}

			sb_int_uuid_set(h->l->sl, k, &u);
		}
		else if (json_is_string(jid))
		{
			const char *k = json_get_string(jid);

			if (h->l->sl && !h->l->is_string)
			{
				printf("linda_out: expected string id\n");
				return 0;
			}

			if (!h->l->sl)
			{
				h->l->sl = sb_string_uuid_create2();
				h->l->is_string = 1;
			}

			sb_string_uuid_set(h->l->sl, k, &u);
		}
	}

	store_hadd(h->hst, &u, s, strlen(s));
	h->last_oid = u;
	json_close(j);
	return 0;
}
Esempio n. 7
0
    bool with_hyphens,
    char id[static 37])
{
    static struct sol_str_slice hyphen = SOL_STR_SLICE_LITERAL("-");
    /* hyphens on positions 8, 13, 18, 23 (from 0) */
    static const int hyphens_pos[] = { 8, 13, 18, 23 };
    struct sol_uuid uuid = { { 0 } };
    unsigned i;
    int r;

    struct sol_buffer buf = { 0 };

    sol_buffer_init_flags(&buf, id, 37,
        SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED);

    r = uuid_gen(&uuid);
    SOL_INT_CHECK(r, < 0, r);

    for (i = 0; i < ARRAY_SIZE(uuid.bytes); i++) {
        r = sol_buffer_append_printf(&buf, upcase ? "%02hhX" : "%02hhx",
            uuid.bytes[i]);
        SOL_INT_CHECK_GOTO(r, < 0, err);
    }

    if (with_hyphens) {
        for (i = 0; i < ARRAY_SIZE(hyphens_pos); i++) {
            r = sol_buffer_insert_slice(&buf, hyphens_pos[i], hyphen);
            SOL_INT_CHECK_GOTO(r, < 0, err);
        }
    }
Esempio n. 8
0
/* 
** Crate a UUID string based on time and MAC address values
*/
char* uuid_tm() { return uuid_gen(CMD_TIME); }
Esempio n. 9
0
/* 
** Crate a UUID string based on random values 
*/
char* uuid_r() { return uuid_gen(CMD_RANDOM); }
Esempio n. 10
0
/* Constructor */
SensorWrapper::SensorWrapper(const char* n) {
  name = n;
  uuid_gen(&uuid);
}