|
From: <jl...@us...> - 2008-09-15 20:31:53
|
Revision: 4293
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=4293&view=rev
Author: jleibs
Date: 2008-09-15 20:32:00 +0000 (Mon, 15 Sep 2008)
Log Message:
-----------
Checking in a minimal curl test case. Hopefully I can remove this
once bug is resolved. If it can be made more deterministic, it might
serve as the basis for an eventual unit test that ought to be added
to roscpp.
Added Paths:
-----------
pkg/trunk/curltest/
pkg/trunk/curltest/CMakeLists.txt
pkg/trunk/curltest/Makefile
pkg/trunk/curltest/curlnode.cpp
pkg/trunk/curltest/curltest.cpp
pkg/trunk/curltest/curltest.h
pkg/trunk/curltest/manifest.xml
Added: pkg/trunk/curltest/CMakeLists.txt
===================================================================
--- pkg/trunk/curltest/CMakeLists.txt (rev 0)
+++ pkg/trunk/curltest/CMakeLists.txt 2008-09-15 20:32:00 UTC (rev 4293)
@@ -0,0 +1,13 @@
+cmake_minimum_required(VERSION 2.6)
+include(rosbuild)
+rospack(curltest)
+
+find_library(curl REQUIRED)
+
+set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
+
+rospack_add_executable(curltest curlnode.cpp curltest.cpp)
+target_link_libraries(curltest curl)
+
+
+
Added: pkg/trunk/curltest/Makefile
===================================================================
--- pkg/trunk/curltest/Makefile (rev 0)
+++ pkg/trunk/curltest/Makefile 2008-09-15 20:32:00 UTC (rev 4293)
@@ -0,0 +1 @@
+include $(shell rospack find mk)/cmake.mk
Added: pkg/trunk/curltest/curlnode.cpp
===================================================================
--- pkg/trunk/curltest/curlnode.cpp (rev 0)
+++ pkg/trunk/curltest/curlnode.cpp 2008-09-15 20:32:00 UTC (rev 4293)
@@ -0,0 +1,81 @@
+///////////////////////////////////////////////////////////////////////////////
+// The axis_cam package provides a library that talks to Axis IP-based cameras
+// as well as ROS nodes which use these libraries
+//
+// Copyright (C) 2008, Morgan Quigley
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * 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.
+// * Neither the name of Stanford University nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
+
+#include "ros/node.h"
+#include "curltest.h"
+#include "std_msgs/String.h"
+
+class CurlNode : public ros::node
+{
+public:
+ CurlTest *curl;
+
+ std_msgs::String msg_out;
+
+ CurlNode() : node("curltest"), curl(NULL)
+ {
+ advertise<std_msgs::String>("chatter",1);
+
+ curl = new CurlTest(string("axis-00408c7dfe2b.local"));
+ }
+
+ virtual ~CurlNode()
+ {
+ if (curl)
+ delete curl;
+ }
+
+ bool spin()
+ {
+ while (ok())
+ {
+ if (curl->get())
+ log(ros::ERROR,"Get failed.");
+
+ msg_out.data = (char*)(curl->buf);
+ publish("chatter", msg_out);
+ }
+ return true;
+ }
+
+};
+
+int main(int argc, char **argv)
+{
+ ros::init(argc, argv);
+
+ CurlNode n;
+
+ n.spin();
+
+ ros::fini();
+
+ return 0;
+}
+
Added: pkg/trunk/curltest/curltest.cpp
===================================================================
--- pkg/trunk/curltest/curltest.cpp (rev 0)
+++ pkg/trunk/curltest/curltest.cpp 2008-09-15 20:32:00 UTC (rev 4293)
@@ -0,0 +1,118 @@
+///////////////////////////////////////////////////////////////////////////////
+// The axis_cam package provides a library that talks to Axis IP-based cameras
+// as well as ROS nodes which use these libraries
+//
+// Copyright (C) 2008, Morgan Quigley, Stanford Univerity
+// Jeremy Leibs, Willow Garage
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * 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.
+// * Neither the name of Stanford University, Willow Garage, nor the names
+// of its contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
+
+#include "curltest.h"
+
+#define RETURN_CURL_ERR(curl, code) \
+ fprintf(stderr, "curl error: [%s]\n", curl_easy_strerror(code)); \
+ if (code == 22) \
+ { \
+ int http_code; \
+ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); \
+ fprintf(stderr, "HTTP response: %d\n", http_code); \
+ return http_code; \
+ } \
+ return code; \
+
+CurlTest::CurlTest(string ip) : ip(ip)
+{
+ buf = NULL;
+ buf_size = 0;
+
+ ostringstream oss;
+
+ oss << "http://" << ip << "/axis-cgi/com/ptz.cgi";
+ url = new char[oss.str().length()+1];
+ strcpy(url, oss.str().c_str());
+
+ curl_global_init(0);
+
+ get_curl = curl_easy_init();
+
+ curl_easy_setopt(get_curl, CURLOPT_URL, url);
+ curl_easy_setopt(get_curl, CURLOPT_WRITEFUNCTION, CurlTest::buf_write);
+ curl_easy_setopt(get_curl, CURLOPT_WRITEDATA, this);
+ curl_easy_setopt(get_curl, CURLOPT_POSTFIELDS, "query=position");
+ curl_easy_setopt(get_curl, CURLOPT_TIMEOUT, 1);
+ curl_easy_setopt(get_curl, CURLOPT_FAILONERROR, 1);
+}
+
+CurlTest::~CurlTest()
+{
+ if (buf)
+ delete[] buf;
+
+ buf = NULL;
+ curl_global_cleanup();
+}
+
+size_t CurlTest::buf_write(void *buf, size_t size, size_t nmemb, void *userp)
+{
+ if (size * nmemb == 0)
+ return 0;
+
+ CurlTest *a = (CurlTest *)userp;
+
+ if (a->buf_file_size + size*nmemb >= a->buf_size)
+ {
+ a->buf_size = 2 * (a->buf_file_size + (size*nmemb));
+
+ uint8_t* tmp = new uint8_t[a->buf_size];
+
+ if (a->buf)
+ {
+ memcpy(tmp, a->buf, a->buf_file_size);
+ delete[] a->buf;
+ } else {
+ memset(tmp, 0, a->buf_size);
+ }
+ a->buf = tmp;
+ }
+ memcpy(a->buf + a->buf_file_size, buf, size*nmemb);
+ a->buf_file_size += size*nmemb;
+ return size*nmemb;
+}
+
+int CurlTest::get()
+{
+
+ CURLcode code;
+
+ buf_file_size = 0;
+
+ if ((code = curl_easy_perform(get_curl)))
+ {
+ RETURN_CURL_ERR(get_curl, code);
+ }
+
+ printf("Read: %s\n", buf);
+
+ return 0;
+}
Added: pkg/trunk/curltest/curltest.h
===================================================================
--- pkg/trunk/curltest/curltest.h (rev 0)
+++ pkg/trunk/curltest/curltest.h 2008-09-15 20:32:00 UTC (rev 4293)
@@ -0,0 +1,59 @@
+///////////////////////////////////////////////////////////////////////////////
+// The axis_cam package provides a library that talks to Axis IP-based cameras
+// as well as ROS nodes which use these libraries
+//
+// Copyright (C) 2008, Morgan Quigley
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * 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.
+// * Neither the name of Stanford University nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
+
+#ifndef AXIS_CAM_AXIS_CAM_H
+#define AXIS_CAM_AXIS_CAM_H
+
+#include <curl/curl.h>
+#include <string>
+#include <sstream>
+#include "rosthread/mutex.h"
+
+using namespace std;
+
+class CurlTest
+{
+public:
+ CurlTest(string ip);
+ ~CurlTest();
+
+ string ip;
+
+ uint8_t *buf;
+ uint32_t buf_size, buf_file_size;
+ CURL *get_curl;
+ char *url;
+
+ int get();
+
+ static size_t buf_write(void *buf, size_t size, size_t nmemb, void *userp);
+};
+
+#endif
+
Added: pkg/trunk/curltest/manifest.xml
===================================================================
--- pkg/trunk/curltest/manifest.xml (rev 0)
+++ pkg/trunk/curltest/manifest.xml 2008-09-15 20:32:00 UTC (rev 4293)
@@ -0,0 +1,13 @@
+<package>
+<description>
+A minimal package to try debugging single-threaded ros and curl interference.
+</description>
+<author>Jeremy Leibs</author>
+<license>BSD</license>
+<url></url>
+<depend package="roscpp"/>
+<depend package="std_msgs"/>
+<sysdepend package="libcurl3-openssl-dev" os="ubuntu" version="7.04-feisty"/>
+<sysdepend package="libcurl4-openssl-dev" os="ubuntu" version="8.04-hardy"/>
+</package>
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|