You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by cl...@apache.org on 2013/07/16 02:55:04 UTC

svn commit: r1503531 - in /qpid/proton/trunk: examples/include/ examples/include/pncompat/ examples/include/pncompat/internal/ examples/messenger/c/ proton-c/ proton-c/include/proton/ proton-c/src/ proton-c/wincompat/ proton-c/wincompat/internal/ tests...

Author: cliffjansen
Date: Tue Jul 16 00:55:03 2013
New Revision: 1503531

URL: http://svn.apache.org/r1503531
Log:
PROTON-348: Platform neutral helper functions for examples and tests.

Added:
    qpid/proton/trunk/examples/include/
    qpid/proton/trunk/examples/include/pncompat/
    qpid/proton/trunk/examples/include/pncompat/internal/
    qpid/proton/trunk/examples/include/pncompat/internal/LICENSE
      - copied unchanged from r1503530, qpid/proton/trunk/proton-c/wincompat/internal/LICENSE
    qpid/proton/trunk/examples/include/pncompat/internal/getopt.c
      - copied unchanged from r1503530, qpid/proton/trunk/proton-c/wincompat/internal/getopt.c
    qpid/proton/trunk/examples/include/pncompat/internal/getopt.h
      - copied unchanged from r1503530, qpid/proton/trunk/proton-c/wincompat/internal/getopt.h
    qpid/proton/trunk/examples/include/pncompat/misc_defs.h
      - copied, changed from r1503530, qpid/proton/trunk/proton-c/wincompat/getopt.h
    qpid/proton/trunk/examples/include/pncompat/misc_funcs.inc
Removed:
    qpid/proton/trunk/proton-c/wincompat/getopt.h
    qpid/proton/trunk/proton-c/wincompat/internal/LICENSE
    qpid/proton/trunk/proton-c/wincompat/internal/getopt.c
    qpid/proton/trunk/proton-c/wincompat/internal/getopt.h
Modified:
    qpid/proton/trunk/examples/messenger/c/recv.c
    qpid/proton/trunk/examples/messenger/c/send.c
    qpid/proton/trunk/proton-c/CMakeLists.txt
    qpid/proton/trunk/proton-c/include/proton/object.h
    qpid/proton/trunk/proton-c/src/proton.c
    qpid/proton/trunk/tests/tools/apps/c/msgr-common.c
    qpid/proton/trunk/tests/tools/apps/c/msgr-common.h

Copied: qpid/proton/trunk/examples/include/pncompat/misc_defs.h (from r1503530, qpid/proton/trunk/proton-c/wincompat/getopt.h)
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/examples/include/pncompat/misc_defs.h?p2=qpid/proton/trunk/examples/include/pncompat/misc_defs.h&p1=qpid/proton/trunk/proton-c/wincompat/getopt.h&r1=1503530&r2=1503531&rev=1503531&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/wincompat/getopt.h (original)
+++ qpid/proton/trunk/examples/include/pncompat/misc_defs.h Tue Jul 16 00:55:03 2013
@@ -1,5 +1,7 @@
+#ifndef PNCOMAPT_MISC_DEFS_H
+#define PNCOMAPT_MISC_DEFS_H
+
 /*
- *
  * 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
@@ -19,21 +21,28 @@
  *
  */
 
+#if defined(qpid_proton_EXPORTS)
+#error This include file is not for use in the main proton library
+#endif
+
 /*
- * Provides an embedded getopt implementation to the C file including
- * this.  Only intended for use by Proton examples and test/debug
- * programs to run on Windows.
+ * Platform neutral definitions. Only intended for use by Proton
+ * examples and test/debug programs.
  *
- * This file and any internal support files may change or be removed
+ * This file and any related support files may change or be removed
  * at any time.
  */
 
-#if defined(qpid_proton_EXPORTS)
-#error This include file is not for use in the main proton library
-#endif
+// getopt()
+
+#include <proton/types.h>
 
 #if !defined(_WIN32) || defined (__CYGWIN__)
-#error This include file only intended for Windows compatibility.
+#include <getopt.h>
+#else
+#include "internal/getopt.h"
 #endif
 
-#include "internal/getopt.c"
+pn_timestamp_t time_now();
+
+#endif /* PNCOMPAT_MISC_DEFS_H */

