int main(int argc, char *argv[]) { uuid_t a, b, c; char buf[100]; char in[100]; char out[100]; int x,y; #ifdef __APPLE__ uuid_generate(a); uuid_generate(b); #else uuid_generate_time_safe(a); uuid_generate_time_safe(b); #endif uuid_unparse(a, buf); printf("%s\n", buf); pr_uuid(a); uuid_unparse(b, buf); printf("%s\n", buf); pr_uuid(b); snprintf(in, sizeof(in), "XYZZY.%s:%d:%d", buf, 3, 4); printf("%s\n", in); get_uuid(&in[6], c); sscanf(&in[42], ":%d:%d", &x, &y); uuid_unparse(c, out); printf("%s:%d:%d\n", out, x, y); uuid_unparse(a, buf); snprintf(in, sizeof(in), "XYZZY.%s", buf); sscanf(in, "XYZZY.%s", out); if (strcmp(buf, out) != 0) { printf("Error %s != %s\n", buf, out); } return 0; }
/* **************************************************************************** * * correlatorGenerate - */ static void correlatorGenerate(char* buffer) { uuid_t uuid; uuid_generate_time_safe(uuid); uuid_unparse_lower(uuid, buffer); }
char *getUniqueId(void) { char *key; uuid_t id; size_t i; char *tmp; if ((uuid_generate_time_safe(id)) == 0) printf("\t\tuuid WAS successfully generated safely\n"); else printf("\t\tuuid was NOT generated safely\n"); if (!(key = malloc(sizeof(uuid_t) * 2 + 1))) return NULL; tmp = key; for (i = 0; i < sizeof(uuid_t); i ++) { sprintf(tmp, "%02x", id[i]); tmp += 2; } tmp -= 1; *tmp = '\0'; printf("\t\t\tReturning unique ID : %s\n", key); return key; }
struct sg_uuid_str sg_uuid_gen(enum sg_uuid_method method, int uppercase) { uuid_t uu; struct sg_uuid_str us; assert(method >= SGUUIDMETHOD_DEFAULT && method <= SGUUIDMETHOD_TIME_MAC); memset(&us, 0, sizeof(struct sg_uuid_str)); switch (method) { case SGUUIDMETHOD_DEFAULT: uuid_generate(uu); break; case SGUUIDMETHOD_RANDOM: uuid_generate_random(uu); break; case SGUUIDMETHOD_TIME_MAC: uuid_generate_time(uu); break; case SGUUIDMETHOD_TIME_MAC_SAFE: uuid_generate_time_safe(uu); break; default: sg_log_err("UUID method error."); return us; } if (uppercase == 0) uuid_unparse_lower(uu, us.buf); else uuid_unparse_upper(uu, us.buf); return us; }
//send message bool activemq_sync_producer::send_message(const std::string& request, std::string& response, int time) { try { char uuid_str[37]; uuid_str[36] = 0; uuid_clear(_uuid); uuid_generate_time_safe(_uuid); uuid_unparse(_uuid, uuid_str); //发送消息 std::auto_ptr<cms::TextMessage> ptr_message(_ptr_session->createTextMessage(request)); ptr_message->setCMSReplyTo(_ptr_recv_queue.get()); ptr_message->setCMSCorrelationID(uuid_str); _ptr_send_message->send(ptr_message.get()); bool recv_data = false; while (1) { std::auto_ptr<cms::TextMessage> recv_message(dynamic_cast<cms::TextMessage*>(_ptr_recv_message->receive(time))); if (NULL != recv_message.get()) { if (recv_message->getCMSCorrelationID().compare(uuid_str) == 0) { response = recv_message->getText(); recv_data = true; break; } else { } } else { break; } } return recv_data; } catch (cms::CMSException& e) { printf("Producer run() CMSException \n"); e.printStackTrace(); return false; } }
/** * ags_id_generator_create_uuid: * * Creates an new string containing UUID. * * Returns: a new string * * Since: 0.4 */ gchar* ags_id_generator_create_uuid() { uuid_t out; gchar *uuid_str; /* make sure uuid is really unique */ while(uuid_generate_time_safe(out) != 0); /* create a string representation */ uuid_str = (gchar *) malloc((AGS_ID_GENERATOR_DEFAULT_UUID_LENGTH + 1) * sizeof(gchar)); uuid_unparse(out, uuid_str); uuid_str[AGS_ID_GENERATOR_DEFAULT_UUID_LENGTH] = '\0'; return(uuid_str); }
static PyObject * py_uuid_generate_time_safe(void) { uuid_t uuid; #ifdef HAVE_UUID_GENERATE_TIME_SAFE int res; res = uuid_generate_time_safe(uuid); return Py_BuildValue("y#i", (const char *) uuid, sizeof(uuid), res); #elif HAVE_UUID_CREATE uint32_t status; uuid_create(&uuid, &status); return Py_BuildValue("y#i", (const char *) &uuid, sizeof(uuid), (int) status); #else uuid_generate_time(uuid); return Py_BuildValue("y#O", (const char *) uuid, sizeof(uuid), Py_None); #endif }
void uuid_generate_time(uuid_t out){ uuid_generate_time_safe(out); }