You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2012/03/08 19:33:47 UTC
svn commit: r1298498 [1/3] - in /qpid/proton/proton-c: ./ include/
include/proton/ mllib/ src/ src/codec/ src/engine/ src/framing/ src/types/
Author: rhs
Date: Thu Mar 8 18:33:46 2012
New Revision: 1298498
URL: http://svn.apache.org/viewvc?rev=1298498&view=rev
Log:
initial import of proton C implementation
Added:
qpid/proton/proton-c/
qpid/proton/proton-c/.gitignore
qpid/proton/proton-c/LICENSE
qpid/proton/proton-c/Makefile
qpid/proton/proton-c/README
qpid/proton/proton-c/TODO
qpid/proton/proton-c/include/
qpid/proton/proton-c/include/proton/
qpid/proton/proton-c/include/proton/codec.h
qpid/proton/proton-c/include/proton/driver.h
qpid/proton/proton-c/include/proton/engine.h
qpid/proton/proton-c/include/proton/framing.h
qpid/proton/proton-c/include/proton/util.h
qpid/proton/proton-c/include/proton/value.h
qpid/proton/proton-c/mllib/
- copied from r1298465, qpid/trunk/qpid/python/mllib/
qpid/proton/proton-c/musings.txt
qpid/proton/proton-c/src/
qpid/proton/proton-c/src/codec/
qpid/proton/proton-c/src/codec/codec.c
qpid/proton/proton-c/src/codec/encodings.h.py (with props)
qpid/proton/proton-c/src/codec/types.xml
qpid/proton/proton-c/src/driver.c
qpid/proton/proton-c/src/engine/
qpid/proton/proton-c/src/engine/engine-internal.h
qpid/proton/proton-c/src/engine/engine.c
qpid/proton/proton-c/src/framing/
qpid/proton/proton-c/src/framing/framing.c
qpid/proton/proton-c/src/messaging.xml
qpid/proton/proton-c/src/protocol.h.py
qpid/proton/proton-c/src/protocol.py
qpid/proton/proton-c/src/proton.c
qpid/proton/proton-c/src/transport.xml
qpid/proton/proton-c/src/types/
qpid/proton/proton-c/src/types/array.c
qpid/proton/proton-c/src/types/binary.c
qpid/proton/proton-c/src/types/decode.c
qpid/proton/proton-c/src/types/list.c
qpid/proton/proton-c/src/types/map.c
qpid/proton/proton-c/src/types/string.c
qpid/proton/proton-c/src/types/value-internal.h
qpid/proton/proton-c/src/types/value.c
qpid/proton/proton-c/src/util.c
qpid/proton/proton-c/src/util.h
Added: qpid/proton/proton-c/.gitignore
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/.gitignore?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/.gitignore (added)
+++ qpid/proton/proton-c/.gitignore Thu Mar 8 18:33:46 2012
@@ -0,0 +1,8 @@
+*.pyc
+*.o
+*.d
+src/codec/encodings.h
+src/protocol.h
+src/proton
+src/test
+src/libqpidproton.so
Added: qpid/proton/proton-c/LICENSE
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/LICENSE?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/LICENSE (added)
+++ qpid/proton/proton-c/LICENSE Thu Mar 8 18:33:46 2012
@@ -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.
+
Added: qpid/proton/proton-c/Makefile
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/Makefile?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/Makefile (added)
+++ qpid/proton/proton-c/Makefile Thu Mar 8 18:33:46 2012
@@ -0,0 +1,51 @@
+CFLAGS := -Wall -Werror -pedantic-errors -std=c99 -g -Iinclude -fPIC
+PYTHON := python
+PYTHONPATH := ${realpath .}
+UTIL_SRC := src/util.c
+CODEC_SRC := src/codec/codec.c
+FRAMING_SRC := src/framing/framing.c
+VALUE_SRC := src/types/value.c src/types/array.c src/types/list.c \
+ src/types/map.c src/types/string.c src/types/binary.c \
+ src/types/decode.c
+UTIL_HDR := include/proton/util.h
+VALUE_HDR := include/proton/value.h
+ENGINE_SRC := src/engine/engine.c
+DRIVER_SRC := src/driver.c
+
+SRCS := ${UTIL_SRC} ${VALUE_SRC} ${FRAMING_SRC} ${CODEC_SRC} ${PROTOCOL_SRC} \
+ ${ENGINE_SRC} ${DRIVER_SRC}
+OBJS := ${SRCS:.c=.o}
+DEPS := ${OBJS:.o=.d}
+HDRS := ${UTIL_HDR} ${VALUE_HDR} \
+ ${FRAMING_SRC:src/framing/%.c=include/proton/%.h} \
+ ${CODEC_SRC:src/codec/%.c=include/proton/%.h} \
+ src/protocol.h \
+ include/proton/engine.h \
+ src/codec/encodings.h
+
+PROGRAMS := src/proton
+LIBRARY := src/libqpidproton.so
+
+all: ${PROGRAMS} ${LIBRARY}
+
+# pull in dependency info for *existing* .o files
+-include ${DEPS}
+
+${PROGRAMS}: ${OBJS}
+
+${LIBRARY}: ${OBJS}
+ $(CC) $(CCFLAGS) -shared -o $@ $^
+
+${OBJS}: ${HDRS}
+${OBJS}: %.o: %.c
+ gcc -c -MMD -MP $(CFLAGS) $*.c -o $*.o
+
+%.h: %.h.py
+ PYTHONPATH=${PYTHONPATH} ${PYTHON} $< > $@
+
+%.c: %.c.py
+ PYTHONPATH=${PYTHONPATH} ${PYTHON} $< > $@
+
+clean:
+ rm -f ${PROGRAMS} ${LIBRARY} ${OBJS} ${DEPS} src/protocol.c \
+ src/protocol.h src/codec/encodings.h src/*.pyc
Added: qpid/proton/proton-c/README
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/README?rev=1298498&view=auto
==============================================================================
(empty)
Added: qpid/proton/proton-c/TODO
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/TODO?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/TODO (added)
+++ qpid/proton/proton-c/TODO Thu Mar 8 18:33:46 2012
@@ -0,0 +1,8 @@
+ - fill in fake codecs
+ - uuid, timestamp
+ - tests: swig/python? mains?
+ - eliminate exported structs
+ - bug in driver when selectable set is modified from handler?
+ - temporary failure in name reslution?
+ - eliminate useless codegen in favor of a single reused arg list
+ + finish this by adding stack thingy to engine for nested structures
Added: qpid/proton/proton-c/include/proton/codec.h
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/include/proton/codec.h?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/include/proton/codec.h (added)
+++ qpid/proton/proton-c/include/proton/codec.h Thu Mar 8 18:33:46 2012
@@ -0,0 +1,108 @@
+#ifndef _PROTON_CODEC_H
+#define _PROTON_CODEC_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 <stdbool.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <wchar.h>
+
+int pn_write_descriptor(char **pos, char *limit);
+int pn_write_null(char **pos, char *limit);
+int pn_write_boolean(char **pos, char *limit, bool v);
+int pn_write_ubyte(char **pos, char *limit, uint8_t v);
+int pn_write_byte(char **pos, char *limit, int8_t v);
+int pn_write_ushort(char **pos, char *limit, uint16_t v);
+int pn_write_short(char **pos, char *limit, int16_t v);
+int pn_write_uint(char **pos, char *limit, uint32_t v);
+int pn_write_int(char **pos, char *limit, int32_t v);
+int pn_write_char(char **pos, char *limit, wchar_t v);
+int pn_write_float(char **pos, char *limit, float v);
+int pn_write_ulong(char **pos, char *limit, uint64_t v);
+int pn_write_long(char **pos, char *limit, int64_t v);
+int pn_write_double(char **pos, char *limit, double v);
+int pn_write_binary(char **pos, char *limit, size_t size, char *src);
+int pn_write_utf8(char **pos, char *limit, size_t size, char *utf8);
+int pn_write_symbol(char **pos, char *limit, size_t size, char *symbol);
+int pn_write_start(char **pos, char *limit, char **start);
+int pn_write_list(char **pos, char *limit, char *start, size_t count);
+int pn_write_map(char **pos, char *limit, char *start, size_t count);
+
+typedef struct {
+ void (*on_null)(void *ctx);
+ void (*on_bool)(void *ctx, bool v);
+ void (*on_ubyte)(void *ctx, uint8_t v);
+ void (*on_byte)(void *ctx, int8_t v);
+ void (*on_ushort)(void *ctx, uint16_t v);
+ void (*on_short)(void *ctx, int16_t v);
+ void (*on_uint)(void *ctx, uint32_t v);
+ void (*on_int)(void *ctx, int32_t v);
+ void (*on_float)(void *ctx, float v);
+ void (*on_ulong)(void *ctx, uint64_t v);
+ void (*on_long)(void *ctx, int64_t v);
+ void (*on_double)(void *ctx, double v);
+ void (*on_binary)(void *ctx, size_t size, char *bytes);
+ void (*on_utf8)(void *ctx, size_t size, char *utf8);
+ void (*on_symbol)(void *ctx, size_t size, char *str);
+ void (*start_descriptor)(void *ctx);
+ void (*stop_descriptor)(void *ctx);
+ void (*start_array)(void *ctx, size_t count, uint8_t code);
+ void (*stop_array)(void *ctx, size_t count, uint8_t code);
+ void (*start_list)(void *ctx, size_t count);
+ void (*stop_list)(void *ctx, size_t count);
+ void (*start_map)(void *ctx, size_t count);
+ void (*stop_map)(void *ctx, size_t count);
+} pn_data_callbacks_t;
+
+ssize_t pn_read_datum(char *bytes, size_t n, pn_data_callbacks_t *cb, void *ctx);
+
+#define PN_DATA_CALLBACKS(STEM) ((pn_data_callbacks_t) { \
+ .on_null = & STEM ## _null, \
+ .on_bool = & STEM ## _bool, \
+ .on_ubyte = & STEM ## _ubyte, \
+ .on_byte = & STEM ## _byte, \
+ .on_ushort = & STEM ## _ushort, \
+ .on_short = & STEM ## _short, \
+ .on_uint = & STEM ## _uint, \
+ .on_int = & STEM ## _int, \
+ .on_float = & STEM ## _float, \
+ .on_ulong = & STEM ## _ulong, \
+ .on_long = & STEM ## _long, \
+ .on_double = & STEM ## _double, \
+ .on_binary = & STEM ## _binary, \
+ .on_utf8 = & STEM ## _utf8, \
+ .on_symbol = & STEM ## _symbol, \
+ .start_descriptor = & STEM ## _start_descriptor, \
+ .stop_descriptor = & STEM ## _stop_descriptor, \
+ .start_array = & STEM ## _start_array, \
+ .stop_array = & STEM ## _stop_array, \
+ .start_list = & STEM ## _start_list, \
+ .stop_list = & STEM ## _stop_list, \
+ .start_map = & STEM ## _start_map, \
+ .stop_map = & STEM ## _stop_map, \
+})
+
+extern pn_data_callbacks_t *noop;
+extern pn_data_callbacks_t *printer;
+
+#endif /* codec.h */
Added: qpid/proton/proton-c/include/proton/driver.h
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/include/proton/driver.h?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/include/proton/driver.h (added)
+++ qpid/proton/proton-c/include/proton/driver.h Thu Mar 8 18:33:46 2012
@@ -0,0 +1,48 @@
+#ifndef _PROTON_DRIVER_H
+#define _PROTON_DRIVER_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/engine.h>
+#include <stdlib.h>
+
+typedef struct pn_driver_t pn_driver_t;
+typedef struct pn_selectable_st pn_selectable_t;
+
+#define PN_SEL_RD (0x0001)
+#define PN_SEL_WR (0x0002)
+
+pn_driver_t *pn_driver(void);
+void pn_driver_run(pn_driver_t *d);
+void pn_driver_stop(pn_driver_t *d);
+void pn_driver_destroy(pn_driver_t *d);
+
+pn_selectable_t *pn_acceptor(pn_driver_t *driver, char *host, char *port,
+ void (*cb)(pn_connection_t*, void*),
+ void* context);
+pn_selectable_t *pn_connector(pn_driver_t *driver, char *host, char *port,
+ void (*cb)(pn_connection_t*, void*),
+ void* context);
+
+void pn_selectable_destroy(pn_selectable_t *sel);
+
+#endif /* driver.h */
Added: qpid/proton/proton-c/include/proton/engine.h
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/include/proton/engine.h?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/include/proton/engine.h (added)
+++ qpid/proton/proton-c/include/proton/engine.h Thu Mar 8 18:33:46 2012
@@ -0,0 +1,123 @@
+#ifndef _PROTON_ENGINE_H
+#define _PROTON_ENGINE_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 <stdbool.h>
+#include <stddef.h>
+#include <sys/types.h>
+#include <proton/value.h>
+
+typedef struct pn_error_t pn_error_t;
+typedef struct pn_endpoint_t pn_endpoint_t;
+typedef struct pn_transport_t pn_transport_t;
+typedef struct pn_connection_t pn_connection_t;
+typedef struct pn_session_t pn_session_t;
+typedef struct pn_link_t pn_link_t;
+typedef struct pn_sender_t pn_sender_t;
+typedef struct pn_receiver_t pn_receiver_t;
+typedef struct pn_delivery_t pn_delivery_t;
+
+typedef enum pn_endpoint_state_t {UNINIT=1, ACTIVE=2, CLOSED=4} pn_endpoint_state_t;
+typedef enum pn_endpoint_type_t {CONNECTION=1, TRANSPORT=2, SESSION=3, SENDER=4, RECEIVER=5} pn_endpoint_type_t;
+typedef enum pn_disposition_t {RECEIVED=1, ACCEPTED=2, REJECTED=3, RELEASED=4, MODIFIED=5} pn_disposition_t;
+
+/* Currently the way inheritence is done it is safe to "upcast" from
+ pn_{transport,connection,session,link,sender,or receiver}_t to
+ pn_endpoint_t and to "downcast" based on the endpoint type. I'm
+ not sure if this should be part of the ABI or not. */
+
+// endpoint
+pn_endpoint_type_t pn_endpoint_type(pn_endpoint_t *endpoint);
+pn_endpoint_state_t pn_local_state(pn_endpoint_t *endpoint);
+pn_endpoint_state_t pn_remote_state(pn_endpoint_t *endpoint);
+pn_error_t *pn_local_error(pn_endpoint_t *endpoint);
+pn_error_t *pn_remote_error(pn_endpoint_t *endpoint);
+void pn_destroy(pn_endpoint_t *endpoint);
+void pn_open(pn_endpoint_t *endpoint);
+void pn_close(pn_endpoint_t *endpoint);
+
+// connection
+pn_connection_t *pn_connection();
+pn_delivery_t *pn_work_head(pn_connection_t *connection);
+pn_delivery_t *pn_work_next(pn_delivery_t *delivery);
+
+pn_session_t *pn_session(pn_connection_t *connection);
+pn_transport_t *pn_transport(pn_connection_t *connection);
+
+void pn_endpoint_mask(pn_connection_t *connection, pn_endpoint_state_t local, pn_endpoint_state_t remote);
+pn_endpoint_t *pn_endpoint_head(pn_connection_t *connection,
+ pn_endpoint_state_t local,
+ pn_endpoint_state_t remote);
+pn_endpoint_t *pn_endpoint_next(pn_endpoint_t *endpoint,
+ pn_endpoint_state_t local,
+ pn_endpoint_state_t remote);
+
+// transport
+#define EOS (-1)
+ssize_t pn_input(pn_transport_t *transport, char *bytes, size_t available);
+ssize_t pn_output(pn_transport_t *transport, char *bytes, size_t size);
+time_t pn_tick(pn_transport_t *engine, time_t now);
+
+// session
+pn_sender_t *pn_sender(pn_session_t *session, const wchar_t *name);
+pn_receiver_t *pn_receiver(pn_session_t *session, const wchar_t *name);
+
+// link
+pn_session_t *pn_get_session(pn_link_t *link);
+void pn_set_source(pn_link_t *link, const wchar_t *source);
+void pn_set_target(pn_link_t *link, const wchar_t *target);
+wchar_t *pn_remote_source(pn_link_t *link);
+wchar_t *pn_remote_target(pn_link_t *link);
+pn_delivery_t *pn_delivery(pn_link_t *link, pn_binary_t *tag);
+pn_delivery_t *pn_current(pn_link_t *link);
+bool pn_advance(pn_link_t *link);
+
+pn_delivery_t *pn_unsettled_head(pn_link_t *link);
+pn_delivery_t *pn_unsettled_next(pn_delivery_t *delivery);
+
+// sender
+void pn_offer(pn_sender_t *sender, int credits);
+ssize_t pn_send(pn_sender_t *sender, const char *bytes, size_t n);
+void pn_abort(pn_sender_t *sender);
+
+// receiver
+#define EOM (-1)
+void pn_flow(pn_receiver_t *receiver, int credits);
+ssize_t pn_recv(pn_receiver_t *receiver, char *bytes, size_t n);
+
+// delivery
+pn_binary_t *pn_delivery_tag(pn_delivery_t *delivery);
+pn_link_t *pn_link(pn_delivery_t *delivery);
+// how do we do delivery state?
+int pn_local_disp(pn_delivery_t *delivery);
+int pn_remote_disp(pn_delivery_t *delivery);
+bool pn_writable(pn_delivery_t *delivery);
+bool pn_readable(pn_delivery_t *delivery);
+bool pn_dirty(pn_delivery_t *delivery);
+void pn_clean(pn_delivery_t *delivery);
+void pn_disposition(pn_delivery_t *delivery, pn_disposition_t disposition);
+//int pn_format(pn_delivery_t *delivery);
+void pn_settle(pn_delivery_t *delivery);
+void pn_delivery_dump(pn_delivery_t *delivery);
+
+#endif /* engine.h */
Added: qpid/proton/proton-c/include/proton/framing.h
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/include/proton/framing.h?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/include/proton/framing.h (added)
+++ qpid/proton/proton-c/include/proton/framing.h Thu Mar 8 18:33:46 2012
@@ -0,0 +1,42 @@
+#ifndef _PROTON_FRAMING_H
+#define _PROTON_FRAMING_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 <stdint.h>
+#include <sys/types.h>
+
+#define AMQP_HEADER_SIZE (8)
+
+typedef struct {
+ uint8_t type;
+ uint16_t channel;
+ size_t ex_size;
+ char *extended;
+ size_t size;
+ char *payload;
+} pn_frame_t;
+
+size_t pn_read_frame(pn_frame_t *frame, char *bytes, size_t available);
+size_t pn_write_frame(char *bytes, size_t size, pn_frame_t frame);
+
+#endif /* framing.h */
Added: qpid/proton/proton-c/include/proton/util.h
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/include/proton/util.h?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/include/proton/util.h (added)
+++ qpid/proton/proton-c/include/proton/util.h Thu Mar 8 18:33:46 2012
@@ -0,0 +1,30 @@
+#ifndef _PROTON_UTIL_H
+#define _PROTON_UTIL_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 <stdarg.h>
+
+void pn_fatal(char *fmt, ...);
+void pn_vfatal(char *fmt, va_list ap);
+
+#endif /* util.h */
Added: qpid/proton/proton-c/include/proton/value.h
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/include/proton/value.h?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/include/proton/value.h (added)
+++ qpid/proton/proton-c/include/proton/value.h Thu Mar 8 18:33:46 2012
@@ -0,0 +1,226 @@
+#ifndef _PROTON_VALUE_H
+#define _PROTON_VALUE_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 <stdarg.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <unistd.h>
+
+enum TYPE {
+ EMPTY,
+ BOOLEAN,
+ UBYTE,
+ USHORT,
+ UINT,
+ ULONG,
+ BYTE,
+ SHORT,
+ INT,
+ LONG,
+ FLOAT,
+ DOUBLE,
+ CHAR,
+ STRING,
+ BINARY,
+ ARRAY,
+ LIST,
+ MAP,
+ TAG,
+ REF
+};
+
+typedef struct pn_value_st pn_value_t;
+typedef struct pn_string_st pn_string_t;
+typedef struct pn_binary_st pn_binary_t;
+typedef struct pn_array_st pn_array_t;
+typedef struct pn_list_st pn_list_t;
+typedef struct pn_map_st pn_map_t;
+typedef struct pn_tag_st pn_tag_t;
+
+struct pn_value_st {
+ enum TYPE type;
+ union {
+ bool as_boolean;
+ uint8_t as_ubyte;
+ uint16_t as_ushort;
+ uint32_t as_uint;
+ uint64_t as_ulong;
+ int8_t as_byte;
+ int16_t as_short;
+ int32_t as_int;
+ int64_t as_long;
+ float as_float;
+ double as_double;
+ wchar_t as_char;
+ pn_string_t *as_string;
+ pn_binary_t *as_binary;
+ pn_array_t *as_array;
+ pn_list_t *as_list;
+ pn_map_t *as_map;
+ pn_tag_t *as_tag;
+ void *as_ref;
+ } u;
+};
+
+struct pn_tag_st {
+ pn_value_t descriptor;
+ pn_value_t value;
+};
+
+#define EMPTY_VALUE ((pn_value_t) {.type = EMPTY})
+
+int pn_scan(pn_value_t *value, const char *fmt, ...);
+int pn_vscan(pn_value_t *value, const char *fmt, va_list ap);
+pn_value_t pn_value(const char *fmt, ...);
+pn_value_t pn_vvalue(const char *fmt, va_list ap);
+
+pn_list_t *pn_to_list(pn_value_t v);
+pn_map_t *pn_to_map(pn_value_t v);
+pn_tag_t *pn_to_tag(pn_value_t v);
+void *pn_to_ref(pn_value_t v);
+
+pn_value_t pn_from_list(pn_list_t *l);
+pn_value_t pn_from_map(pn_map_t *m);
+pn_value_t pn_from_tag(pn_tag_t *t);
+pn_value_t pn_from_ref(void *r);
+pn_value_t pn_from_binary(pn_binary_t *b);
+
+int pn_compare_string(pn_string_t *a, pn_string_t *b);
+int pn_compare_binary(pn_binary_t *a, pn_binary_t *b);
+int pn_compare_list(pn_list_t *a, pn_list_t *b);
+int pn_compare_map(pn_map_t *a, pn_map_t *b);
+int pn_compare_tag(pn_tag_t *a, pn_tag_t *b);
+int pn_compare_value(pn_value_t a, pn_value_t b);
+
+uintptr_t pn_hash_string(pn_string_t *s);
+uintptr_t pn_hash_binary(pn_binary_t *b);
+uintptr_t pn_hash_list(pn_list_t *l);
+uintptr_t pn_hash_map(pn_map_t *m);
+uintptr_t pn_hash_tag(pn_tag_t *t);
+uintptr_t pn_hash_value(pn_value_t v);
+
+size_t pn_format_sizeof(pn_value_t v);
+size_t pn_format_sizeof_array(pn_array_t *array);
+size_t pn_format_sizeof_list(pn_list_t *list);
+size_t pn_format_sizeof_map(pn_map_t *map);
+size_t pn_format_sizeof_tag(pn_tag_t *tag);
+
+int pn_format_binary(char **pos, char *limit, pn_binary_t *binary);
+int pn_format_array(char **pos, char *limit, pn_array_t *array);
+int pn_format_list(char **pos, char *limit, pn_list_t *list);
+int pn_format_map(char **pos, char *limit, pn_map_t *map);
+int pn_format_tag(char **pos, char *limit, pn_tag_t *tag);
+int pn_format_value(char **pos, char *limit, pn_value_t *values, size_t n);
+int pn_format(char *buf, size_t size, pn_value_t v);
+char *pn_aformat(pn_value_t v);
+
+size_t pn_encode_sizeof(pn_value_t v);
+size_t pn_encode(pn_value_t v, char *out);
+ssize_t pn_decode(pn_value_t *v, char *bytes, size_t n);
+
+void pn_free_value(pn_value_t v);
+void pn_free_array(pn_array_t *a);
+void pn_free_list(pn_list_t *l);
+void pn_free_map(pn_map_t *m);
+void pn_free_tag(pn_tag_t *t);
+void pn_free_binary(pn_binary_t *b);
+void pn_free_string(pn_string_t *s);
+
+void pn_visit(pn_value_t v, void (*visitor)(pn_value_t));
+void pn_visit_array(pn_array_t *v, void (*visitor)(pn_value_t));
+void pn_visit_list(pn_list_t *l, void (*visitor)(pn_value_t));
+void pn_visit_map(pn_map_t *m, void (*visitor)(pn_value_t));
+void pn_visit_tag(pn_tag_t *t, void (*visitor)(pn_value_t));
+
+/* scalars */
+#define pn_boolean(V) ((pn_value_t) {.type = BOOLEAN, .u.as_boolean = (V)})
+#define pn_uint(V) ((pn_value_t) {.type = UINT, .u.as_uint = (V)})
+#define pn_ulong(V) ((pn_value_t) {.type = ULONG, .u.as_ulong = (V)})
+#define pn_to_uint8(V) ((V).u.as_ubyte)
+#define pn_to_uint16(V) ((V).u.as_ushort)
+#define pn_to_uint32(V) ((V).u.as_uint)
+#define pn_to_int32(V) ((V).u.as_int)
+#define pn_to_bool(V) ((V).u.as_boolean)
+#define pn_to_string(V) ((V).u.as_string)
+#define pn_to_binary(V) ((V).u.as_binary)
+
+
+/* string */
+
+pn_string_t *pn_string(wchar_t *wcs);
+size_t pn_string_size(pn_string_t *str);
+wchar_t *pn_string_wcs(pn_string_t *str);
+
+/* binary */
+
+pn_binary_t *pn_binary(char *bytes, size_t size);
+size_t pn_binary_size(pn_binary_t *b);
+char *pn_binary_bytes(pn_binary_t *b);
+pn_binary_t *pn_binary_dup(pn_binary_t *b);
+
+/* arrays */
+
+pn_array_t *pn_array(enum TYPE type, int capacity);
+pn_value_t pn_array_get(pn_array_t *a, int index);
+size_t pn_encode_sizeof_array(pn_array_t *a);
+size_t pn_encode_array(pn_array_t *array, char *out);
+
+/* lists */
+
+pn_list_t *pn_list(int capacity);
+pn_value_t pn_list_get(pn_list_t *l, int index);
+pn_value_t pn_list_set(pn_list_t *l, int index, pn_value_t v);
+int pn_list_add(pn_list_t *l, pn_value_t v);
+bool pn_list_remove(pn_list_t *l, pn_value_t v);
+pn_value_t pn_list_pop(pn_list_t *l, int index);
+int pn_list_extend(pn_list_t *l, const char *fmt, ...);
+int pn_list_fill(pn_list_t *l, pn_value_t v, int n);
+void pn_list_clear(pn_list_t *l);
+int pn_list_size(pn_list_t *l);
+size_t pn_encode_sizeof_list(pn_list_t *l);
+size_t pn_encode_list(pn_list_t *l, char *out);
+
+/* maps */
+
+pn_map_t *pn_map(int capacity);
+int pn_map_set(pn_map_t *map, pn_value_t key, pn_value_t value);
+pn_value_t pn_map_get(pn_map_t *map, pn_value_t key);
+pn_value_t pn_map_pop(pn_map_t *map, pn_value_t key);
+size_t pn_encode_sizeof_map(pn_map_t *map);
+size_t pn_encode_map(pn_map_t *m, char *out);
+
+/* tags */
+
+pn_tag_t *pn_tag(pn_value_t descriptor, pn_value_t value);
+pn_value_t pn_tag_descriptor(pn_tag_t *t);
+pn_value_t pn_tag_value(pn_tag_t *t);
+size_t pn_encode_sizeof_tag(pn_tag_t *t);
+size_t pn_encode_tag(pn_tag_t *t, char *out);
+
+/* random */
+
+int pn_fmt(char **pos, char *limit, const char *fmt, ...);
+
+#endif /* value.h */
Added: qpid/proton/proton-c/musings.txt
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/musings.txt?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/musings.txt (added)
+++ qpid/proton/proton-c/musings.txt Thu Mar 8 18:33:46 2012
@@ -0,0 +1,15 @@
+
+ - interfaces more connection/transfer oriented with links + sessions
+ as views on the total ordering of messages on the connection
+ + circular buffer of transfers with pointers to the next session and link transfers?
+ - who allocates transfers?
+ + probably engine can manage the transfers themselves
+ - who allocates message data?
+ + if engine then this forces another copy
+ + if user then we need to be able to pass back an empty transfer
+ and have the bytes pointer be supplied by the user
+ - expanded or additional low level interface that would cover
+ creation of multiple network connections, and/por accepting of
+ incoming connections
+ - change sessions and links to be fully contained by connections
+ without independent lifecycle
Added: qpid/proton/proton-c/src/codec/codec.c
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/src/codec/codec.c?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/src/codec/codec.c (added)
+++ qpid/proton/proton-c/src/codec/codec.c Thu Mar 8 18:33:46 2012
@@ -0,0 +1,521 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <arpa/inet.h>
+#include <proton/codec.h>
+#include "encodings.h"
+
+typedef union {
+ uint32_t i;
+ uint32_t a[2];
+ uint64_t l;
+ float f;
+ double d;
+} conv_t;
+
+static int pn_write_code(char **pos, char *limit, uint8_t code) {
+ char *dst = *pos;
+ if (limit - dst < 1) {
+ return -1;
+ } else {
+ dst[0] = code;
+ *pos += 1;
+ return 0;
+ }
+}
+int pn_write_descriptor(char **pos, char *limit) {
+ return pn_write_code(pos, limit, PNE_DESCRIPTOR);
+}
+int pn_write_null(char **pos, char *limit) {
+ return pn_write_code(pos, limit, PNE_NULL);
+}
+
+static int pn_write_fixed8(char **pos, char *limit, uint8_t v, uint8_t code) {
+ char *dst = *pos;
+ if (limit - dst < 2) {
+ return -1;
+ } else {
+ dst[0] = code;
+ dst[1] = v;
+ *pos += 2;
+ return 0;
+ }
+}
+
+int pn_write_boolean(char **pos, char *limit, bool v) {
+ return pn_write_fixed8(pos, limit, v, PNE_BOOLEAN);
+}
+int pn_write_ubyte(char **pos, char *limit, uint8_t v) {
+ return pn_write_fixed8(pos, limit, v, PNE_UBYTE);
+}
+int pn_write_byte(char **pos, char *limit, int8_t v) {
+ return pn_write_fixed8(pos, limit, v, PNE_BYTE);
+}
+
+static int pn_write_fixed16(char **pos, char *limit, uint16_t v,
+ uint8_t code) {
+ char *dst = *pos;
+ if (limit - dst < 3) {
+ return -1;
+ } else {
+ dst[0] = code;
+ *((uint16_t *) (dst + 1)) = htons(v);
+ *pos += 3;
+ return 0;
+ }
+}
+int pn_write_ushort(char **pos, char *limit, uint16_t v) {
+ return pn_write_fixed16(pos, limit, v, PNE_USHORT);
+}
+int pn_write_short(char **pos, char *limit, int16_t v) {
+ return pn_write_fixed16(pos, limit, v, PNE_SHORT);
+}
+
+static int pn_write_fixed32(char **pos, char *limit, uint32_t v, uint8_t code) {
+ char *dst = *pos;
+ if (limit - dst < 5) {
+ return -1;
+ } else {
+ dst[0] = code;
+ *((uint32_t *) (dst + 1)) = htonl(v);
+ *pos += 5;
+ return 0;
+ }
+}
+int pn_write_uint(char **pos, char *limit, uint32_t v) {
+ return pn_write_fixed32(pos, limit, v, PNE_UINT);
+}
+int pn_write_int(char **pos, char *limit, int32_t v) {
+ return pn_write_fixed32(pos, limit, v, PNE_INT);
+}
+int pn_write_char(char **pos, char *limit, wchar_t v) {
+ return pn_write_fixed32(pos, limit, v, PNE_UTF32);
+}
+int pn_write_float(char **pos, char *limit, float v) {
+ conv_t c;
+ c.f = v;
+ return pn_write_fixed32(pos, limit, c.i, PNE_FLOAT);
+}
+
+static int pn_write_fixed64(char **pos, char *limit, uint64_t v, uint8_t code) {
+ char *dst = *pos;
+ if (limit - dst < 9) {
+ return -1;
+ } else {
+ dst[0] = code;
+ uint32_t hi = v >> 32;
+ uint32_t lo = v;
+ *((uint32_t *) (dst + 1)) = htonl(hi);
+ *((uint32_t *) (dst + 5)) = htonl(lo);
+ *pos += 9;
+ return 0;
+ }
+}
+int pn_write_ulong(char **pos, char *limit, uint64_t v) {
+ return pn_write_fixed64(pos, limit, v, PNE_ULONG);
+}
+int pn_write_long(char **pos, char *limit, int64_t v) {
+ return pn_write_fixed64(pos, limit, v, PNE_LONG);
+}
+int pn_write_double(char **pos, char *limit, double v) {
+ conv_t c;
+ c.d = v;
+ return pn_write_fixed64(pos, limit, c.l, PNE_DOUBLE);
+}
+
+#define CONSISTENT (1)
+
+static int pn_write_variable(char **pos, char *limit, size_t size, char *src,
+ uint8_t code8, uint8_t code32) {
+ int n;
+
+ if (!CONSISTENT && size < 256) {
+ if ((n = pn_write_fixed8(pos, limit, size, code8)))
+ return n;
+ } else {
+ if ((n = pn_write_fixed32(pos, limit, size, code32)))
+ return n;
+ }
+
+ if (limit - *pos < size) return -1;
+
+ memmove(*pos, src, size);
+ *pos += size;
+ return 0;
+}
+int pn_write_binary(char **pos, char *limit, size_t size, char *src) {
+ return pn_write_variable(pos, limit, size, src, PNE_VBIN8, PNE_VBIN32);
+}
+int pn_write_utf8(char **pos, char *limit, size_t size, char *utf8) {
+ return pn_write_variable(pos, limit, size, utf8, PNE_STR8_UTF8, PNE_STR32_UTF8);
+}
+int pn_write_symbol(char **pos, char *limit, size_t size, char *symbol) {
+ return pn_write_variable(pos, limit, size, symbol, PNE_SYM8, PNE_SYM32);
+}
+
+int pn_write_start(char **pos, char *limit, char **start) {
+ char *dst = *pos;
+ if (limit - dst < 9) {
+ return -1;
+ } else {
+ *start = dst;
+ *pos += 9;
+ return 0;
+ }
+}
+
+static int pn_write_end(char **pos, char *limit, char *start, size_t count, uint8_t code) {
+ int n;
+ if ((n = pn_write_fixed32(&start, limit, *pos - start - 5, code)))
+ return n;
+ *((uint32_t *) start) = htonl(count);
+ return 0;
+}
+
+int pn_write_list(char **pos, char *limit, char *start, size_t count) {
+ return pn_write_end(pos, limit, start, count, PNE_LIST32);
+}
+
+int pn_write_map(char **pos, char *limit, char *start, size_t count) {
+ return pn_write_end(pos, limit, start, 2*count, PNE_MAP32);
+}
+
+ssize_t pn_read_datum(char *bytes, size_t n, pn_data_callbacks_t *cb, void *ctx);
+
+ssize_t pn_read_type(char *bytes, size_t n, pn_data_callbacks_t *cb, void *ctx, uint8_t *code)
+{
+ if (bytes[0] != PNE_DESCRIPTOR) {
+ *code = bytes[0];
+ return 1;
+ } else {
+ ssize_t offset = 1;
+ ssize_t rcode;
+ cb->start_descriptor(ctx);
+ rcode = pn_read_datum(bytes + offset, n - offset, cb, ctx);
+ cb->stop_descriptor(ctx);
+ if (rcode < 0) return rcode;
+ offset += rcode;
+ rcode = pn_read_type(bytes + offset, n - offset, cb, ctx, code);
+ if (rcode < 0) return rcode;
+ offset += rcode;
+ return offset;
+ }
+}
+
+ssize_t pn_read_encoding(char *bytes, size_t n, pn_data_callbacks_t *cb, void *ctx, uint8_t code)
+{
+ size_t size;
+ size_t count;
+ conv_t conv;
+ ssize_t rcode;
+ int offset = 0;
+
+ switch (code)
+ {
+ case PNE_DESCRIPTOR:
+ return -8;
+ case PNE_NULL:
+ cb->on_null(ctx);
+ return offset;
+ case PNE_TRUE:
+ cb->on_bool(ctx, true);
+ return offset;
+ case PNE_FALSE:
+ cb->on_bool(ctx, false);
+ return offset;
+ case PNE_BOOLEAN:
+ cb->on_bool(ctx, *(bytes + offset) != 0);
+ offset += 1;
+ return offset;
+ case PNE_UBYTE:
+ cb->on_ubyte(ctx, *((uint8_t *) (bytes + offset)));
+ offset += 1;
+ return offset;
+ case PNE_BYTE:
+ cb->on_byte(ctx, *((int8_t *) (bytes + offset)));
+ offset += 1;
+ return offset;
+ case PNE_USHORT:
+ cb->on_ushort(ctx, ntohs(*((uint16_t *) (bytes + offset))));
+ offset += 2;
+ return offset;
+ case PNE_SHORT:
+ cb->on_short(ctx, (int16_t) ntohs(*((int16_t *) (bytes + offset))));
+ offset += 2;
+ return offset;
+ case PNE_UINT:
+ cb->on_uint(ctx, ntohl(*((uint32_t *) (bytes + offset))));
+ offset += 4;
+ return offset;
+ case PNE_UINT0:
+ cb->on_uint(ctx, 0);
+ return offset;
+ case PNE_INT:
+ cb->on_int(ctx, ntohl(*((uint32_t *) (bytes + offset))));
+ offset += 4;
+ return offset;
+ case PNE_FLOAT:
+ // XXX: this assumes the platform uses IEEE floats
+ conv.i = ntohl(*((uint32_t *) (bytes + offset)));
+ cb->on_float(ctx, conv.f);
+ offset += 4;
+ return offset;
+ case PNE_ULONG:
+ case PNE_LONG:
+ case PNE_DOUBLE:
+ {
+ uint32_t hi = ntohl(*((uint32_t *) (bytes + offset)));
+ offset += 4;
+ uint32_t lo = ntohl(*((uint32_t *) (bytes + offset)));
+ offset += 4;
+ conv.l = (((uint64_t) hi) << 32) | lo;
+ }
+
+ switch (code)
+ {
+ case PNE_ULONG:
+ cb->on_ulong(ctx, conv.l);
+ break;
+ case PNE_LONG:
+ cb->on_long(ctx, (int64_t) conv.l);
+ break;
+ case PNE_DOUBLE:
+ // XXX: this assumes the platform uses IEEE floats
+ cb->on_double(ctx, conv.d);
+ break;
+ default:
+ return -1;
+ }
+
+ return offset;
+ case PNE_ULONG0:
+ cb->on_ulong(ctx, 0);
+ return offset;
+ case PNE_VBIN8:
+ case PNE_STR8_UTF8:
+ case PNE_SYM8:
+ case PNE_VBIN32:
+ case PNE_STR32_UTF8:
+ case PNE_SYM32:
+ switch (code & 0xF0)
+ {
+ case 0xA0:
+ size = *(uint8_t *) (bytes + offset);
+ offset += 1;
+ break;
+ case 0xB0:
+ size = ntohl(*(uint32_t *) (bytes + offset));
+ offset += 4;
+ break;
+ default:
+ return -2;
+ }
+
+ {
+ char *start = (char *) (bytes + offset);
+ switch (code & 0x0F)
+ {
+ case 0x0:
+ cb->on_binary(ctx, size, start);
+ break;
+ case 0x1:
+ cb->on_utf8(ctx, size, start);
+ break;
+ case 0x3:
+ cb->on_symbol(ctx, size, start);
+ break;
+ default:
+ return -3;
+ }
+ }
+
+ offset += size;
+ return offset;
+ case PNE_LIST0:
+ count = 0;
+ cb->start_list(ctx, count);
+ cb->stop_list(ctx, count);
+ return offset;
+ case PNE_ARRAY8:
+ case PNE_ARRAY32:
+ case PNE_LIST8:
+ case PNE_LIST32:
+ case PNE_MAP8:
+ case PNE_MAP32:
+ switch (code)
+ {
+ case PNE_ARRAY8:
+ case PNE_LIST8:
+ case PNE_MAP8:
+ size = *(uint8_t *) (bytes + offset);
+ offset += 1;
+ count = *(uint8_t *) (bytes + offset);
+ offset += 1;
+ break;
+ case PNE_ARRAY32:
+ case PNE_LIST32:
+ case PNE_MAP32:
+ size = ntohl(*(uint32_t *) (bytes + offset));
+ offset += 4;
+ count = ntohl(*(uint32_t *) (bytes + offset));
+ offset += 4;
+ break;
+ default:
+ return -4;
+ }
+
+ switch (code)
+ {
+ case PNE_ARRAY8:
+ case PNE_ARRAY32:
+ {
+ uint8_t acode;
+ rcode = pn_read_type(bytes + offset, n - offset, cb, ctx, &acode);
+ cb->start_array(ctx, count, acode);
+ if (rcode < 0) return rcode;
+ offset += rcode;
+ for (int i = 0; i < count; i++)
+ {
+ rcode = pn_read_encoding(bytes + offset, n - offset, cb, ctx, acode);
+ if (rcode < 0) return rcode;
+ offset += rcode;
+ }
+ cb->stop_array(ctx, count, acode);
+ }
+ return offset;
+ case PNE_LIST8:
+ case PNE_LIST32:
+ cb->start_list(ctx, count);
+ break;
+ case PNE_MAP8:
+ case PNE_MAP32:
+ cb->start_map(ctx, count);
+ break;
+ default:
+ return -5;
+ }
+
+ for (int i = 0; i < count; i++)
+ {
+ rcode = pn_read_datum(bytes + offset, n - offset, cb, ctx);
+ if (rcode < 0) return rcode;
+ offset += rcode;
+ }
+
+ switch (code)
+ {
+ case PNE_LIST8:
+ case PNE_LIST32:
+ cb->stop_list(ctx, count);
+ break;
+ case PNE_MAP8:
+ case PNE_MAP32:
+ cb->stop_map(ctx, count);
+ break;
+ default:
+ return -6;
+ }
+
+ return offset;
+ default:
+ printf("Unrecognised typecode: %u\n", code);
+ return -7;
+ }
+}
+
+ssize_t pn_read_datum(char *bytes, size_t n, pn_data_callbacks_t *cb, void *ctx)
+{
+ uint8_t code;
+ ssize_t rcode;
+ size_t offset = 0;
+
+ rcode = pn_read_type(bytes + offset, n - offset, cb, ctx, &code);
+ if (rcode < 0) return rcode;
+ offset += rcode;
+ rcode = pn_read_encoding(bytes + offset, n - offset, cb, ctx, code);
+ if (rcode < 0) return rcode;
+ offset += rcode;
+ return offset;
+}
+
+void noop_null(void *ctx) {}
+void noop_bool(void *ctx, bool v) {}
+void noop_ubyte(void *ctx, uint8_t v) {}
+void noop_byte(void *ctx, int8_t v) {}
+void noop_ushort(void *ctx, uint16_t v) {}
+void noop_short(void *ctx, int16_t v) {}
+void noop_uint(void *ctx, uint32_t v) {}
+void noop_int(void *ctx, int32_t v) {}
+void noop_float(void *ctx, float f) {}
+void noop_ulong(void *ctx, uint64_t v) {}
+void noop_long(void *ctx, int64_t v) {}
+void noop_double(void *ctx, double v) {}
+void noop_binary(void *ctx, size_t size, char *bytes) {}
+void noop_utf8(void *ctx, size_t size, char *bytes) {}
+void noop_symbol(void *ctx, size_t size, char *bytes) {}
+void noop_start_array(void *ctx, size_t count, uint8_t code) {}
+void noop_stop_array(void *ctx, size_t count, uint8_t code) {}
+void noop_start_list(void *ctx, size_t count) {}
+void noop_stop_list(void *ctx, size_t count) {}
+void noop_start_map(void *ctx, size_t count) {}
+void noop_stop_map(void *ctx, size_t count) {}
+void noop_start_descriptor(void *ctx) {}
+void noop_stop_descriptor(void *ctx) {}
+
+pn_data_callbacks_t *noop = &PN_DATA_CALLBACKS(noop);
+
+void print_null(void *ctx) { printf("null\n"); }
+void print_bool(void *ctx, bool v) { if (v) printf("true\n"); else printf("false\n"); }
+void print_ubyte(void *ctx, uint8_t v) { printf("%hhu\n", v); }
+void print_byte(void *ctx, int8_t v) { printf("%hhi\n", v); }
+void print_ushort(void *ctx, uint16_t v) { printf("%hu\n", v); }
+void print_short(void *ctx, int16_t v) { printf("%hi\n", v); }
+void print_uint(void *ctx, uint32_t v) { printf("%u\n", v); }
+void print_int(void *ctx, int32_t v) { printf("%i\n", v); }
+void print_float(void *ctx, float v) { printf("%f\n", v); }
+void print_ulong(void *ctx, uint64_t v) { printf("%"PRIu64"\n", v); }
+void print_long(void *ctx, int64_t v) { printf("%"PRIi64"\n", v); }
+void print_double(void *ctx, double v) { printf("%f\n", v); }
+
+void print_bytes(char *label, int size, char *bytes) {
+ printf("%s(%.*s)\n", label, size, bytes);
+}
+
+void print_binary(void *ctx, size_t size, char *bytes) { print_bytes("bin", size, bytes); }
+void print_utf8(void *ctx, size_t size, char *bytes) { print_bytes("utf8", size, bytes); }
+void print_symbol(void *ctx, size_t size, char *bytes) { print_bytes("sym", size, bytes); }
+void print_start_array(void *ctx, size_t count, uint8_t code) { printf("start array %zd\n", count); }
+void print_stop_array(void *ctx, size_t count, uint8_t code) { printf("stop array %zd\n", count); }
+void print_start_list(void *ctx, size_t count) { printf("start list %zd\n", count); }
+void print_stop_list(void *ctx, size_t count) { printf("stop list %zd\n", count); }
+void print_start_map(void *ctx, size_t count) { printf("start map %zd\n", count); }
+void print_stop_map(void *ctx, size_t count) { printf("stop map %zd\n", count); }
+void print_start_descriptor(void *ctx) { printf("start descriptor "); }
+void print_stop_descriptor(void *ctx) { printf("stop descriptor "); }
+
+pn_data_callbacks_t *printer = &PN_DATA_CALLBACKS(print);
Added: qpid/proton/proton-c/src/codec/encodings.h.py
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/src/codec/encodings.h.py?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/src/codec/encodings.h.py (added)
+++ qpid/proton/proton-c/src/codec/encodings.h.py Thu Mar 8 18:33:46 2012
@@ -0,0 +1,41 @@
+#!/usr/bin/python
+#
+# 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.
+#
+
+import mllib, optparse, os, sys
+
+xml = os.path.join(os.path.dirname(__file__), "types.xml")
+doc = mllib.xml_parse(xml)
+
+print "/* generated from %s */" % xml
+print "#ifndef _PROTON_ENCODINGS_H"
+print "#define _PROTON_ENCODINGS_H 1"
+print
+print "#define PNE_DESCRIPTOR (0x00)"
+
+for enc in doc.query["amqp/section/type/encoding"]:
+ name = enc["@name"] or enc.parent["@name"]
+ # XXX: a bit hacky
+ if name == "ieee-754":
+ name = enc.parent["@name"]
+ cname = "PNE_" + name.replace("-", "_").upper()
+ print "#define %s%s(%s)" % (cname, " "*(20-len(cname)), enc["@code"])
+
+print
+print "#endif /* encodings.h */"
Propchange: qpid/proton/proton-c/src/codec/encodings.h.py
------------------------------------------------------------------------------
svn:executable = *
Added: qpid/proton/proton-c/src/codec/types.xml
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/src/codec/types.xml?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/src/codec/types.xml (added)
+++ qpid/proton/proton-c/src/codec/types.xml Thu Mar 8 18:33:46 2012
@@ -0,0 +1,125 @@
+<?xml version="1.0"?>
+
+<!--
+
+Copyright Bank of America, N.A., Barclays Bank PLC, Cisco Systems, Credit
+Suisse, Deutsche Boerse Systems, Goldman Sachs, HCL Technologies Ltd, INETCO
+Systems Limited, Informatica Corporation, JPMorgan Chase Bank Inc. N.A,
+Microsoft Corporation, my-Channels, Novell, Progress Software, Red Hat Inc.,
+Software AG, Solace Systems Inc., StormMQ Ltd., Tervela Inc., TWIST Process
+Innovations Ltd, VMware Inc. and WS02 Inc. 2006-2011. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-->
+
+<amqp name="types" xmlns="http://www.amqp.org/schema/amqp.xsd">
+ <section name="encodings">
+ <type name="null" class="primitive">
+ <encoding code="0x40" category="fixed" width="0"/>
+ </type>
+ <type name="boolean" class="primitive">
+ <encoding code="0x56" category="fixed" width="1"/>
+ <encoding name="true" code="0x41" category="fixed" width="0"/>
+ <encoding name="false" code="0x42" category="fixed" width="0"/>
+ </type>
+ <type name="ubyte" class="primitive">
+ <encoding code="0x50" category="fixed" width="1"/>
+ </type>
+ <type name="ushort" class="primitive">
+ <encoding code="0x60" category="fixed" width="2"/>
+ </type>
+ <type name="uint" class="primitive">
+ <encoding code="0x70" category="fixed" width="4"/>
+ <encoding name="smalluint" code="0x52" category="fixed" width="1"/>
+ <encoding name="uint0" code="0x43" category="fixed" width="0"/>
+ </type>
+ <type name="ulong" class="primitive">
+ <encoding code="0x80" category="fixed" width="8"/>
+ <encoding name="smallulong" code="0x53" category="fixed" width="1"/>
+ <encoding name="ulong0" code="0x44" category="fixed" width="0"/>
+ </type>
+ <type name="byte" class="primitive">
+ <encoding code="0x51" category="fixed" width="1"/>
+ </type>
+ <type name="short" class="primitive">
+ <encoding code="0x61" category="fixed" width="2"/>
+ </type>
+ <type name="int" class="primitive">
+ <encoding code="0x71" category="fixed" width="4"/>
+ <encoding name="smallint" code="0x54" category="fixed" width="1"/>
+ </type>
+ <type name="long" class="primitive">
+ <encoding code="0x81" category="fixed" width="8"/>
+ <encoding name="smalllong" code="0x55" category="fixed" width="1"/>
+ </type>
+ <type name="float" class="primitive">
+ <encoding name="ieee-754" code="0x72" category="fixed" width="4"/>
+ </type>
+ <type name="double" class="primitive">
+ <encoding name="ieee-754" code="0x82" category="fixed" width="8"/>
+ </type>
+ <type name="decimal32" class="primitive">
+ <encoding name="ieee-754" code="0x74" category="fixed" width="4"/>
+ </type>
+ <type name="decimal64" class="primitive">
+ <encoding name="ieee-754" code="0x84" category="fixed" width="8"/>
+ </type>
+ <type name="decimal128" class="primitive">
+ <encoding name="ieee-754" code="0x94" category="fixed" width="16"/>
+ </type>
+ <type name="char" class="primitive">
+ <encoding name="utf32" code="0x73" category="fixed" width="4"/>
+ </type>
+ <type name="timestamp" class="primitive">
+ <encoding name="ms64" code="0x83" category="fixed" width="8"/>
+ </type>
+ <type name="uuid" class="primitive">
+ <encoding code="0x98" category="fixed" width="16"/>
+ </type>
+ <type name="binary" class="primitive">
+ <encoding name="vbin8" code="0xa0" category="variable" width="1"/>
+ <encoding name="vbin32" code="0xb0" category="variable" width="4"/>
+ </type>
+ <type name="string" class="primitive">
+ <encoding name="str8-utf8" code="0xa1" category="variable" width="1"/>
+ <encoding name="str32-utf8" code="0xb1" category="variable" width="4"/>
+ </type>
+ <type name="symbol" class="primitive">
+ <encoding name="sym8" code="0xa3" category="variable" width="1"/>
+ <encoding name="sym32" code="0xb3" category="variable" width="4"/>
+ </type>
+ <type name="list" class="primitive">
+ <encoding name="list0" code="0x45" category="fixed" width="0"/>
+ <encoding name="list8" code="0xc0" category="compound" width="1"/>
+ <encoding name="list32" code="0xd0" category="compound" width="4"/>
+ </type>
+ <type name="map" class="primitive">
+ <encoding name="map8" code="0xc1" category="compound" width="1"/>
+ <encoding name="map32" code="0xd1" category="compound" width="4"/>
+ </type>
+ <type name="array" class="primitive">
+ <encoding name="array8" code="0xe0" category="array" width="1"/>
+ <encoding name="array32" code="0xf0" category="array" width="4"/>
+ </type>
+ </section>
+</amqp>
Added: qpid/proton/proton-c/src/driver.c
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/src/driver.c?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/src/driver.c (added)
+++ qpid/proton/proton-c/src/driver.c Thu Mar 8 18:33:46 2012
@@ -0,0 +1,431 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#define _POSIX_C_SOURCE 1
+
+#include <poll.h>
+#include <stdio.h>
+#include <time.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <unistd.h>
+
+#include <proton/driver.h>
+#include "util.h"
+
+
+/* Decls */
+
+struct pn_driver_t {
+ pn_selectable_t *head;
+ pn_selectable_t *tail;
+ size_t size;
+ int ctrl[2];//pipe for updating selectable status
+ bool stopping;
+};
+
+struct pn_selectable_st {
+ pn_driver_t *driver;
+ pn_selectable_t *next;
+ pn_selectable_t *prev;
+ int fd;
+ int status;
+ time_t wakeup;
+ void (*readable)(pn_selectable_t *s);
+ void (*writable)(pn_selectable_t *s);
+ time_t (*tick)(pn_selectable_t *s, time_t now);
+ void (*destroy)(pn_selectable_t *s);
+ void *context;
+};
+
+/* Impls */
+
+pn_driver_t *pn_driver()
+{
+ pn_driver_t *d = malloc(sizeof(pn_driver_t));
+ if (!d) return NULL;
+ d->head = NULL;
+ d->tail = NULL;
+ d->size = 0;
+ d->ctrl[0] = 0;
+ d->ctrl[1] = 0;
+ d ->stopping = false;
+ return d;
+}
+
+void pn_driver_destroy(pn_driver_t *d)
+{
+ while (d->head)
+ pn_selectable_destroy(d->head);
+ free(d);
+}
+
+static void pn_driver_add(pn_driver_t *d, pn_selectable_t *s)
+{
+ LL_ADD(d->head, d->tail, s);
+ s->driver = d;
+ d->size++;
+}
+
+static void pn_driver_remove(pn_driver_t *d, pn_selectable_t *s)
+{
+ LL_REMOVE(d->head, d->tail, s);
+ s->driver = NULL;
+ d->size--;
+}
+
+void pn_driver_run(pn_driver_t *d)
+{
+ int i, nfds = 0;
+ struct pollfd *fds = NULL;
+
+ if (pipe(d->ctrl)) {
+ perror("Can't create control pipe");
+ }
+ while (!d->stopping)
+ {
+ int n = d->size;
+ if (n == 0) break;
+ if (n > nfds) {
+ fds = realloc(fds, (n+1)*sizeof(struct pollfd));
+ nfds = n;
+ }
+
+ pn_selectable_t *s = d->head;
+ for (i = 0; i < n; i++)
+ {
+ fds[i].fd = s->fd;
+ fds[i].events = (s->status & PN_SEL_RD ? POLLIN : 0) |
+ (s->status & PN_SEL_WR ? POLLOUT : 0);
+ fds[i].revents = 0;
+ if (s->tick) {
+ // XXX
+ s->tick(s, 0);
+ }
+ s = s->next;
+ }
+ fds[n].fd = d->ctrl[0];
+ fds[n].events = POLLIN;
+ fds[n].revents = 0;
+
+ DIE_IFE(poll(fds, n+1, -1));
+
+ s = d->head;
+ for (i = 0; i < n; i++)
+ {
+ if (fds[i].revents & POLLIN)
+ s->readable(s);
+ if (fds[i].revents & POLLOUT)
+ s->writable(s);
+ s = s->next;
+ }
+
+ if (fds[n].revents & POLLIN) {
+ //clear the pipe
+ char buffer[512];
+ while (read(d->ctrl[0], buffer, 512) == 512);
+ }
+ }
+
+ close(d->ctrl[0]);
+ close(d->ctrl[1]);
+ free(fds);
+}
+
+void pn_driver_stop(pn_driver_t *d)
+{
+ d->stopping = true;
+ write(d->ctrl[1], "x", 1);
+}
+
+static pn_selectable_t *pn_selectable()
+{
+ pn_selectable_t *s = malloc(sizeof(pn_selectable_t));
+ if (!s) return NULL;
+ s->driver = NULL;
+ s->next = NULL;
+ s->prev = NULL;
+ s->status = 0;
+ s->wakeup = 0;
+ s->readable = NULL;
+ s->writable = NULL;
+ s->tick = NULL;
+ s->destroy = NULL;
+ s->context = NULL;
+ return s;
+}
+
+void pn_selectable_destroy(pn_selectable_t *s)
+{
+ if (s->driver) pn_driver_remove(s->driver, s);
+ if (s->destroy) s->destroy(s);
+ free(s);
+}
+
+// engine related
+
+#define IO_BUF_SIZE (4*1024)
+
+struct pn_engine_ctx {
+ pn_connection_t *connection;
+ pn_transport_t *transport;
+ int in_size;
+ int out_size;
+ char input[IO_BUF_SIZE];
+ char output[IO_BUF_SIZE];
+ void (*callback)(pn_connection_t*, void*);
+ void *context;
+};
+
+static void pn_selectable_engine_close(pn_selectable_t *sel)
+{
+ sel->status = 0;
+ if (close(sel->fd) == -1)
+ perror("close");
+ pn_driver_remove(sel->driver, sel);
+ pn_selectable_destroy(sel);
+}
+
+static struct pn_engine_ctx *pn_selectable_engine_read(pn_selectable_t *sel)
+{
+ struct pn_engine_ctx *ctx = sel->context;
+ ssize_t n = recv(sel->fd, ctx->input + ctx->in_size, IO_BUF_SIZE - ctx->in_size, 0);
+
+ if (n <= 0) {
+ printf("disconnected: %zi\n", n);
+ pn_selectable_engine_close(sel);
+ return NULL;
+ } else {
+ ctx->in_size += n;
+ }
+ return ctx;
+}
+
+static void pn_selectable_engine_consume(struct pn_engine_ctx *ctx, int n)
+{
+ ctx->in_size -= n;
+ memmove(ctx->input, ctx->input + n, ctx->in_size);
+}
+
+static void pn_engine_readable_input(pn_selectable_t *sel, struct pn_engine_ctx *ctx)
+{
+ pn_transport_t *transport = ctx->transport;
+ ssize_t n = pn_input(transport, ctx->input, ctx->in_size);
+ if (n < 0) {
+ if (n != EOS) {
+ printf("error: %zi\n", n);
+ }
+ pn_selectable_engine_close(sel);
+ } else {
+ pn_selectable_engine_consume(ctx, n);
+ }
+}
+
+static void pn_engine_readable(pn_selectable_t *sel)
+{
+ struct pn_engine_ctx *ctx = pn_selectable_engine_read(sel);
+ if (ctx) pn_engine_readable_input(sel, ctx);
+}
+
+static void pn_engine_readable_hdr(pn_selectable_t *sel)
+{
+ struct pn_engine_ctx *ctx = pn_selectable_engine_read(sel);
+
+ if (!ctx)
+ return;
+
+ if (ctx->in_size >= 8) {
+ if (memcmp(ctx->input, "AMQP\x00\x01\x00\x00", 8)) {
+ printf("header missmatch");
+ pn_selectable_engine_close(sel);
+ } else {
+ pn_selectable_engine_consume(ctx, 8);
+ sel->readable = &pn_engine_readable;
+ pn_engine_readable_input(sel, ctx);
+ }
+ }
+}
+
+static void pn_engine_writable(pn_selectable_t *sel)
+{
+ struct pn_engine_ctx *ctx = sel->context;
+ pn_transport_t *transport = ctx->transport;
+ ssize_t n = pn_output(transport, ctx->output + ctx->out_size, IO_BUF_SIZE - ctx->out_size);
+ if (n < 0) {
+ printf("internal error: %zi", n);
+ pn_selectable_engine_close(sel);
+ } else {
+ ctx->out_size += n;
+ n = send(sel->fd, ctx->output, ctx->out_size, 0);
+ if (n < 0) {
+ // XXX
+ perror("writable");
+ } else {
+ ctx->out_size -= n;
+ memmove(ctx->output, ctx->output + n, ctx->out_size);
+ }
+ if (ctx->out_size)
+ sel->status |= PN_SEL_WR;
+ else
+ sel->status &= ~PN_SEL_WR;
+ }
+}
+
+static time_t pn_selectable_engine_tick(pn_selectable_t *sel, time_t now)
+{
+ struct pn_engine_ctx *ctx = sel->context;
+ time_t result = pn_tick(ctx->transport, now);
+ if (ctx->callback) ctx->callback(ctx->connection, ctx->context);
+ pn_engine_writable(sel);
+ return result;
+}
+
+static void pn_engine_destroy(pn_selectable_t *s)
+{
+ struct pn_engine_ctx *ctx = s->context;
+ if (ctx) {
+ pn_destroy((pn_endpoint_t *)ctx->connection);
+ free(ctx);
+ s->context = NULL;
+ }
+}
+
+static pn_selectable_t *pn_selectable_engine(int sock, pn_connection_t *conn,
+ void (*cb)(pn_connection_t*, void*), void* ctx)
+{
+ pn_selectable_t *sel = pn_selectable();
+ sel->fd = sock;
+ sel->readable = &pn_engine_readable_hdr;
+ sel->writable = &pn_engine_writable;
+ sel->destroy = &pn_engine_destroy;
+ sel->tick = &pn_selectable_engine_tick;
+ sel->status = PN_SEL_RD | PN_SEL_WR;
+ struct pn_engine_ctx *sctx = malloc(sizeof(struct pn_engine_ctx));
+ sctx->connection = conn;
+ sctx->transport = pn_transport(conn);
+ sctx->in_size = 0;
+ memmove(sctx->output, "AMQP\x00\x01\x00\x00", 8);
+ sctx->out_size = 8;
+ sctx->callback = cb;
+ sctx->context = ctx;
+ sel->context = sctx;
+ return sel;
+}
+
+pn_selectable_t *pn_connector(pn_driver_t *drv, char *host, char *port,
+ void (*cb)(pn_connection_t*, void*), void* ctx)
+{
+ struct addrinfo *addr;
+ int code = getaddrinfo(host, port, NULL, &addr);
+ if (code) {
+ fprintf(stderr, "%s", gai_strerror(code));
+ return NULL;
+ }
+
+ int sock = socket(AF_INET, SOCK_STREAM, getprotobyname("tcp")->p_proto);
+ if (sock == -1)
+ return NULL;
+
+ if (connect(sock, addr->ai_addr, addr->ai_addrlen) == -1) {
+ freeaddrinfo(addr);
+ return NULL;
+ }
+
+ freeaddrinfo(addr);
+
+ pn_connection_t *conn = pn_connection();
+ pn_selectable_t *s = pn_selectable_engine(sock, conn, cb, ctx);
+
+ pn_driver_add(drv, s);
+ printf("Connected to %s:%s\n", host, port);
+ return s;
+}
+
+static void do_accept(pn_selectable_t *s)
+{
+ struct sockaddr_in addr = {0};
+ addr.sin_family = AF_INET;
+ socklen_t addrlen = sizeof(addr);
+ int sock = accept(s->fd, (struct sockaddr *) &addr, &addrlen);
+ if (sock == -1) {
+ perror("accept");
+ } else {
+ char host[1024], serv[64];
+ int code;
+ if ((code = getnameinfo((struct sockaddr *) &addr, addrlen, host, 1024, serv, 64, 0))) {
+ printf("getnameinfo: %s\n", gai_strerror(code));
+ if (close(sock) == -1)
+ perror("close");
+ } else {
+ printf("accepted from %s:%s\n", host, serv);
+ pn_connection_t *conn = pn_connection();
+ struct pn_engine_ctx *ctx = s->context;
+ pn_selectable_t *a = pn_selectable_engine(sock, conn, ctx->callback, ctx->context);
+ a->status = PN_SEL_RD | PN_SEL_WR;
+ pn_driver_add(s->driver, a);
+ }
+ }
+}
+
+pn_selectable_t *pn_acceptor(pn_driver_t *drv, char *host, char *port,
+ void (*cb)(pn_connection_t*, void*), void* context)
+{
+ struct addrinfo *addr;
+ int code = getaddrinfo(host, port, NULL, &addr);
+ if (code) {
+ fprintf(stderr, "%s", gai_strerror(code));
+ return NULL;
+ }
+
+ int sock = socket(AF_INET, SOCK_STREAM, getprotobyname("tcp")->p_proto);
+ if (sock == -1)
+ return NULL;
+
+ int optval = 1;
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1)
+ return NULL;
+
+ if (bind(sock, addr->ai_addr, addr->ai_addrlen) == -1) {
+ freeaddrinfo(addr);
+ return NULL;
+ }
+
+ freeaddrinfo(addr);
+
+ if (listen(sock, 50) == -1)
+ return NULL;
+
+ pn_selectable_t *s = pn_selectable();
+ s->fd = sock;
+ s->readable = &do_accept;
+ s->writable = NULL;
+ s->status = PN_SEL_RD;
+ struct pn_engine_ctx *ctx = malloc(sizeof(struct pn_engine_ctx));
+ ctx->callback = cb;
+ ctx->context = context;
+ s->context = ctx;
+
+ pn_driver_add(drv, s);
+ printf("Listening on %s:%s\n", host, port);
+ return s;
+}
Added: qpid/proton/proton-c/src/engine/engine-internal.h
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/src/engine/engine-internal.h?rev=1298498&view=auto
==============================================================================
--- qpid/proton/proton-c/src/engine/engine-internal.h (added)
+++ qpid/proton/proton-c/src/engine/engine-internal.h Thu Mar 8 18:33:46 2012
@@ -0,0 +1,205 @@
+#ifndef _PROTON_ENGINE_INTERNAL_H
+#define _PROTON_ENGINE_INTERNAL_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/engine.h>
+#include <proton/value.h>
+#include "../util.h"
+
+#define DESCRIPTION (1024)
+
+struct pn_error_t {
+ const char *condition;
+ char description[DESCRIPTION];
+ pn_map_t *info;
+};
+
+struct pn_endpoint_t {
+ pn_endpoint_type_t type;
+ pn_endpoint_state_t local_state, remote_state;
+ pn_error_t local_error, remote_error;
+ pn_endpoint_t *endpoint_next;
+ pn_endpoint_t *endpoint_prev;
+ pn_endpoint_t *transport_next;
+ pn_endpoint_t *transport_prev;
+ bool modified;
+};
+
+typedef int32_t pn_sequence_t;
+
+typedef struct {
+ pn_delivery_t *delivery;
+ pn_sequence_t id;
+ bool sent;
+} pn_delivery_state_t;
+
+typedef struct {
+ pn_sequence_t next;
+ size_t capacity;
+ size_t head;
+ size_t size;
+ pn_delivery_state_t *deliveries;
+} pn_delivery_buffer_t;
+
+typedef struct {
+ pn_link_t *link;
+ // XXX: stop using negative numbers
+ uint32_t local_handle;
+ uint32_t remote_handle;
+ pn_sequence_t delivery_count;
+ // XXX: this is only used for receiver
+ pn_sequence_t link_credit;
+} pn_link_state_t;
+
+typedef struct {
+ pn_session_t *session;
+ // XXX: stop using negative numbers
+ uint16_t local_channel;
+ uint16_t remote_channel;
+ pn_delivery_buffer_t incoming;
+ pn_delivery_buffer_t outgoing;
+ pn_link_state_t *links;
+ size_t link_capacity;
+ pn_link_state_t **handles;
+ size_t handle_capacity;
+} pn_session_state_t;
+
+#define SCRATCH (1024)
+
+struct pn_transport_t {
+ pn_endpoint_t endpoint;
+ pn_connection_t *connection;
+ pn_map_t *dispatch;
+ pn_list_t *args;
+ const char* payload_bytes;
+ size_t payload_size;
+ char *output;
+ size_t available;
+ size_t capacity;
+ bool open_sent;
+ bool close_sent;
+ pn_session_state_t *sessions;
+ size_t session_capacity;
+ pn_session_state_t **channels;
+ size_t channel_capacity;
+ char scratch[SCRATCH];
+};
+
+struct pn_connection_t {
+ pn_endpoint_t endpoint;
+ pn_endpoint_t *endpoint_head;
+ pn_endpoint_t *endpoint_tail;
+ pn_endpoint_t *transport_head;
+ pn_endpoint_t *transport_tail;
+ pn_session_t **sessions;
+ size_t session_capacity;
+ size_t session_count;
+ pn_transport_t *transport;
+ pn_delivery_t *work_head;
+ pn_delivery_t *work_tail;
+ pn_delivery_t *tpwork_head;
+ pn_delivery_t *tpwork_tail;
+};
+
+struct pn_session_t {
+ pn_endpoint_t endpoint;
+ pn_connection_t *connection;
+ pn_link_t **links;
+ size_t link_capacity;
+ size_t link_count;
+ size_t id;
+};
+
+struct pn_link_t {
+ pn_endpoint_t endpoint;
+ wchar_t *name;
+ pn_session_t *session;
+ const wchar_t *local_source;
+ const wchar_t *local_target;
+ wchar_t *remote_source;
+ wchar_t *remote_target;
+ pn_delivery_t *head;
+ pn_delivery_t *tail;
+ pn_delivery_t *current;
+ pn_delivery_t *settled_head;
+ pn_delivery_t *settled_tail;
+ pn_sequence_t credit;
+ size_t id;
+};
+
+struct pn_sender_t {
+ pn_link_t link;
+};
+
+struct pn_receiver_t {
+ pn_link_t link;
+ pn_sequence_t credits;
+};
+
+struct pn_delivery_t {
+ pn_link_t *link;
+ pn_binary_t *tag;
+ int local_state;
+ int remote_state;
+ bool local_settled;
+ bool remote_settled;
+ bool dirty;
+ pn_delivery_t *link_next;
+ pn_delivery_t *link_prev;
+ pn_delivery_t *work_next;
+ pn_delivery_t *work_prev;
+ bool work;
+ pn_delivery_t *tpwork_next;
+ pn_delivery_t *tpwork_prev;
+ bool tpwork;
+ char *bytes;
+ size_t size;
+ size_t capacity;
+ void *context;
+};
+
+void pn_destroy_connection(pn_connection_t *connection);
+void pn_destroy_transport(pn_transport_t *transport);
+void pn_destroy_session(pn_session_t *session);
+void pn_destroy_sender(pn_sender_t *sender);
+void pn_destroy_receiver(pn_receiver_t *receiver);
+
+void pn_link_dump(pn_link_t *link);
+
+#define PN_ENSURE(ARRAY, CAPACITY, COUNT) \
+ while ((CAPACITY) < (COUNT)) { \
+ (CAPACITY) = (CAPACITY) ? 2 * (CAPACITY) : 16; \
+ (ARRAY) = realloc((ARRAY), (CAPACITY) * sizeof (*(ARRAY))); \
+ } \
+
+#define PN_ENSUREZ(ARRAY, CAPACITY, COUNT) \
+ { \
+ size_t _old_capacity = (CAPACITY); \
+ PN_ENSURE((ARRAY), (CAPACITY), (COUNT)); \
+ memset((ARRAY) + _old_capacity, 0, \
+ sizeof(*(ARRAY))*((CAPACITY) - _old_capacity)); \
+ }
+
+void pn_dump(pn_connection_t *conn);
+
+#endif /* engine-internal.h */
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org