qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fad...@apache.org
Subject svn commit: r1544669 - in /qpid/proton/branches/fadams-javascript-binding/proton-c: ./ bindings/javascript/ bindings/javascript/examples/ bindings/javascript/uuid/ bindings/javascript/uuid/include/ bindings/javascript/uuid/include/uuid/ bindings/javasc...
Date Fri, 22 Nov 2013 20:24:29 GMT
Author: fadams
Date: Fri Nov 22 20:24:28 2013
New Revision: 1544669

URL: http://svn.apache.org/r1544669
Log:
commit working proof of concept emscripten based javascript proton binding

Added:
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/LICENSE   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/README   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/TODO   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/recv-async.c   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/send-async.c   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/my-library.js   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/include/
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/include/uuid/
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/include/uuid/uuid.h   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/src/
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/src/library_uuid.js   (with props)
Modified:
    qpid/proton/branches/fadams-javascript-binding/proton-c/CMakeLists.txt

Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/CMakeLists.txt
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/CMakeLists.txt?rev=1544669&r1=1544668&r2=1544669&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/CMakeLists.txt (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/CMakeLists.txt Fri Nov 22 20:24:28 2013
@@ -220,6 +220,29 @@ if (SWIG_FOUND)
   add_subdirectory(bindings)
 endif (SWIG_FOUND)
 
+# TODO Make these tests more idiomatic cmake as per comments by Andrew Stitcher.
+# Build the JavaScript language binding.
+# This is somewhat different to the other language bindings in that it does not use swig. It uses a C/C++ to
+# JavaScript cross-compiler called emscripten (https://github.com/kripken/emscripten). Emscripten takes C/C++
+# and "compiles" it into a highly optimisable subset of JavaScript called asm.js (http://asmjs.org/) that can
+# be aggressively optimised and run at near-native speed (usually between 1.5 to 10 times slower than native C/C++).
+option("BUILD_JAVASCRIPT" "Build JavaScript language binding" ON)
+if (BUILD_JAVASCRIPT)
+  # First check that Node.js is installed as that is needed by emscripten.
+  find_program(NODE node)
+  if (NOT NODE)
+    message(STATUS "Node.js (http://nodejs.org) is not installed: can't build JavaScript binding")
+  else (NOT NODE)
+    # Check that the emscripten C/C++ to JavaScript cross-compiler is installed.
+    find_program(EMCC emcc)
+    if (NOT EMCC)
+      message(STATUS "Emscripten (https://github.com/kripken/emscripten) is not installed: can't build JavaScript binding")
+    else (NOT EMCC)
+      add_subdirectory(bindings/javascript)
+    endif (NOT EMCC)
+  endif (NOT NODE)
+endif (BUILD_JAVASCRIPT)
+
 add_subdirectory(docs/api)
 add_subdirectory(docs/man)
 add_subdirectory(../examples/messenger/c examples/messenger/c)

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt?rev=1544669&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt Fri Nov 22 20:24:28 2013
@@ -0,0 +1,216 @@
+#
+# 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 allows cross-compiling of proton to JavaScript using emscripten (https://github.com/kripken/emscripten)
+# As it is really a cross-compilation (as opposed to a binding a la swig) the approach is rather different and
+# somewhat replicates the main build in the proton-c/CMakeLists.txt using quite a bit of "copy and paste reuse".
+# TODO refactor this file (and proton-c/CMakeLists.txt) to keep the main compilation and cross-compilation consistent.
+
+message(STATUS "Found emscripten, using that to build JavaScript binding")
+
+# Specify the compiler to use for cross-compilation.
+set(CMAKE_C_COMPILER "${EMCC}")
+
+# Specify the archiver to use for cross-compilation.
+find_program(EMAR emar)
+set(CMAKE_AR "${EMAR}")
+
+# Specify the ranlib to use for cross-compilation.
+find_program(EMRANLIB emranlib)
+set(CMAKE_RANLIB "${EMRANLIB}")
+
+# Don't do compiler autodetection, since we are cross-compiling.
+include(CMakeForceCompiler)
+CMAKE_FORCE_C_COMPILER("${CMAKE_C_COMPILER}" Clang)
+
+# Specify the program to use when building static libraries. Force Emscripten-related command line options to clang.
+set(CMAKE_C_ARCHIVE_CREATE "${CMAKE_AR} rc <TARGET> ${CMAKE_START_TEMP_FILE} <LINK_FLAGS> <OBJECTS>${CMAKE_END_TEMP_FILE}")
+
+# From this point we should be using emscripten compilation tools rather than default ones
+message(STATUS "emscripten compilation environment:")
+message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
+message(STATUS "CMAKE_AR: ${CMAKE_AR}")
+message(STATUS "CMAKE_RANLIB: ${CMAKE_RANLIB}")
+message(STATUS "CMAKE_C_ARCHIVE_CREATE: ${CMAKE_C_ARCHIVE_CREATE}")
+
+# Set this to the proton-c directory, we're cross-compiling code from there.
+set(PN_PATH ${CMAKE_SOURCE_DIR}/proton-c)
+
+
+# TODO the OpenSSL stuff won't work for emscripten by default. It might well be possible to compile it from
+# source using emscripten (that's the standard practice for libraries with emscripten) see the comments in
+# https://github.com/kripken/emscripten/wiki/FAQ "Q. How do I link against system libraries like SDL, boost, etc.?"
+# Though to be honest it might be more natural to simply use a TLS protected wss:// WebSocket URL.
+#  set(pn_driver_ssl_impl src/ssl/openssl.c)
+#  set(SSL_LIB ${OPENSSL_LIBRARIES})
+set(pn_driver_ssl_impl ${PN_PATH}/src/ssl/ssl_stub.c)
+set(SSL_LIB "")
+
+# emscripten is Linux like so use the posix driver.
+set(pn_driver_impl ${PN_PATH}/src/posix/driver.c)
+
+
+# Use stub UUID library (implemented in JavaScript)
+# TODO push proper libuuid back to emscripten and remove this from here.
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/uuid/include")
+set(UUID_LIB "")
+set(UUID_STUB_LIB ${CMAKE_CURRENT_SOURCE_DIR}/uuid/src/library_uuid.js)
+
+# The time lib is in the standard emscripten libraries.
+set(TIME_LIB "")
+
+# Generate encodings.h and protocol.h
+# It may be possible to use the ones generated for the main proton-c build but qpid-proton-core has
+# a dependency on the generated files so I'm not sure if it'll work without a command that can
+# be run as a dependency. Probably best do it this way when cross-compiling - though more copy'n'paste
+add_custom_command(
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/encodings.h
+  COMMAND python ${PN_PATH}/env.py PYTHONPATH=${PN_PATH} python ${PN_PATH}/src/codec/encodings.h.py > ${CMAKE_CURRENT_BINARY_DIR}/encodings.h
+  DEPENDS ${PN_PATH}/src/codec/encodings.h.py
+  )
+
+add_custom_command(
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/protocol.h
+  COMMAND python ${PN_PATH}/env.py PYTHONPATH=${PN_PATH} python ${PN_PATH}/src/protocol.h.py > ${CMAKE_CURRENT_BINARY_DIR}/protocol.h
+  DEPENDS ${PN_PATH}/src/protocol.h.py
+  )
+
+# TODO put back -Werror once offending warnings get eliminated.
+#set(COMPILE_WARNING_FLAGS "-Werror -Wall -pedantic-errors -Wno-comment -Wno-warn-absolute-paths")
+set(COMPILE_WARNING_FLAGS "-Wall -pedantic-errors -Wno-comment -Wno-warn-absolute-paths")
+
+# Explicitly set PLATFORM_DEFINITIONS to Linux ones for emscripten as we don't want to inadvertently use
+# Windows versions if we happen to be cross-compiling from a Windows platform
+set(PLATFORM_DEFINITIONS "USE_CLOCK_GETTIME;USE_UUID_GENERATE;USE_STRERROR_R;USE_ATOLL")
+
+# TODO temporary messages - remove.
+message(STATUS "COMPILE_WARNING_FLAGS: ${COMPILE_WARNING_FLAGS}")
+message(STATUS "PLATFORM_DEFINITIONS: ${PLATFORM_DEFINITIONS}")
+message(STATUS "UUID_LIB: ${UUID_LIB}")
+message(STATUS "SSL_LIB: ${SSL_LIB}")
+message(STATUS "TIME_LIB: ${TIME_LIB}")
+message(STATUS "PLATFORM_LIBS: ${PLATFORM_LIBS}") # can be empty for emscripten
+
+
+
+# The following is copied from the the main proton-c/CMakeLists.txt and annotated where there are differences
+# to make it easier to refactor if we want to keep the main compilation and cross-compilation consistent.
+# The main differences are prefixing paths with ${PN_PATH}/ as we can't use a relative path from this
+# CMakeLists.txt and marking the library as "STATIC", as the library is really LLVM bitcode.
+
+set(qpid-proton-platform
+  ${pn_driver_impl}
+  ${PN_PATH}/src/platform.c
+  ${pn_driver_ssl_impl}
+  )
+
+set(qpid-proton-core
+  ${PN_PATH}/src/object/object.c
+
+  ${PN_PATH}/src/util.c
+  ${PN_PATH}/src/error.c
+  ${PN_PATH}/src/buffer.c
+  ${PN_PATH}/src/parser.c
+  ${PN_PATH}/src/scanner.c
+  ${PN_PATH}/src/types.c
+
+  ${PN_PATH}/src/framing/framing.c
+
+  ${PN_PATH}/src/codec/codec.c
+  ${PN_PATH}/src/codec/decoder.c
+  ${PN_PATH}/src/codec/encoder.c
+
+  ${PN_PATH}/src/dispatcher/dispatcher.c
+  ${PN_PATH}/src/engine/engine.c
+  ${PN_PATH}/src/transport/transport.c
+  ${PN_PATH}/src/message/message.c
+  ${PN_PATH}/src/sasl/sasl.c
+
+  ${PN_PATH}/src/messenger/messenger.c
+  ${PN_PATH}/src/messenger/subscription.c
+  ${PN_PATH}/src/messenger/store.c
+  ${PN_PATH}/src/messenger/transform.c
+
+  ${CMAKE_CURRENT_BINARY_DIR}/encodings.h
+  ${CMAKE_CURRENT_BINARY_DIR}/protocol.h
+  )
+
+set_source_files_properties(
+  ${qpid-proton-core}
+  PROPERTIES
+  COMPILE_FLAGS "${COMPILE_WARNING_FLAGS} ${COMPILE_LANGUAGE_FLAGS}"
+  )
+
+set_source_files_properties(
+  ${qpid-proton-platform}
+  PROPERTIES
+  COMPILE_FLAGS "${COMPILE_WARNING_FLAGS} ${COMPILE_PLATFORM_FLAGS}"
+  COMPILE_DEFINITIONS "${PLATFORM_DEFINITIONS}"
+  )
+
+add_library(
+  qpid-proton-js SHARED
+
+  ${qpid-proton-core}
+  ${qpid-proton-platform}
+  )
+
+target_link_libraries(qpid-proton-js ${UUID_LIB} ${SSL_LIB} ${TIME_LIB} ${PLATFORM_LIBS})
+
+set_target_properties(
+  qpid-proton-js
+  PROPERTIES
+  VERSION   "${PN_LIB_SOMAJOR}.${PN_LIB_SOMINOR}"
+  SOVERSION "${PN_LIB_SOMAJOR}"
+  LINK_FLAGS "${CATCH_UNDEFINED}"
+  )
+
+#add_executable(proton.js ${PN_PATH}/src/proton.c)
+#target_link_libraries(proton.js qpid-proton-js)
+
+#add_executable(proton-dump.js ${PN_PATH}/src/proton-dump.c)
+#target_link_libraries(proton-dump.js qpid-proton-js)
+
+add_executable(send-async.js examples/send-async.c)
+target_link_libraries(send-async.js qpid-proton-js)
+
+add_executable(recv-async.js examples/recv-async.c)
+target_link_libraries(recv-async.js qpid-proton-js)
+
+#add_executable(msgr-send.js ${PN_PATH}/../tests/tools/apps/c/msgr-common.c ${PN_PATH}/../tests/tools/apps/c/msgr-send.c)
+#target_link_libraries(msgr-send.js qpid-proton-js)
+
+#add_executable(msgr-recv.js ${PN_PATH}/../tests/tools/apps/c/msgr-common.c ${PN_PATH}/../tests/tools/apps/c/msgr-recv.c)
+#target_link_libraries(msgr-recv.js qpid-proton-js)
+
+# TODO get the uuid library and the patches in my-library.js pushed properly into emscripten ASAP
+set_target_properties(
+  send-async.js recv-async.js
+  PROPERTIES
+  COMPILE_FLAGS "${COMPILE_WARNING_FLAGS} ${COMPILE_PLATFORM_FLAGS}"
+  LINK_FLAGS "-s SOCKET_DEBUG=1 --js-library ${UUID_STUB_LIB} --js-library ${CMAKE_CURRENT_SOURCE_DIR}/my-library.js"
+  )
+
+
+
+# Some hacks so check what's getting built TODO to get rid of eventually 
+#message(STATUS "qpid-proton-platform: ${qpid-proton-platform}")
+#message(STATUS "qpid-proton-core: ${qpid-proton-core}")
+
+

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/LICENSE
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/LICENSE?rev=1544669&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/LICENSE (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/LICENSE Fri Nov 22 20:24:28 2013
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/LICENSE
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/LICENSE
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/README
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/README?rev=1544669&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/README (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/README Fri Nov 22 20:24:28 2013
@@ -0,0 +1,75 @@
+Qpid Proton JavaScript Language Bindings
+========================================
+
+The code contained herein provides JavaScript language bindings for working
+with the Qpid Proton AMQP 1.0 protocol engine and messenger library.
+
+Creating The Bindings
+=====================
+
+To generate the JavaScript bindings we actually cross-compile from proton-c
+
+You will need to have emscripten (https://github.com/kripken/emscripten) installed
+to do the cross-compilation and in addition you will require a few things that
+emscripten itself depends upon https://github.com/kripken/emscripten/wiki/Emscripten-SDK
+provides some fairly easy to follow instructions for getting started on several
+platforms the main dependencies are as follows (on Windows the SDK includes these):
+
+* The Emscripten code, from github (git clone git://github.com/kripken/emscripten.git. The documentation suggests
+  master branch but in the short term incoming is probably better as a few updates to emscripten have been added
+  to help get proton working and these may take a little while to get merged back to master.
+* LLVM with Clang. Version 3.2 is the officially supported version, others may not work. There are official clang
+  binaries that include LLVM for some platforms, if yours is not there then you should get the LLVM and Clang
+  sources and build them.
+* Node.js (0.8 or above; 0.10.17 or above to run websocket-using servers in node)
+* Python 2.7.3
+* Optionally, if you want to use Closure Compiler to minify your code as much as possible, you will also need Java.
+
+If you haven't run Emscripten before it's agood idea to have a play with the tutorial
+https://github.com/kripken/emscripten/wiki/Tutorial
+
+
+when you are all set up with emscripten and have got the basic tests in the tutorial running
+building Proton should be simple, simply go to the Proton root directory and follow the main
+instructions in the README there, in precis (from the root directory) it's:
+
+  mkdir build
+  cd build
+  cmake ..
+  make
+
+
+In order to use WebSockets from Node.js you will need to install the "ws" package, the easiest
+way to do this is to use npm. From <proton-root>/build/proton-c/bindings/javascript (or where
+ever you decide to put the JavaScript binding library created by this build) simply do:
+
+  npm install ws
+
+and you should be all set, to test it's all working do:
+
+  node recv-async.js
+
+in one window and
+
+  node send-async.js
+
+in another
+
+
+KNOWN ISSUES
+============
+
+send-async and recv-async are both pretty hacky at the moment and not really asynchronous, this will
+be addressed ASAP.
+
+
+SUPPORT
+=======
+
+To report bugs in the bindings, or to request an enhancement, please file
+a tracker request:
+
+    https://issues.apache.org/jira/browse/PROTON
+
+You can also directly interact with the development team and other users
+in the #qpid channel on irc.freenode.net.

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/README
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/README
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/TODO
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/TODO?rev=1544669&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/TODO (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/TODO Fri Nov 22 20:24:28 2013
@@ -0,0 +1,31 @@
+Qpid Proton JavaScript Language Bindings TODO List
+==================================================
+
+This is still largely a Proof of Concept, but it builds cleanly from an unmodified proton-c 
+code base, so for the most part it feels like a really neat way to generate JavaScript bindings.
+
+The main TODO is to actually create JavaScript bindings :-)
+
+At the moment the send-async.js and recv-async.js are actually compiled to JavaScript from
+send-async.c and recv-async.c so "real" JavaScript bindings usable from other JavaScript code
+haven't been exported yet. I suspect that one of the most important things to check when that is
+done would be interoperability across different types. This is all easy in the C code because
+the emscripten runtime heap is backed by typed Arrays, but there might be shenanigans to be had
+mapping stuff across the binding - it's definitely do-able just don't know how fiddly.
+
+Other TODO the code base contains some tweaked emscripten library code, this is ultimately going
+to get done properly, commited back to emscripten and removed from here.
+
+
+The example send-async and recv-async are both pretty hacky at the moment and *not really asynchronous*!!
+This will be addressed ASAP, I hate the timed loop and although the code is non-blocking it's not
+asynchronous. I'm pretty sure that I know how to get emscripten to call back when data is available
+on a WebSocket so hopefully this should be straightforward.
+
+There's probably a slightly more contentious discussion to be had about a proper asynchronous interface
+in proton-c proper. I suspect that it could do with one in the brave new multicore world pushing out
+data down non-blocking queues to consumer threads tends to scale better than a model of threads locking
+a resource, which is the behaviour I suspect the current API likely steers clients towards.
+
+proton-j seems to use hawt-dispatch, which is modelled after Grand Central Dispatch so I need to
+work out what it's using it do do and whether there are parallels in proton-c

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/TODO
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/TODO
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/recv-async.c
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/recv-async.c?rev=1544669&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/recv-async.c (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/recv-async.c Fri Nov 22 20:24:28 2013
@@ -0,0 +1,203 @@
+/*
+ * 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/message.h"
+#include "proton/messenger.h"
+
+#include "pncompat/misc_funcs.inc"
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#if EMSCRIPTEN
+#include <emscripten.h>
+#endif
+
+#define check(messenger)                                                     \
+  {                                                                          \
+    if(pn_messenger_errno(messenger))                                        \
+    {                                                                        \
+      die(__FILE__, __LINE__, pn_error_text(pn_messenger_error(messenger))); \
+    }                                                                        \
+  }                                                                          \
+
+// FA Temporarily make these global
+  pn_message_t * message;
+  pn_messenger_t * messenger;
+
+void die(const char *file, int line, const char *message)
+{
+  fprintf(stderr, "%s:%i: %s\n", file, line, message);
+  exit(1);
+}
+
+void usage()
+{
+  printf("Usage: recv [options] <addr>\n");
+  printf("-c    \tPath to the certificate file.\n");
+  printf("-k    \tPath to the private key file.\n");
+  printf("-p    \tPassword for the private key.\n");
+  printf("<addr>\tAn address.\n");
+  exit(0);
+}
+
+void main_loop(void *arg) {
+
+    pn_messenger_recv(messenger, -1);
+    //pn_messenger_recv(messenger, 1024);
+    //pn_messenger_recv(messenger, 0);
+    check(messenger);
+
+    while(pn_messenger_incoming(messenger))
+    {
+      pn_messenger_get(messenger, message);
+      check(messenger);
+
+      char buffer[1024];
+      size_t buffsize = sizeof(buffer);
+      pn_data_t *body = pn_message_body(message);
+      pn_data_format(body, buffer, &buffsize);
+
+      printf("Address: %s\n", pn_message_get_address(message));
+      const char* subject = pn_message_get_subject(message);
+      printf("Subject: %s\n", subject ? subject : "(no subject)");
+      printf("Content: %s\n", buffer);
+    }
+
+}
+
+int main(int argc, char** argv)
+{
+  char* certificate = NULL;
+  char* privatekey = NULL;
+  char* password = NULL;
+  char* address = (char *) "amqp://~0.0.0.0";
+  int c;
+  opterr = 0;
+
+  while((c = getopt(argc, argv, "hc:k:p:")) != -1)
+  {
+    switch(c)
+    {
+    case 'h':
+      usage();
+      break;
+
+    case 'c': certificate = optarg; break;
+    case 'k': privatekey = optarg; break;
+    case 'p': password = optarg; break;
+
+    case '?':
+      if(optopt == 'c' ||
+         optopt == 'k' ||
+         optopt == 'p')
+      {
+        fprintf(stderr, "Option -%c requires an argument.\n", optopt);
+      }
+      else if(isprint(optopt))
+      {
+        fprintf(stderr, "Unknown option `-%c'.\n", optopt);
+      }
+      else
+      {
+        fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
+      }
+      return 1;
+    default:
+      abort();
+    }
+  }
+
+  if (optind < argc)
+  {
+    address = argv[optind];
+  }
+
+//  pn_message_t * message;
+//  pn_messenger_t * messenger;
+
+  message = pn_message();
+  messenger = pn_messenger(NULL);
+pn_messenger_set_blocking(messenger, false); // FA Addition.
+
+
+
+  /* load the various command line options if they're set */
+  if(certificate)
+  {
+    pn_messenger_set_certificate(messenger, certificate);
+  }
+
+  if(privatekey)
+  {
+    pn_messenger_set_private_key(messenger, privatekey);
+  }
+
+  if(password)
+  {
+    pn_messenger_set_password(messenger, password);
+  }
+
+  pn_messenger_start(messenger);
+  check(messenger);
+
+  pn_messenger_subscribe(messenger, address);
+  check(messenger);
+
+#if EMSCRIPTEN
+  emscripten_set_main_loop(main_loop, 0, 0);
+#else
+  while (1) {
+    main_loop(NULL);
+
+    struct timeval timeout;
+    timeout.tv_sec = 0;
+    timeout.tv_usec = 16667;
+    select(0, NULL, NULL, NULL, &timeout);
+  }
+#endif
+
+
+/*
+  for(;;)
+  {
+    pn_messenger_recv(messenger, 1024);
+    check(messenger);
+
+    while(pn_messenger_incoming(messenger))
+    {
+      pn_messenger_get(messenger, message);
+      check(messenger);
+
+      char buffer[1024];
+      size_t buffsize = sizeof(buffer);
+      pn_data_t *body = pn_message_body(message);
+      pn_data_format(body, buffer, &buffsize);
+
+      printf("Address: %s\n", pn_message_get_address(message));
+      const char* subject = pn_message_get_subject(message);
+      printf("Subject: %s\n", subject ? subject : "(no subject)");
+      printf("Content: %s\n", buffer);
+    }
+  }
+*/
+
+  return 0;
+}

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/recv-async.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/recv-async.c
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/send-async.c
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/send-async.c?rev=1544669&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/send-async.c (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/send-async.c Fri Nov 22 20:24:28 2013
@@ -0,0 +1,157 @@
+/*
+ * 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/message.h"
+#include "proton/messenger.h"
+
+#include "pncompat/misc_funcs.inc"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#if EMSCRIPTEN
+#include <emscripten.h>
+#endif
+
+#define check(messenger)                                                     \
+  {                                                                          \
+    if(pn_messenger_errno(messenger))                                        \
+    {                                                                        \
+      die(__FILE__, __LINE__, pn_error_text(pn_messenger_error(messenger))); \
+    }                                                                        \
+  }                                                                          \
+
+// FA Temporarily make global
+  pn_message_t * message;
+  pn_messenger_t * messenger;
+int count = 0;
+
+void die(const char *file, int line, const char *message)
+{
+  fprintf(stderr, "%s:%i: %s\n", file, line, message);
+  exit(1);
+}
+
+void usage()
+{
+  printf("Usage: send [-a addr] [message]\n");
+  printf("-a     \tThe target address [amqp[s]://domain[/name]]\n");
+  printf("message\tA text string to send.\n");
+  exit(0);
+}
+
+
+void main_loop(void *arg) {
+//printf("                          *** main_loop ***\n");
+
+    pn_messenger_work(messenger, 0); // FA Addition.
+
+/*
+count++;
+if (count % 100 == 0) {
+exit(1);
+}
+*/
+
+}
+
+
+int main(int argc, char** argv)
+{
+  int c;
+  opterr = 0;
+  char * address = (char *) "amqp://0.0.0.0";
+  char * msgtext = (char *) "Hello World!";
+
+  while((c = getopt(argc, argv, "ha:b:c:")) != -1)
+  {
+    switch(c)
+    {
+    case 'a': address = optarg; break;
+    case 'h': usage(); break;
+
+    case '?':
+      if(optopt == 'a')
+      {
+        fprintf(stderr, "Option -%c requires an argument.\n", optopt);
+      }
+      else if(isprint(optopt))
+      {
+        fprintf(stderr, "Unknown option `-%c'.\n", optopt);
+      }
+      else
+      {
+        fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
+      }
+      return 1;
+    default:
+      abort();
+    }
+  }
+
+  if (optind < argc) msgtext = argv[optind];
+
+//  pn_message_t * message;
+//  pn_messenger_t * messenger;
+
+  message = pn_message();
+  messenger = pn_messenger(NULL);
+pn_messenger_set_blocking(messenger, false); // FA Addition.
+
+
+
+
+  pn_messenger_start(messenger);
+
+  pn_message_set_address(message, address);
+  pn_data_t *body = pn_message_body(message);
+  pn_data_put_string(body, pn_bytes(strlen(msgtext), msgtext));
+
+  pn_messenger_put(messenger, message);
+  check(messenger);
+
+  //pn_messenger_send(messenger, -1);
+  pn_messenger_send(messenger, 0); // FA Addition.
+  check(messenger);
+
+#if EMSCRIPTEN
+  emscripten_set_main_loop(main_loop, 0, 0);
+#else
+
+  while (1) {
+    main_loop(NULL);
+
+    struct timeval timeout;
+    timeout.tv_sec = 0;
+    timeout.tv_usec = 16667;
+    select(0, NULL, NULL, NULL, &timeout);
+  }
+#endif
+
+
+/*
+  pn_messenger_stop(messenger);
+  pn_messenger_free(messenger);
+  pn_message_free(message);
+*/
+
+  return 0;
+}

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/send-async.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/examples/send-async.c
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/my-library.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/my-library.js?rev=1544669&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/my-library.js (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/my-library.js Fri Nov 22 20:24:28 2013
@@ -0,0 +1,677 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+
+mergeInto(LibraryManager.library, {
+
+  $PROTOCOLS: null,
+  __buildProtocols__deps: ['$PROTOCOLS'],
+  __buildProtocols: function() {
+
+    // Allocate and populate a protoent structure given a name, protocol number and array of aliases
+    function allocprotoent(name, proto, aliases) {
+      // write name into buffer
+      var nameBuf = _malloc(name.length + 1);
+      writeAsciiToMemory(name, nameBuf);
+
+      // write aliases into buffer
+      var j = 0;
+      var length = aliases.length;
+      var aliasListBuf = _malloc((length + 1) * 4); // Use length + 1 so we have space for the terminating NULL pointer.
+
+      for (var i = 0; i < length; i++, j += 4) {
+        var alias = aliases[i];
+        var aliasBuf = _malloc(alias.length + 1);
+        writeAsciiToMemory(alias, aliasBuf);
+        {{{ makeSetValue('aliasListBuf', 'j', 'aliasBuf', 'i8*') }}};
+      }
+      {{{ makeSetValue('aliasListBuf', 'j', '0', 'i8*') }}}; // Terminating NULL pointer.
+
+      // generate protoent
+      var pe = _malloc({{{ C_STRUCTS.protoent.__size__ }}});
+      {{{ makeSetValue('pe', C_STRUCTS.protoent.p_name, 'nameBuf', 'i8*') }}};
+      {{{ makeSetValue('pe', C_STRUCTS.protoent.p_aliases, 'aliasListBuf', 'i8**') }}};
+      {{{ makeSetValue('pe', C_STRUCTS.protoent.p_proto, 'proto', 'i32') }}};
+      return pe;
+    };
+
+    PROTOCOLS = {};
+    PROTOCOLS['tcp'] = PROTOCOLS['6'] = allocprotoent('tcp', 6, ['TCP']);
+    PROTOCOLS['udp'] = PROTOCOLS['17'] = allocprotoent('udp', 17, ['UDP']);
+  },
+
+  getprotobyname__deps: ['__buildProtocols', '$PROTOCOLS'],
+  getprotobyname: function(name) {
+    // struct protoent *getprotobyname (const char *);
+    name = Pointer_stringify(name);
+    if (!PROTOCOLS) {
+        ___buildProtocols();
+    }
+
+    var result = PROTOCOLS[name];
+    return {{{ makeGetValue(0, 'result', 'i8*') }}};
+  },
+  getprotobynumber__deps: ['getprotobyname'],
+  getprotobynumber: function(number) {
+    _getprotobyname(number);
+  },
+
+
+
+
+
+
+
+// Hacks below
+// -----------------------------------------------------------------------------------------------------------------
+
+
+  $SOCKFS__postset: '__ATINIT__.push({ func: function() { SOCKFS.root = FS.mount(SOCKFS, {}, null); } });',
+  $SOCKFS__deps: ['$FS'],
+  $SOCKFS: {
+    mount: function(mount) {
+      return FS.createNode(null, '/', {{{ cDefine('S_IFDIR') }}} | 0777, 0);
+    },
+    createSocket: function(family, type, protocol) {
+      var streaming = type == {{{ cDefine('SOCK_STREAM') }}};
+      if (protocol) {
+        assert(streaming == (protocol == {{{ cDefine('IPPROTO_TCP') }}})); // if SOCK_STREAM, must be tcp
+      }
+
+      // create our internal socket structure
+      var sock = {
+        family: family,
+        type: type,
+        protocol: protocol,
+        server: null,
+        peers: {},
+        pending: [],
+        recv_queue: [],
+#if SOCKET_WEBRTC
+#else
+        sock_ops: SOCKFS.websocket_sock_ops
+#endif
+      };
+
+      // create the filesystem node to store the socket structure
+      var name = SOCKFS.nextname();
+      var node = FS.createNode(SOCKFS.root, name, {{{ cDefine('S_IFSOCK') }}}, 0);
+      node.sock = sock;
+
+      // and the wrapping stream that enables library functions such
+      // as read and write to indirectly interact with the socket
+      var stream = FS.createStream({
+        path: name,
+        node: node,
+        flags: FS.modeStringToFlags('r+'),
+        seekable: false,
+        stream_ops: SOCKFS.stream_ops
+      });
+
+      // map the new stream to the socket structure (sockets have a 1:1
+      // relationship with a stream)
+      sock.stream = stream;
+
+      return sock;
+    },
+    getSocket: function(fd) {
+      var stream = FS.getStream(fd);
+      if (!stream || !FS.isSocket(stream.node.mode)) {
+        return null;
+      }
+      return stream.node.sock;
+    },
+    // node and stream ops are backend agnostic
+    stream_ops: {
+      poll: function(stream) {
+        var sock = stream.node.sock;
+        return sock.sock_ops.poll(sock);
+      },
+      ioctl: function(stream, request, varargs) {
+console.log('stream_ops.ioctl');
+        var sock = stream.node.sock;
+        return sock.sock_ops.ioctl(sock, request, varargs);
+      },
+      read: function(stream, buffer, offset, length, position /* ignored */) {
+        var sock = stream.node.sock;
+        var msg = sock.sock_ops.recvmsg(sock, length);
+        if (!msg) {
+          // socket is closed
+          return 0;
+        }
+#if USE_TYPED_ARRAYS == 2
+        buffer.set(msg.buffer, offset);
+#else
+        for (var i = 0; i < size; i++) {
+          buffer[offset + i] = msg.buffer[i];
+        }
+#endif
+        return msg.buffer.length;
+      },
+      write: function(stream, buffer, offset, length, position /* ignored */) {
+        var sock = stream.node.sock;
+        return sock.sock_ops.sendmsg(sock, buffer, offset, length);
+      },
+      close: function(stream) {
+console.log('stream_ops.close');
+        var sock = stream.node.sock;
+        sock.sock_ops.close(sock);
+      }
+    },
+    nextname: function() {
+      if (!SOCKFS.nextname.current) {
+        SOCKFS.nextname.current = 0;
+      }
+      return 'socket[' + (SOCKFS.nextname.current++) + ']';
+    },
+    // backend-specific stream ops
+    websocket_sock_ops: {
+      //
+      // peers are a small wrapper around a WebSocket to help in
+      // emulating dgram sockets
+      //
+      // these functions aren't actually sock_ops members, but we're
+      // abusing the namespace to organize them
+      //
+      createPeer: function(sock, addr, port) {
+        var ws;
+
+        if (typeof addr === 'object') {
+          ws = addr;
+          addr = null;
+          port = null;
+        }
+
+        if (ws) {
+          // for sockets that've already connected (e.g. we're the server)
+          // we can inspect the _socket property for the address
+          if (ws._socket) {
+            addr = ws._socket.remoteAddress;
+            port = ws._socket.remotePort;
+          }
+          // if we're just now initializing a connection to the remote,
+          // inspect the url property
+          else {
+            var result = /ws[s]?:\/\/([^:]+):(\d+)/.exec(ws.url);
+            if (!result) {
+              throw new Error('WebSocket URL must be in the format ws(s)://address:port');
+            }
+            addr = result[1];
+            port = parseInt(result[2], 10);
+          }
+        } else {
+          // create the actual websocket object and connect
+          try {
+            var url = 'ws://' + addr + ':' + port;
+#if SOCKET_DEBUG
+            console.log('connect: ' + url);
+#endif
+            // the node ws library API is slightly different than the browser's
+            var opts = ENVIRONMENT_IS_NODE ? {headers: {'websocket-protocol': ['binary']}} : ['binary'];
+            // If node we use the ws library.
+            var WebSocket = ENVIRONMENT_IS_NODE ? require('ws') : window['WebSocket'];
+            ws = new WebSocket(url, opts);
+            ws.binaryType = 'arraybuffer';
+          } catch (e) {
+console.log('e: ' + e);
+            throw new FS.ErrnoError(ERRNO_CODES.EHOSTUNREACH);
+          }
+        }
+
+#if SOCKET_DEBUG
+        Module.print('websocket adding peer: ' + addr + ':' + port);
+#endif
+
+        var peer = {
+          addr: addr,
+          port: port,
+          socket: ws,
+          dgram_send_queue: []
+        };
+
+        SOCKFS.websocket_sock_ops.addPeer(sock, peer);
+        SOCKFS.websocket_sock_ops.handlePeerEvents(sock, peer);
+
+        // if this is a bound dgram socket, send the port number first to allow
+        // us to override the ephemeral port reported to us by remotePort on the
+        // remote end.
+        if (sock.type === {{{ cDefine('SOCK_DGRAM') }}} && typeof sock.sport !== 'undefined') {
+#if SOCKET_DEBUG
+          Module.print('websocket queuing port message (port ' + sock.sport + ')');
+#endif
+          peer.dgram_send_queue.push(new Uint8Array([
+              255, 255, 255, 255,
+              'p'.charCodeAt(0), 'o'.charCodeAt(0), 'r'.charCodeAt(0), 't'.charCodeAt(0),
+              ((sock.sport & 0xff00) >> 8) , (sock.sport & 0xff)
+          ]));
+        }
+
+        return peer;
+      },
+      getPeer: function(sock, addr, port) {
+        return sock.peers[addr + ':' + port];
+      },
+      addPeer: function(sock, peer) {
+        sock.peers[peer.addr + ':' + peer.port] = peer;
+      },
+      removePeer: function(sock, peer) {
+        delete sock.peers[peer.addr + ':' + peer.port];
+      },
+      handlePeerEvents: function(sock, peer) {
+        var first = true;
+
+        var handleOpen = function () {
+#if SOCKET_DEBUG
+          Module.print('websocket handle open');
+#endif
+          try {
+            var queued = peer.dgram_send_queue.shift();
+            while (queued) {
+#if SOCKET_DEBUG
+              Module.print('websocket sending queued data (' + queued.byteLength + ' bytes): ' + [Array.prototype.slice.call(new Uint8Array(queued))]);
+#endif
+              peer.socket.send(queued);
+              queued = peer.dgram_send_queue.shift();
+            }
+          } catch (e) {
+            // not much we can do here in the way of proper error handling as we've already
+            // lied and said this data was sent. shut it down.
+            peer.socket.close();
+          }
+        };
+
+        function handleMessage(data) {
+          assert(typeof data !== 'string' && data.byteLength !== undefined);  // must receive an ArrayBuffer
+          data = new Uint8Array(data);  // make a typed array view on the array buffer
+
+#if SOCKET_DEBUG
+          //Module.print('websocket handle message (' + data.byteLength + ' bytes): ' + [Array.prototype.slice.call(data)]);
+          //Module.print('websocket handle message (' + data.byteLength + ' bytes)');
+#endif
+
+          // if this is the port message, override the peer's port with it
+          var wasfirst = first;
+          first = false;
+          if (wasfirst &&
+              data.length === 10 &&
+              data[0] === 255 && data[1] === 255 && data[2] === 255 && data[3] === 255 &&
+              data[4] === 'p'.charCodeAt(0) && data[5] === 'o'.charCodeAt(0) && data[6] === 'r'.charCodeAt(0) && data[7] === 't'.charCodeAt(0)) {
+            // update the peer's port and it's key in the peer map
+            var newport = ((data[8] << 8) | data[9]);
+            SOCKFS.websocket_sock_ops.removePeer(sock, peer);
+            peer.port = newport;
+            SOCKFS.websocket_sock_ops.addPeer(sock, peer);
+            return;
+          }
+
+          sock.recv_queue.push({ addr: peer.addr, port: peer.port, data: data });
+        };
+
+        if (ENVIRONMENT_IS_NODE) {
+          peer.socket.on('open', handleOpen);
+          peer.socket.on('message', function(data, flags) {
+            if (!flags.binary) {
+              return;
+            }
+            handleMessage((new Uint8Array(data)).buffer);  // copy from node Buffer -> ArrayBuffer
+          });
+          peer.socket.on('error', function(error) {
+console.log('error ' + error);
+            // don't throw
+          });
+        } else {
+          peer.socket.onopen = handleOpen;
+          peer.socket.onmessage = function peer_socket_onmessage(event) {
+            handleMessage(event.data);
+          };
+        }
+      },
+
+      //
+      // actual sock ops
+      //
+      poll: function(sock) {
+        if (sock.type === {{{ cDefine('SOCK_STREAM') }}} && sock.server) {
+          // listen sockets should only say they're available for reading
+          // if there are pending clients.
+          return sock.pending.length ? ({{{ cDefine('POLLRDNORM') }}} | {{{ cDefine('POLLIN') }}}) : 0;
+        }
+
+        var mask = 0;
+        var dest = sock.type === {{{ cDefine('SOCK_STREAM') }}} ?  // we only care about the socket state for connection-based sockets
+          SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport) :
+          null;
+
+        if (sock.recv_queue.length ||
+            !dest ||  // connection-less sockets are always ready to read
+            (dest && dest.socket.readyState === dest.socket.CLOSING) ||
+            (dest && dest.socket.readyState === dest.socket.CLOSED)) {  // let recv return 0 once closed
+          mask |= ({{{ cDefine('POLLRDNORM') }}} | {{{ cDefine('POLLIN') }}});
+        }
+
+        if (!dest ||  // connection-less sockets are always ready to write
+            (dest && dest.socket.readyState === dest.socket.OPEN)) {
+          mask |= {{{ cDefine('POLLOUT') }}};
+        }
+
+        if ((dest && dest.socket.readyState === dest.socket.CLOSING) ||
+            (dest && dest.socket.readyState === dest.socket.CLOSED)) {
+          mask |= {{{ cDefine('POLLHUP') }}};
+        }
+        return mask;
+      },
+      ioctl: function(sock, request, arg) {
+console.log('ioctl');
+        switch (request) {
+          case {{{ cDefine('FIONREAD') }}}:
+            var bytes = 0;
+            if (sock.recv_queue.length) {
+              bytes = sock.recv_queue[0].data.length;
+            }
+            {{{ makeSetValue('arg', '0', 'bytes', 'i32') }}};
+            return 0;
+          default:
+            return ERRNO_CODES.EINVAL;
+        }
+      },
+      close: function(sock) {
+console.log('close');
+        // if we've spawned a listen server, close it
+        if (sock.server) {
+          try {
+            sock.server.close();
+          } catch (e) {
+          }
+          sock.server = null;
+        }
+        // close any peer connections
+        var peers = Object.keys(sock.peers);
+        for (var i = 0; i < peers.length; i++) {
+          var peer = sock.peers[peers[i]];
+          try {
+            peer.socket.close();
+          } catch (e) {
+          }
+          SOCKFS.websocket_sock_ops.removePeer(sock, peer);
+        }
+        return 0;
+      },
+      bind: function(sock, addr, port) {
+        if (typeof sock.saddr !== 'undefined' || typeof sock.sport !== 'undefined') {
+          throw new FS.ErrnoError(ERRNO_CODES.EINVAL);  // already bound
+        }
+        sock.saddr = addr;
+        sock.sport = port || _mkport();
+        // in order to emulate dgram sockets, we need to launch a listen server when
+        // binding on a connection-less socket
+        // note: this is only required on the server side
+        if (sock.type === {{{ cDefine('SOCK_DGRAM') }}}) {
+          // close the existing server if it exists
+          if (sock.server) {
+            sock.server.close();
+            sock.server = null;
+          }
+          // swallow error operation not supported error that occurs when binding in the
+          // browser where this isn't supported
+          try {
+            sock.sock_ops.listen(sock, 0);
+          } catch (e) {
+            if (!(e instanceof FS.ErrnoError)) throw e;
+            if (e.errno !== ERRNO_CODES.EOPNOTSUPP) throw e;
+          }
+        }
+      },
+      connect: function(sock, addr, port) {
+        if (sock.server) {
+          throw new FS.ErrnoError(ERRNO_CODS.EOPNOTSUPP);
+        }
+
+        // TODO autobind
+        // if (!sock.addr && sock.type == {{{ cDefine('SOCK_DGRAM') }}}) {
+        // }
+
+        // early out if we're already connected / in the middle of connecting
+        if (typeof sock.daddr !== 'undefined' && typeof sock.dport !== 'undefined') {
+          var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
+          if (dest) {
+            if (dest.socket.readyState === dest.socket.CONNECTING) {
+              throw new FS.ErrnoError(ERRNO_CODES.EALREADY);
+            } else {
+              throw new FS.ErrnoError(ERRNO_CODES.EISCONN);
+            }
+          }
+        }
+
+        // add the socket to our peer list and set our
+        // destination address / port to match
+        var peer = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
+        sock.daddr = peer.addr;
+        sock.dport = peer.port;
+
+        // always "fail" in non-blocking mode
+        throw new FS.ErrnoError(ERRNO_CODES.EINPROGRESS);
+      },
+      listen: function(sock, backlog) {
+        if (!ENVIRONMENT_IS_NODE) {
+          throw new FS.ErrnoError(ERRNO_CODES.EOPNOTSUPP);
+        }
+        if (sock.server) {
+           throw new FS.ErrnoError(ERRNO_CODES.EINVAL);  // already listening
+        }
+        var WebSocketServer = require('ws').Server;
+        var host = sock.saddr;
+#if SOCKET_DEBUG
+        console.log('listen: ' + host + ':' + sock.sport);
+#endif
+        sock.server = new WebSocketServer({
+          host: host,
+          port: sock.sport
+          // TODO support backlog
+        });
+
+        sock.server.on('connection', function(ws) {
+#if SOCKET_DEBUG
+          console.log('received connection from: ' + ws._socket.remoteAddress + ':' + ws._socket.remotePort);
+#endif
+          if (sock.type === {{{ cDefine('SOCK_STREAM') }}}) {
+            var newsock = SOCKFS.createSocket(sock.family, sock.type, sock.protocol);
+
+            // create a peer on the new socket
+            var peer = SOCKFS.websocket_sock_ops.createPeer(newsock, ws);
+            newsock.daddr = peer.addr;
+            newsock.dport = peer.port;
+
+            // push to queue for accept to pick up
+            sock.pending.push(newsock);
+          } else {
+            // create a peer on the listen socket so calling sendto
+            // with the listen socket and an address will resolve
+            // to the correct client
+            SOCKFS.websocket_sock_ops.createPeer(sock, ws);
+          }
+        });
+        sock.server.on('closed', function() {
+console.log('closed');
+          sock.server = null;
+        });
+        sock.server.on('error', function() {
+console.log('error');
+          // don't throw
+        });
+      },
+      accept: function(listensock) {
+console.log('accept');
+        if (!listensock.server) {
+          throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
+        }
+
+        var newsock = listensock.pending.shift();
+        newsock.stream.flags = listensock.stream.flags;
+        return newsock;
+      },
+      getname: function(sock, peer) {
+console.log('getname');
+        var addr, port;
+        if (peer) {
+          if (sock.daddr === undefined || sock.dport === undefined) {
+            throw new FS.ErrnoError(ERRNO_CODES.ENOTCONN);
+          }
+          addr = sock.daddr;
+          port = sock.dport;
+        } else {
+          // TODO saddr and sport will be set for bind()'d UDP sockets, but what
+          // should we be returning for TCP sockets that've been connect()'d?
+          addr = sock.saddr || 0;
+          port = sock.sport || 0;
+        }
+        return { addr: addr, port: port };
+      },
+      sendmsg: function(sock, buffer, offset, length, addr, port) {
+        if (sock.type === {{{ cDefine('SOCK_DGRAM') }}}) {
+          // connection-less sockets will honor the message address,
+          // and otherwise fall back to the bound destination address
+          if (addr === undefined || port === undefined) {
+            addr = sock.daddr;
+            port = sock.dport;
+          }
+          // if there was no address to fall back to, error out
+          if (addr === undefined || port === undefined) {
+            throw new FS.ErrnoError(ERRNO_CODES.EDESTADDRREQ);
+          }
+        } else {
+          // connection-based sockets will only use the bound
+          addr = sock.daddr;
+          port = sock.dport;
+        }
+
+        // find the peer for the destination address
+        var dest = SOCKFS.websocket_sock_ops.getPeer(sock, addr, port);
+
+        // early out if not connected with a connection-based socket
+        if (sock.type === {{{ cDefine('SOCK_STREAM') }}}) {
+          if (!dest || dest.socket.readyState === dest.socket.CLOSING || dest.socket.readyState === dest.socket.CLOSED) {
+            throw new FS.ErrnoError(ERRNO_CODES.ENOTCONN);
+          } else if (dest.socket.readyState === dest.socket.CONNECTING) {
+            throw new FS.ErrnoError(ERRNO_CODES.EAGAIN);
+          }
+        }
+
+        // create a copy of the incoming data to send, as the WebSocket API
+        // doesn't work entirely with an ArrayBufferView, it'll just send
+        // the entire underlying buffer
+        var data;
+        if (buffer instanceof Array || buffer instanceof ArrayBuffer) {
+          data = buffer.slice(offset, offset + length);
+        } else {  // ArrayBufferView
+          data = buffer.buffer.slice(buffer.byteOffset + offset, buffer.byteOffset + offset + length);
+        }
+
+        // if we're emulating a connection-less dgram socket and don't have
+        // a cached connection, queue the buffer to send upon connect and
+        // lie, saying the data was sent now.
+        if (sock.type === {{{ cDefine('SOCK_DGRAM') }}}) {
+          if (!dest || dest.socket.readyState !== dest.socket.OPEN) {
+            // if we're not connected, open a new connection
+            if (!dest || dest.socket.readyState === dest.socket.CLOSING || dest.socket.readyState === dest.socket.CLOSED) {
+              dest = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
+            }
+#if SOCKET_DEBUG
+            Module.print('websocket queuing (' + length + ' bytes): ' + [Array.prototype.slice.call(new Uint8Array(data))]);
+#endif
+            dest.dgram_send_queue.push(data);
+            return length;
+          }
+        }
+
+        try {
+#if SOCKET_DEBUG
+          Module.print('websocket send (' + length + ' bytes): ' + [Array.prototype.slice.call(new Uint8Array(data))]);
+#endif
+          // send the actual data
+          dest.socket.send(data);
+          return length;
+        } catch (e) {
+          throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
+        }
+      },
+      recvmsg: function(sock, length) {
+        // http://pubs.opengroup.org/onlinepubs/7908799/xns/recvmsg.html
+        if (sock.type === {{{ cDefine('SOCK_STREAM') }}} && sock.server) {
+          // tcp servers should not be recv()'ing on the listen socket
+          throw new FS.ErrnoError(ERRNO_CODES.ENOTCONN);
+        }
+
+        var queued = sock.recv_queue.shift();
+        if (!queued) {
+          if (sock.type === {{{ cDefine('SOCK_STREAM') }}}) {
+            var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
+
+            if (!dest) {
+              // if we have a destination address but are not connected, error out
+              throw new FS.ErrnoError(ERRNO_CODES.ENOTCONN);
+            }
+            else if (dest.socket.readyState === dest.socket.CLOSING || dest.socket.readyState === dest.socket.CLOSED) {
+              // return null if the socket has closed
+              return null;
+            }
+            else {
+              // else, our socket is in a valid state but truly has nothing available
+              throw new FS.ErrnoError(ERRNO_CODES.EAGAIN);
+            }
+          } else {
+            throw new FS.ErrnoError(ERRNO_CODES.EAGAIN);
+          }
+        }
+
+        // queued.data will be an ArrayBuffer if it's unadulterated, but if it's
+        // requeued TCP data it'll be an ArrayBufferView
+        var queuedLength = queued.data.byteLength || queued.data.length;
+        var queuedOffset = queued.data.byteOffset || 0;
+        var queuedBuffer = queued.data.buffer || queued.data;
+        var bytesRead = Math.min(length, queuedLength);
+        var res = {
+          buffer: new Uint8Array(queuedBuffer, queuedOffset, bytesRead),
+          addr: queued.addr,
+          port: queued.port
+        };
+
+#if SOCKET_DEBUG
+        Module.print('websocket read (' + bytesRead + ' bytes): ' + [Array.prototype.slice.call(res.buffer)]);
+#endif
+
+        // push back any unread data for TCP connections
+        if (sock.type === {{{ cDefine('SOCK_STREAM') }}} && bytesRead < queuedLength) {
+          var bytesRemaining = queuedLength - bytesRead;
+#if SOCKET_DEBUG
+          Module.print('websocket read: put back ' + bytesRemaining + ' bytes');
+#endif
+          queued.data = new Uint8Array(queuedBuffer, queuedOffset + bytesRead, bytesRemaining);
+          sock.recv_queue.unshift(queued);
+        }
+
+        return res;
+      }
+    }
+  },
+
+
+
+});

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/my-library.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/include/uuid/uuid.h
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/include/uuid/uuid.h?rev=1544669&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/include/uuid/uuid.h (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/include/uuid/uuid.h Fri Nov 22 20:24:28 2013
@@ -0,0 +1,40 @@
+/*
+ *
+ * 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.
+ *
+ * Public include file for the emscripten based UUID library stub.
+ *
+ */
+
+#ifndef _UUID_UUID_H
+#define _UUID_UUID_H
+
+typedef unsigned char uuid_t[16];
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void uuid_generate(uuid_t out);
+void uuid_unparse(const uuid_t uu, char *out);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _UUID_UUID_H */

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/include/uuid/uuid.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/include/uuid/uuid.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/src/library_uuid.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/src/library_uuid.js?rev=1544669&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/src/library_uuid.js (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/src/library_uuid.js Fri Nov 22 20:24:28 2013
@@ -0,0 +1,50 @@
+/*
+ *
+ * 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 library is a simple emscripten "stub" library for libuuid. It uses the method described in
+ * https://github.com/kripken/emscripten/wiki/Interacting-with-code Calling JavaScript From C/C++
+ * and used by the built-in emscripten libraries and needs to be linked using: --js-library library_uuid.js
+ * N.B. This is *not* a complete implementation of libuuid, rather it's primarily implementing uuid_unparse()
+ * for use in proton's "pn_i_genuuid" function.
+ */
+mergeInto(LibraryManager.library, {
+    uuid_generate: function(out) {
+        // void uuid_generate(uuid_t out);
+    },
+    /**
+     * Write a RFC4122 version 4 compliant UUID to the buffer pointed to by out using the method found in
+     * http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
+     * Note that the real uuid_unparse takes a "compact" uuid created by uuid_generate, but for proton
+     * we have a simple use-case of uuid_generate() immediately followed by uuid_unparse() and use no
+     * other uuid functions, so we can cut a few corners.
+     */
+    uuid_unparse: function(uu, out) {
+        // void uuid_unparse(const uuid_t uu, char *out);
+        var d = new Date().getTime();
+        var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
+            var r = (d + Math.random()*16)%16 | 0;
+            d = Math.floor(d/16);
+            return (c=='x' ? r : (r&0x7|0x8)).toString(16);
+        });
+        writeStringToMemory(uuid, out);
+    }
+});

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/uuid/src/library_uuid.js
------------------------------------------------------------------------------
    svn:eol-style = native



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


Mime
View raw message