Author: astitcher
Date: Wed Dec 5 17:42:47 2012
New Revision: 1417551
URL: http://svn.apache.org/viewvc?rev=1417551&view=rev
Log:
PROTON-168: Allow platforms without clock_gettime() to use the obsolete
gettimeofday()
- Create platform.[ch] intended to "hide-away" platform specific API code
NO-JIRA: Improve some portability issues:
- Compile directly on FreeBSD using the built in uuid API
Added:
qpid/proton/trunk/proton-c/src/platform.c
qpid/proton/trunk/proton-c/src/platform.h
Modified:
qpid/proton/trunk/proton-c/CMakeLists.txt
qpid/proton/trunk/proton-c/include/proton/driver.h
qpid/proton/trunk/proton-c/src/driver.c
qpid/proton/trunk/proton-c/src/messenger.c
Modified: qpid/proton/trunk/proton-c/CMakeLists.txt
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/CMakeLists.txt?rev=1417551&r1=1417550&r2=1417551&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/CMakeLists.txt (original)
+++ qpid/proton/trunk/proton-c/CMakeLists.txt Wed Dec 5 17:42:47 2012
@@ -105,28 +105,37 @@ if (SWIG_FOUND)
add_subdirectory(bindings)
endif (SWIG_FOUND)
-# When checking for clock_gettime etc. first check whether the symbol
-# is present in the library that it may be in, if it is not then check
-# whether the symbol works using just the regular C library
-CHECK_LIBRARY_EXISTS (rt clock_gettime "" CLOCK_GETTIME_IN_RT)
-if (CLOCK_GETTIME_IN_RT)
- set (TIME_LIB rt)
-else (CLOCK_GETTIME_IN_RT)
- CHECK_SYMBOL_EXISTS(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
- if (NOT HAVE_CLOCK_GETTIME)
- message(FATAL_ERROR "clock_gettime() not found")
- endif (NOT HAVE_CLOCK_GETTIME)
-endif (CLOCK_GETTIME_IN_RT)
-
-CHECK_LIBRARY_EXISTS (uuid uuid_generate "" UUID_GENERATE_IN_UUID)
-if (UUID_GENERATE_IN_UUID)
- set (UUID_LIB uuid)
-else (UUID_GENERATE_IN_UUID)
- CHECK_SYMBOL_EXISTS(uuid_generate "uuid/uuid.h" HAVE_UUID_GENERATE)
- if (NOT HAVE_UUID_GENERATE)
- message(FATAL_ERROR "uuid_generate() not found")
- endif (NOT HAVE_UUID_GENERATE)
-endif (UUID_GENERATE_IN_UUID)
+# First check whether we get clock_gettime without any special library linked
+CHECK_SYMBOL_EXISTS(clock_gettime "time.h" CLOCK_GETTIME_IN_LIBC)
+if (CLOCK_GETTIME_IN_LIBC)
+ list(APPEND PLATFORM_DEFINITIONS "USE_CLOCK_GETTIME")
+else (CLOCK_GETTIME_IN_LIBC)
+ CHECK_LIBRARY_EXISTS (rt clock_gettime "" CLOCK_GETTIME_IN_RT)
+ if (CLOCK_GETTIME_IN_RT)
+ set (TIME_LIB rt)
+ list(APPEND PLATFORM_DEFINITIONS "USE_CLOCK_GETTIME")
+ else (CLOCK_GETTIME_IN_RT)
+ list(APPEND PLATFORM_DEFINITIONS "USE_GETTIMEOFDAY")
+ endif (CLOCK_GETTIME_IN_RT)
+endif (CLOCK_GETTIME_IN_LIBC)
+
+CHECK_SYMBOL_EXISTS(uuid_generate "uuid/uuid.h" UUID_GENERATE_IN_LIBC)
+if (UUID_GENERATE_IN_LIBC)
+ list(APPEND PLATFORM_DEFINITIONS "USE_UUID_GENERATE")
+else (UUID_GENERATE_IN_LIBC)
+ CHECK_LIBRARY_EXISTS (uuid uuid_generate "" UUID_GENERATE_IN_UUID)
+ if (UUID_GENERATE_IN_UUID)
+ set (UUID_LIB uuid)
+ list(APPEND PLATFORM_DEFINITIONS "USE_UUID_GENERATE")
+ else (UUID_GENERATE_IN_UUID)
+ CHECK_SYMBOL_EXISTS(uuid_create "uuid.h" UUID_CREATE_IN_LIBC)
+ if (UUID_CREATE_IN_LIBC)
+ list(APPEND PLATFORM_DEFINITIONS "USE_UUID_CREATE")
+ else (UUID_CREATE_IN_LIBC)
+ message(FATAL_ERROR "neither uuid_generate() nor uuid_create() found")
+ endif (UUID_CREATE_IN_LIBC)
+ endif (UUID_GENERATE_IN_UUID)
+endif (UUID_GENERATE_IN_LIBC)
# Set any additional platform specific C compiler flags
if (CMAKE_COMPILER_IS_GNUCC)
@@ -141,6 +150,7 @@ add_subdirectory(examples/messenger/c)
set (qpid-proton-platform
src/driver.c
+ src/platform.c
${pn_driver_ssl_impl}
)
@@ -177,6 +187,7 @@ set_source_files_properties (
${qpid-proton-platform}
PROPERTIES
COMPILE_FLAGS "${COMPILE_WARNING_FLAGS} ${COMPILE_PLATFORM_FLAGS}"
+ COMPILE_DEFINITIONS "${PLATFORM_DEFINITIONS}"
)
add_library (
Modified: qpid/proton/trunk/proton-c/include/proton/driver.h
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/include/proton/driver.h?rev=1417551&r1=1417550&r2=1417551&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/include/proton/driver.h (original)
+++ qpid/proton/trunk/proton-c/include/proton/driver.h Wed Dec 5 17:42:47 2012
@@ -121,16 +121,6 @@ pn_listener_t *pn_driver_listener(pn_dri
*/
pn_connector_t *pn_driver_connector(pn_driver_t *driver);
-/** Get the current time in pn_timestamp_t format.
- *
- * Returns current time in milliseconds since Unix Epoch,
- * as defined by AMQP 1.0
- *
- * @param[in] driver the driver
- * @return current time
- */
-pn_timestamp_t pn_driver_now(pn_driver_t *driver);
-
/** Free the driver allocated via pn_driver, and all associated
* listeners and connectors.
*
Modified: qpid/proton/trunk/proton-c/src/driver.c
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/driver.c?rev=1417551&r1=1417550&r2=1417551&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/driver.c (original)
+++ qpid/proton/trunk/proton-c/src/driver.c Wed Dec 5 17:42:47 2012
@@ -22,7 +22,6 @@
#include <assert.h>
#include <poll.h>
#include <stdio.h>
-#include <time.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
@@ -37,6 +36,7 @@
#include <proton/ssl.h>
#include <proton/util.h>
#include "util.h"
+#include "platform.h"
#include "ssl/ssl-internal.h"
/* Decls */
@@ -615,7 +615,7 @@ void pn_connector_process(pn_connector_t
}
pn_connector_process_input(c);
- c->wakeup = pn_connector_tick(c, pn_driver_now(c->driver));
+ c->wakeup = pn_connector_tick(c, pn_i_now());
pn_connector_process_output(c);
if (c->pending_write) {
@@ -759,7 +759,7 @@ void pn_driver_wait_1(pn_driver_t *d)
int pn_driver_wait_2(pn_driver_t *d, int timeout)
{
if (d->wakeup) {
- pn_timestamp_t now = pn_driver_now(d);
+ pn_timestamp_t now = pn_i_now();
if (now >= d->wakeup)
timeout = 0;
else
@@ -784,7 +784,7 @@ void pn_driver_wait_3(pn_driver_t *d)
l = l->listener_next;
}
- pn_timestamp_t now = pn_driver_now(d);
+ pn_timestamp_t now = pn_i_now();
pn_connector_t *c = d->connector_head;
while (c) {
if (c->closed) {
@@ -854,10 +854,3 @@ pn_connector_t *pn_driver_connector(pn_d
return NULL;
}
-
-pn_timestamp_t pn_driver_now(pn_driver_t *driver)
-{
- struct timespec now;
- if (clock_gettime(CLOCK_REALTIME, &now)) pn_fatal("clock_gettime()
failed\n");
- return ((pn_timestamp_t)now.tv_sec) * 1000 + (now.tv_nsec / 1000000);
-}
Modified: qpid/proton/trunk/proton-c/src/messenger.c
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/messenger.c?rev=1417551&r1=1417550&r2=1417551&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/messenger.c (original)
+++ qpid/proton/trunk/proton-c/src/messenger.c Wed Dec 5 17:42:47 2012
@@ -29,8 +29,8 @@
#include <string.h>
#include <stdio.h>
#include <sys/time.h>
-#include <uuid/uuid.h>
#include "util.h"
+#include "platform.h"
typedef struct {
size_t capacity;
@@ -230,11 +230,7 @@ static char *build_name(const char *name
if (name) {
return pn_strdup(name);
} else {
- char *generated = malloc(37*sizeof(char));
- uuid_t uuid;
- uuid_generate(uuid);
- uuid_unparse_lower(uuid, generated);
- return generated;
+ return pn_i_genuuid();
}
}
@@ -475,7 +471,7 @@ int pn_messenger_tsync(pn_messenger_t *m
ctor = pn_connector_next(ctor);
}
- pn_timestamp_t now = pn_driver_now(messenger->driver);
+ pn_timestamp_t now = pn_i_now();
long int deadline = now + timeout;
bool pred;
@@ -530,7 +526,7 @@ int pn_messenger_tsync(pn_messenger_t *m
}
if (timeout >= 0) {
- now = pn_driver_now(messenger->driver);
+ now = pn_i_now();
}
}
Added: qpid/proton/trunk/proton-c/src/platform.c
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/platform.c?rev=1417551&view=auto
==============================================================================
--- qpid/proton/trunk/proton-c/src/platform.c (added)
+++ qpid/proton/trunk/proton-c/src/platform.c Wed Dec 5 17:42:47 2012
@@ -0,0 +1,67 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "platform.h"
+#include "util.h"
+#include "proton/util.h" // for pn_fatal() ?should pn_fatal() be public?
+
+/* Allow for systems that do not implement clock_gettime()*/
+#ifdef USE_CLOCK_GETTIME
+#include <time.h>
+pn_timestamp_t pn_i_now(void)
+{
+ struct timespec now;
+ if (clock_gettime(CLOCK_REALTIME, &now)) pn_fatal("clock_gettime()
failed\n");
+ return ((pn_timestamp_t)now.tv_sec) * 1000 + (now.tv_nsec / 1000000);
+}
+#else
+#include <sys/time.h>
+pn_timestamp_t pn_i_now(void)
+{
+ struct timeval now;
+ if (gettimeofday(&now, NULL)) pn_fatal("gettimeofday failed\n");
+ return ((pn_timestamp_t)now.tv_sec) * 1000 + (now.tv_usec / 1000);
+}
+#endif
+
+#ifdef USE_UUID_GENERATE
+#include <uuid/uuid.h>
+#include <stdlib.h>
+char* pn_i_genuuid(void) {
+ char *generated = malloc(37*sizeof(char));
+ uuid_t uuid;
+ uuid_generate(uuid);
+ uuid_unparse_lower(uuid, generated);
+ return generated;
+}
+#elif USE_UUID_CREATE
+#include <uuid.h>
+char* pn_i_genuuid(void) {
+ char *generated;
+ uuid_t uuid;
+ uint32_t rc;
+ uuid_create(&uuid, &rc);
+ uuid_to_string(&uuid, &generated, &rc);
+ return pn_strdup(generated);
+}
+#else
+#error "Don't know how to generate uuid strings on this platform"
+#endif
Added: qpid/proton/trunk/proton-c/src/platform.h
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/platform.h?rev=1417551&view=auto
==============================================================================
--- qpid/proton/trunk/proton-c/src/platform.h (added)
+++ qpid/proton/trunk/proton-c/src/platform.h Wed Dec 5 17:42:47 2012
@@ -0,0 +1,56 @@
+#ifndef PROTON_PLATFORM_H
+#define PROTON_PLATFORM_H 1
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "proton/types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** Get the current time in pn_timestamp_t format.
+ *
+ * Returns current time in milliseconds since Unix Epoch,
+ * as defined by AMQP 1.0
+ *
+ * @return current time
+ * @internal
+ */
+pn_timestamp_t pn_i_now(void);
+
+/** Generate a UUID in string format.
+ *
+ * Returns a newly generated UUID in the standard 36 char format.
+ * The returned char* array is zero terminated.
+ * (eg. d797830d-0f5b-49d4-a83f-adaa78425125)
+ *
+ * @return newly generated stringised UUID
+ * @internal
+ */
+char* pn_i_genuuid(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* driver.h */
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]