Added: qpid/proton/trunk/examples/include/pncompat/misc_funcs.inc
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/examples/include/pncompat/misc_funcs.inc?rev=1503531&view=auto
==============================================================================
--- qpid/proton/trunk/examples/include/pncompat/misc_funcs.inc (added)
+++ qpid/proton/trunk/examples/include/pncompat/misc_funcs.inc Tue Jul 16 00:55:03 2013
@@ -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.
+ *
+ */
+
+/*
+ * This file provides the functions for "misc_defs.h" in the form of
+ * included code, as opposed to a separate library or object
+ * dependency.  In the absence of portable "pragma weak" compiler
+ * directives, this provides a simple workaround.
+ *
+ * Usage for a single compilation unit:
+ *
+ *  #include "pncompat/misc_funcs.inc"
+ *
+ * Usage for multiple combined compilation units: chose one to include
+ * "pncompat/misc_funcs.inc" as above and in each other unit needing the
+ * definitions use
+ *
+ *  #include "pncompat/misc_defs.h"
+ *
+ */
+
+#include "misc_defs.h"
+
+#if defined(_WIN32) && ! defined(__CYGWIN__)
+#include "pncompat/internal/getopt.c"
+#endif
+
+#if defined(_WIN32) && ! defined(__CYGWIN__)
+#include <windows.h>
+pn_timestamp_t time_now(void)
+{
+  FILETIME now;
+  GetSystemTimeAsFileTime(&now);
+  ULARGE_INTEGER t;
+  t.u.HighPart = now.dwHighDateTime;
+  t.u.LowPart = now.dwLowDateTime;
+  // Convert to milliseconds and adjust base epoch
+  return t.QuadPart / 10000 - 11644473600000;
+}
+#else
+#include <proton/util.h>
+#include <sys/time.h>
+#include <stddef.h>
+pn_timestamp_t time_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

Modified: qpid/proton/trunk/examples/messenger/c/recv.c
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/examples/messenger/c/recv.c?rev=1503531&r1=1503530&r2=1503531&view=diff
==============================================================================
--- qpid/proton/trunk/examples/messenger/c/recv.c (original)
+++ qpid/proton/trunk/examples/messenger/c/recv.c Tue Jul 16 00:55:03 2013
@@ -21,11 +21,7 @@
 #include "proton/message.h"
 #include "proton/messenger.h"
 
-#if defined(_WIN32) && ! defined(__CYGWIN__)
-#include "../../../proton-c/wincompat/getopt.h"
-#else
-#include <getopt.h>
-#endif
+#include "pncompat/misc_funcs.inc"
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>

Modified: qpid/proton/trunk/examples/messenger/c/send.c
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/examples/messenger/c/send.c?rev=1503531&r1=1503530&r2=1503531&view=diff
==============================================================================
--- qpid/proton/trunk/examples/messenger/c/send.c (original)
+++ qpid/proton/trunk/examples/messenger/c/send.c Tue Jul 16 00:55:03 2013
@@ -21,11 +21,7 @@
 #include "proton/message.h"
 #include "proton/messenger.h"
 
-#if defined(_WIN32) && ! defined(__CYGWIN__)
-#include "../../../proton-c/wincompat/getopt.h"
-#else
-#include <getopt.h>
-#endif
+#include "pncompat/misc_funcs.inc"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>

