Author: rhs
Date: Sun Nov  4 23:20:41 2012
New Revision: 1405665

URL: http://svn.apache.org/viewvc?rev=1405665&view=rev
Log:
added C examples based patches from PROTON-43, reorganized the examples to make 
a bit more sense, removed the unmaintained broker examples

Added:
    qpid/proton/trunk/proton-c/examples/
      - copied from r1405615, qpid/proton/trunk/examples/
    qpid/proton/trunk/proton-c/examples/messenger/c/
    qpid/proton/trunk/proton-c/examples/messenger/c/CMakeLists.txt
    qpid/proton/trunk/proton-c/examples/messenger/c/recv.c
    qpid/proton/trunk/proton-c/examples/messenger/c/send.c
    qpid/proton/trunk/proton-c/examples/messenger/py/
    qpid/proton/trunk/proton-c/examples/messenger/py/README.txt
      - copied unchanged from r1405615, 
qpid/proton/trunk/examples/messenger/README.txt
    qpid/proton/trunk/proton-c/examples/messenger/py/client.py
      - copied unchanged from r1405615, 
qpid/proton/trunk/examples/messenger/client.py
    qpid/proton/trunk/proton-c/examples/messenger/py/recv.py
      - copied unchanged from r1405615, 
qpid/proton/trunk/examples/messenger/recv.py
    qpid/proton/trunk/proton-c/examples/messenger/py/send.py
      - copied unchanged from r1405615, 
qpid/proton/trunk/examples/messenger/send.py
    qpid/proton/trunk/proton-c/examples/messenger/py/server.py
      - copied unchanged from r1405615, 
qpid/proton/trunk/examples/messenger/server.py
Removed:
    qpid/proton/trunk/examples/
    qpid/proton/trunk/proton-c/examples/broker/
    qpid/proton/trunk/proton-c/examples/messenger/README.txt
    qpid/proton/trunk/proton-c/examples/messenger/client.py
    qpid/proton/trunk/proton-c/examples/messenger/recv.py
    qpid/proton/trunk/proton-c/examples/messenger/send.py
    qpid/proton/trunk/proton-c/examples/messenger/server.py
Modified:
    qpid/proton/trunk/proton-c/CMakeLists.txt

Modified: qpid/proton/trunk/proton-c/CMakeLists.txt
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/CMakeLists.txt?rev=1405665&r1=1405664&r2=1405665&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/CMakeLists.txt (original)
+++ qpid/proton/trunk/proton-c/CMakeLists.txt Sun Nov  4 23:20:41 2012
@@ -64,6 +64,8 @@ else()
     add_custom_target(docs)
 endif()
 
+set (PN_COMPILE_FLAGS "-Wall -Werror -pedantic-errors -std=c99")
+
 # Set the default SSL/TLS implementation
 find_package(OpenSSL)
 
@@ -107,6 +109,7 @@ if (SWIG_FOUND)
 endif (SWIG_FOUND)
 
 add_subdirectory(docs/api)
+add_subdirectory(examples/messenger/c)
 
 # Should really be finding the uuid library appropriate for the platform
 # in lieu of doing this set the library name directly.
@@ -154,15 +157,15 @@ target_link_libraries (proton-dump qpid-
 set_target_properties (
   qpid-proton
   PROPERTIES
-  COMPILE_FLAGS "-Wall -Werror -pedantic-errors -std=c99 -g -Iinclude -fPIC"
+  COMPILE_FLAGS "${PN_COMPILE_FLAGS}"
   VERSION   "${PN_LIB_SOMAJOR}.${PN_LIB_SOMINOR}"
   SOVERSION "${PN_LIB_SOMAJOR}"
 )
 
 set_target_properties (
-   proton proton-dump
+  proton proton-dump
   PROPERTIES
-  COMPILE_FLAGS "-Wall -Werror -pedantic-errors -std=c99 -g -Iinclude -fPIC"
+  COMPILE_FLAGS "${PN_COMPILE_FLAGS}"
 )
 
 # Install executables and libraries

Added: qpid/proton/trunk/proton-c/examples/messenger/c/CMakeLists.txt
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/examples/messenger/c/CMakeLists.txt?rev=1405665&view=auto
==============================================================================
--- qpid/proton/trunk/proton-c/examples/messenger/c/CMakeLists.txt (added)
+++ qpid/proton/trunk/proton-c/examples/messenger/c/CMakeLists.txt Sun Nov  4 
23:20:41 2012
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+
+add_executable(recv recv.c)
+add_executable(send send.c)
+
+target_link_libraries(recv qpid-proton)
+target_link_libraries(send qpid-proton)
+
+set_target_properties (
+  recv send
+  PROPERTIES
+  COMPILE_FLAGS "${PN_COMPILE_FLAGS}"
+)

Added: qpid/proton/trunk/proton-c/examples/messenger/c/recv.c
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/examples/messenger/c/recv.c?rev=1405665&view=auto
==============================================================================
--- qpid/proton/trunk/proton-c/examples/messenger/c/recv.c (added)
+++ qpid/proton/trunk/proton-c/examples/messenger/c/recv.c Sun Nov  4 23:20:41 
2012
@@ -0,0 +1,152 @@
+/*
+ * 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 <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <error.h>
+#include <ctype.h>
+
+#define check(messenger)                                         \
+  {                                                              \
+    if(pn_messenger_errno(messenger))                            \
+    {                                                            \
+      die(__FILE__, __LINE__, pn_messenger_error(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);
+}
+
+int main(int argc, char** argv)
+{
+  char* certificate = NULL;
+  char* privatekey = NULL;
+  char* password = NULL;
+  char* address = "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((argc - optind) > 0)
+  {
+    address = argv[argc - optind];
+  }
+
+  pn_message_t * message;
+  pn_messenger_t * messenger;
+
+  message = pn_message();
+  messenger = pn_messenger(NULL);
+
+  /* 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);
+
+  for(;;)
+  {
+    pn_messenger_recv(messenger, 1024);
+    check(messenger);
+
+    while(pn_messenger_incoming(messenger))
+    {
+      pn_messenger_get(messenger, message);
+      check(messenger);
+
+      size_t buffsize = 1024;
+      char buffer[buffsize];
+      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;
+}

Added: qpid/proton/trunk/proton-c/examples/messenger/c/send.c
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/examples/messenger/c/send.c?rev=1405665&view=auto
==============================================================================
--- qpid/proton/trunk/proton-c/examples/messenger/c/send.c (added)
+++ qpid/proton/trunk/proton-c/examples/messenger/c/send.c Sun Nov  4 23:20:41 
2012
@@ -0,0 +1,108 @@
+/*
+ * 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 <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <error.h>
+#include <ctype.h>
+
+#define check(messenger)                                         \
+  {                                                              \
+    if(pn_messenger_errno(messenger))                            \
+    {                                                            \
+      die(__FILE__, __LINE__, pn_messenger_error(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: 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);
+}
+
+int main(int argc, char** argv)
+{
+  int c;
+  opterr = 0;
+  char * address = "amqp://0.0.0.0";
+  char * msgtext = "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((argc - optind) > 0) msgtext = argv[argc - optind];
+
+  pn_message_t * message;
+  pn_messenger_t * messenger;
+
+  message = pn_message();
+  messenger = pn_messenger(NULL);
+
+  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);
+  check(messenger);
+
+  pn_messenger_stop(messenger);
+  pn_messenger_free(messenger);
+
+  return 0;
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to