Modified: qpid/proton/trunk/proton-c/CMakeLists.txt
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/CMakeLists.txt?rev=1503531&r1=1503530&r2=1503531&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/CMakeLists.txt (original)
+++ qpid/proton/trunk/proton-c/CMakeLists.txt Tue Jul 16 00:55:03 2013
@@ -57,6 +57,7 @@ configure_file (
 
 include_directories ("${CMAKE_CURRENT_BINARY_DIR}")
 include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/include")
+include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/../examples/include")
 
 add_custom_command (
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/encodings.h

Modified: qpid/proton/trunk/proton-c/include/proton/object.h
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/include/proton/object.h?rev=1503531&r1=1503530&r2=1503531&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/include/proton/object.h (original)
+++ qpid/proton/trunk/proton-c/include/proton/object.h Tue Jul 16 00:55:03 2013
@@ -22,11 +22,14 @@
  *
  */
 
+#include <proton/types.h>
+#ifndef __cplusplus
 #include <stdbool.h>
-#include <stddef.h>
 #include <stdint.h>
-#include <sys/types.h>
-
+#else
+#include <proton/type_compat.h>
+#endif
+#include <stddef.h>
 #include <proton/import_export.h>
 
 #ifdef __cplusplus
@@ -102,7 +105,10 @@ PN_EXTERN int pn_string_setn(pn_string_t
 PN_EXTERN ssize_t pn_string_put(pn_string_t *string, char *dst);
 PN_EXTERN void pn_string_clear(pn_string_t *string);
 PN_EXTERN int pn_string_format(pn_string_t *string, const char *format, ...)
-  __attribute__ ((format (printf, 2, 3)));
+#ifdef __GNUC__
+  __attribute__ ((format (printf, 2, 3)))
+#endif
+    ;
 PN_EXTERN char *pn_string_buffer(pn_string_t *string);
 PN_EXTERN size_t pn_string_capacity(pn_string_t *string);
 PN_EXTERN int pn_string_resize(pn_string_t *string, size_t size);

Modified: qpid/proton/trunk/proton-c/src/proton.c
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/proton.c?rev=1503531&r1=1503530&r2=1503531&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/proton.c (original)
+++ qpid/proton/trunk/proton-c/src/proton.c Tue Jul 16 00:55:03 2013
@@ -22,7 +22,7 @@
 #if defined(_WIN32) && ! defined(__CYGWIN__)
 #define NOGDI
 #include <winsock2.h>
-#include "../wincompat/getopt.h"
+#include "pncompat/misc_funcs.inc"
 #else
 #include <unistd.h>
 #include <libgen.h>

Modified: qpid/proton/trunk/tests/tools/apps/c/msgr-common.c
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/tests/tools/apps/c/msgr-common.c?rev=1503531&r1=1503530&r2=1503531&view=diff
==============================================================================
--- qpid/proton/trunk/tests/tools/apps/c/msgr-common.c (original)
+++ qpid/proton/trunk/tests/tools/apps/c/msgr-common.c Tue Jul 16 00:55:03 2013
@@ -19,11 +19,11 @@
  */
 
 #include "msgr-common.h"
+#include <pncompat/misc_funcs.inc>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/time.h>
 #include <assert.h>
 
 void msgr_die(const char *file, int line, const char *message)
@@ -43,12 +43,11 @@ char *msgr_strdup( const char *src )
   return r;
 }
 
-//sigh part deux - would be nice if proton exported pn_i_now()
+
 pn_timestamp_t msgr_now()
 {
-  struct timeval now;
-  if (gettimeofday(&now, NULL)) abort();
-  return ((pn_timestamp_t)now.tv_sec) * 1000 + (now.tv_usec / 1000);
+  // from "pncompat/misc_funcs.inc"
+  return time_now();
 }
 
 void addresses_init( Addresses_t *a )

Modified: qpid/proton/trunk/tests/tools/apps/c/msgr-common.h
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/tests/tools/apps/c/msgr-common.h?rev=1503531&r1=1503530&r2=1503531&view=diff
==============================================================================
--- qpid/proton/trunk/tests/tools/apps/c/msgr-common.h (original)
+++ qpid/proton/trunk/tests/tools/apps/c/msgr-common.h Tue Jul 16 00:55:03 2013
@@ -18,17 +18,21 @@
  *
  */
 
-#if defined(_WIN32) && ! defined(__CYGWIN__)
-#include "../wincompat/getopt.h"
-#else
-#include <getopt.h>
-#endif
+#include "pncompat/misc_defs.h"
 
 #if defined(USE_INTTYPES)
+#ifdef __cplusplus
+#define __STDC_FORMAT_MACROS
+#endif
 #include <inttypes.h>
 #endif
 
-/* should be defined in inttypes.h, if not, best guess */
+#ifdef _MSC_VER
+#define PRIu64 "I64u"
+#define SCNu64 "I64u"
+#endif
+
+/* If still not defined, best guess */
 #if !defined(SCNu64)
 #define SCNu64 "ul"
 #endif



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org