summaryrefslogtreecommitdiff
path: root/ucb/source
diff options
context:
space:
mode:
authorAndreas Bille <abi@openoffice.org>2002-06-20 13:49:21 +0000
committerAndreas Bille <abi@openoffice.org>2002-06-20 13:49:21 +0000
commit77f7fbd6ebeab675be6bd1108d89fdbcacdb453b (patch)
tree397eac7962163db8188be61661e51e42b8b55956 /ucb/source
parentf41a382dbaba620c8c03829a255afe247b2b96af (diff)
Changed to oslThreadKey and partners
Diffstat (limited to 'ucb/source')
-rw-r--r--ucb/source/ucp/ftp/ftpcontent.cxx90
-rw-r--r--ucb/source/ucp/ftp/ftpcontent.hxx12
-rw-r--r--ucb/source/ucp/ftp/ftpcontentprovider.cxx29
-rw-r--r--ucb/source/ucp/ftp/ftpcontentprovider.hxx17
-rw-r--r--ucb/source/ucp/ftp/ftploaderthread.cxx128
-rw-r--r--ucb/source/ucp/ftp/ftploaderthread.hxx52
6 files changed, 133 insertions, 195 deletions
diff --git a/ucb/source/ucp/ftp/ftpcontent.cxx b/ucb/source/ucp/ftp/ftpcontent.cxx
index e75566d78740..4bc497a22a9c 100644
--- a/ucb/source/ucp/ftp/ftpcontent.cxx
+++ b/ucb/source/ucp/ftp/ftpcontent.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcontent.cxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: abi $ $Date: 2002-06-07 15:31:00 $
+ * last change: $Author: abi $ $Date: 2002-06-20 14:49:20 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -119,9 +119,10 @@ using namespace com::sun::star::io;
//=========================================================================
FtpContent::FtpContent( const Reference< XMultiServiceFactory >& rxSMgr,
- ::ucb::ContentProviderImplHelper* pProvider,
+ FtpContentProvider* pProvider,
const Reference< XContentIdentifier >& Identifier)
- : ContentImplHelper(rxSMgr,pProvider,Identifier)
+ : ContentImplHelper(rxSMgr,pProvider,Identifier),
+ m_pFCP(pProvider)
{
}
@@ -205,20 +206,36 @@ struct XOutputStreamContainer
};
+#ifdef __cplusplus
+extern "C" {
+#endif
-int writeToXOutputStream(void *buffer, size_t size, size_t nmemb, void *stream)
-{
- XOutputStreamContainer *p = static_cast<XOutputStreamContainer*>(stream);
- Sequence<sal_Int8> seq(static_cast<sal_Int8*>(buffer),size*nmemb);
- try{
- p->stream->writeBytes(seq);
- return size*nmemb;
- }
- catch(const Exception&)
+ /** Callback for curl_easy_perform();
+ */
+
+ int write2OutputStream(void *buffer,size_t size,size_t nmemb,void *stream)
{
- return 0;
+ size_t ret = size*nmemb;
+
+ if(!stream) // OK, no error if nothing can be written.
+ return ret;
+
+ XOutputStreamContainer *p = static_cast<XOutputStreamContainer*>(stream);
+ Sequence<sal_Int8> seq(static_cast<sal_Int8*>(buffer),size*nmemb);
+ try{
+ if(p && p->stream.is())
+ p->stream->writeBytes(seq);
+ return ret;
+ }
+ catch(const Exception&)
+ {
+ return 0;
+ }
}
+
+#ifdef __cplusplus
}
+#endif
// virtual
@@ -241,32 +258,41 @@ Any SAL_CALL FtpContent::execute( const Command& aCommand,
throw IllegalArgumentException();
Reference< XActiveDataStreamer > activeDataStreamer( aOpenCommand.Sink,UNO_QUERY );
- if( activeDataStreamer.is() )
+ if(activeDataStreamer.is())
throw UnsupportedDataSinkException();
- CURL *curl = FtpLoaderThread::curlHandle();
+ CURL *curl = m_pFCP->handle();
+
+ /** Now setting the URL
+ */
- Reference< XActiveDataSink > xActiveDataSink( aOpenCommand.Sink,UNO_QUERY );
- if( xActiveDataSink.is() )
- ;
+ rtl::OUString aOUStr(m_xIdentifier->getContentIdentifier());
+ rtl::OString aOStr(aOUStr.getStr(),
+ aOUStr.getLength(),
+ RTL_TEXTENCODING_UTF8); // Only ASCII in URLs -> UTF8
+ curl_easy_setopt(curl,CURLOPT_URL,aOStr.getStr());
- Reference< XOutputStream > xOutputStream( aOpenCommand.Sink,UNO_QUERY );
- if( xOutputStream.is() )
+ Reference<XActiveDataSink> activeDataSink(aOpenCommand.Sink,UNO_QUERY);
+ if(activeDataSink.is())
+ throw UnsupportedDataSinkException();;
+
+ Reference< XOutputStream > xOutputStream(aOpenCommand.Sink,UNO_QUERY);
+ if(xOutputStream.is())
{
- rtl::OUString aOUStr(m_xIdentifier->getContentIdentifier());
- rtl::OString aOStr(aOUStr.getStr(),
- aOUStr.getLength(),
- RTL_TEXTENCODING_UTF8);
-
- curl_easy_setopt(curl,CURLOPT_URL,
- aOStr.getStr());
- curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,
- writeToXOutputStream);
XOutputStreamContainer container;
container.stream = xOutputStream;
- curl_easy_setopt(curl,CURLOPT_FILE,
- &container);
+ struct curl_slist *list = curl_slist_append(NULL,"pwd");
+ curl_easy_setopt(curl,CURLOPT_QUOTE,list);
+ CURLcode code;
+
+ code = curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,write2OutputStream);
+ curl_easy_setopt(curl,CURLOPT_WRITEDATA,&container);
+
+ code = curl_easy_setopt(curl,CURLOPT_HEADERFUNCTION,write2OutputStream);
+ curl_easy_setopt(curl,CURLOPT_WRITEHEADER,&container);
+
curl_easy_perform(curl);
+ curl_slist_free_all(list);
}
}
else
diff --git a/ucb/source/ucp/ftp/ftpcontent.hxx b/ucb/source/ucp/ftp/ftpcontent.hxx
index c054ed3eecab..81efcf09b35f 100644
--- a/ucb/source/ucp/ftp/ftpcontent.hxx
+++ b/ucb/source/ucp/ftp/ftpcontent.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcontent.hxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: abi $ $Date: 2002-06-07 15:31:00 $
+ * last change: $Author: abi $ $Date: 2002-06-20 14:49:21 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -103,6 +103,10 @@ namespace ftp
//=========================================================================
+ class FtpContentProvider;
+
+//=========================================================================
+
class FtpContent
: public ::ucb::ContentImplHelper
{
@@ -110,7 +114,7 @@ namespace ftp
FtpContent( const ::com::sun::star::uno::Reference<
::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
- ::ucb::ContentProviderImplHelper* pProvider,
+ FtpContentProvider* pProvider,
const ::com::sun::star::uno::Reference<
::com::sun::star::ucb::XContentIdentifier >& Identifier);
@@ -148,6 +152,8 @@ namespace ftp
private:
+ FtpContentProvider *m_pFCP;
+
virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
getProperties( const com::sun::star::uno::Reference<
com::sun::star::ucb::XCommandEnvironment > & xEnv );
diff --git a/ucb/source/ucp/ftp/ftpcontentprovider.cxx b/ucb/source/ucp/ftp/ftpcontentprovider.cxx
index 1f6aa166e125..e538c280a0c4 100644
--- a/ucb/source/ucp/ftp/ftpcontentprovider.cxx
+++ b/ucb/source/ucp/ftp/ftpcontentprovider.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcontentprovider.cxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: abi $ $Date: 2002-06-07 15:31:00 $
+ * last change: $Author: abi $ $Date: 2002-06-20 14:49:21 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -71,7 +71,9 @@
#ifndef _FTP_FTPCONTENT_HXX_
#include "ftpcontent.hxx"
#endif
-
+#ifndef _FTP_FTPLOADERTHREAD_HXX_
+#include "ftploaderthread.hxx"
+#endif
using namespace ftp;
@@ -91,7 +93,7 @@ using namespace com::sun::star::ucb;
FtpContentProvider::FtpContentProvider(const Reference< XMultiServiceFactory >& rSMgr)
: ::ucb::ContentProviderImplHelper(rSMgr),
- m_bInitialized( false )
+ m_ftpLoaderThread(NULL)
{
}
@@ -99,6 +101,7 @@ FtpContentProvider::FtpContentProvider(const Reference< XMultiServiceFactory >&
// virtual
FtpContentProvider::~FtpContentProvider()
{
+ delete m_ftpLoaderThread;
}
//=========================================================================
@@ -163,15 +166,25 @@ Reference<XContent> SAL_CALL FtpContentProvider::queryContent(const Reference< X
{
// Initialize
osl::MutexGuard aGuard( m_aMutex );
- if(!m_bInitialized )
+ if(!m_ftpLoaderThread)
+ {
init();
+ if(!m_ftpLoaderThread)
+ throw RuntimeException();
+ }
}
+
xContent = new FtpContent(m_xSMgr,this,xCanonicId); // may throw IllegalIdentifierException
return xContent;
}
-void FtpContentProvider::init()
-{
- m_bInitialized = true;
+void FtpContentProvider::init() {
+ m_ftpLoaderThread = new FtpLoaderThread();
+}
+
+
+CURL* FtpContentProvider::handle() {
+ // Cannot be zero if called from here;
+ return m_ftpLoaderThread->handle();
}
diff --git a/ucb/source/ucp/ftp/ftpcontentprovider.hxx b/ucb/source/ucp/ftp/ftpcontentprovider.hxx
index 6aaa6401609b..06302e7dfdbd 100644
--- a/ucb/source/ucp/ftp/ftpcontentprovider.hxx
+++ b/ucb/source/ucp/ftp/ftpcontentprovider.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcontentprovider.hxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: abi $ $Date: 2002-06-07 15:31:00 $
+ * last change: $Author: abi $ $Date: 2002-06-20 14:49:21 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -71,6 +71,9 @@
#ifndef _UCBHELPER_PROVIDERHELPER_HXX
#include <ucbhelper/providerhelper.hxx>
#endif
+#ifndef __CURL_TYPES_H
+#include <curl/types.h>
+#endif
// #ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIERFACTORY_HPP_
// #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
// #endif
@@ -95,6 +98,9 @@
namespace ftp {
+ class FtpLoaderThread;
+
+
class FtpContentProvider:
public ::ucb::ContentProviderImplHelper
{
@@ -137,13 +143,16 @@ namespace ftp {
// const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& Id2 )
// throw( com::sun::star::uno::RuntimeException );
+ CURL* handle();
+
private:
osl::Mutex m_aMutex;
- sal_Bool m_bInitialized;
-
+ FtpLoaderThread *m_ftpLoaderThread;
void init();
+
+
}; // end class FtpContentProvider
} // end namespace ftp
diff --git a/ucb/source/ucp/ftp/ftploaderthread.cxx b/ucb/source/ucp/ftp/ftploaderthread.cxx
index 0298f4a54ea5..fb97f893efb4 100644
--- a/ucb/source/ucp/ftp/ftploaderthread.cxx
+++ b/ucb/source/ucp/ftp/ftploaderthread.cxx
@@ -9,24 +9,25 @@
using namespace ftp;
-
/********************************************************************************/
/* */
-/* the joiner */
+/* cleanup function for thread specific data */
/* */
/********************************************************************************/
-static void ftploaderthread_terminater(void *pData)
-{
- FtpLoaderThread* pLoaderThread = static_cast<FtpLoaderThread*>(pData);
- oslThreadIdentifier threaId(pLoaderThread->threadId());
-// oslThread aThread = osl_getThreadFromIdentifier(threaId);
-// osl_joinWithThread(aThread);
-// FtpLoaderThread::remove(threaId);
-}
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void delete_CURL(void *pData)
+ {
+ curl_easy_cleanup(static_cast<CURL*>(pData));
+ }
+#ifdef __cplusplus
+}
+#endif
/********************************************************************************/
@@ -37,112 +38,25 @@ static void ftploaderthread_terminater(void *pData)
FtpLoaderThread::FtpLoaderThread()
- : m_nThreadId(osl_getThreadIdentifier(NULL)),
- m_pHandle(NULL)
-{
-}
-
-
-FtpLoaderThread::FtpLoaderThread(oslThreadIdentifier nThreadId)
- : m_nThreadId(nThreadId),
- m_pHandle(NULL)
-{
-}
-
-
-FtpLoaderThread::FtpLoaderThread(const FtpLoaderThread& r)
-{
- m_nThreadId = r.m_nThreadId;
- m_pHandle = r.m_pHandle;
- r.m_pHandle = NULL;
-}
-
-
-FtpLoaderThread& FtpLoaderThread::operator=(const FtpLoaderThread& r)
-{
- m_nThreadId = r.m_nThreadId;
- m_pHandle = r.m_pHandle;
- r.m_pHandle = NULL;
- return *this;
-}
-
-
-FtpLoaderThread::~FtpLoaderThread()
-{
- if(m_pHandle)
- curl_easy_cleanup(m_pHandle);
-}
-
-
-bool FtpLoaderThread::operator==(const FtpLoaderThread& r) const
-{
- return m_nThreadId == r.threadId();
+ : m_threadKey(osl_createThreadKey(delete_CURL)) {
}
-oslThreadIdentifier FtpLoaderThread::threadId() const
-{
- return m_nThreadId;
-}
-
-void FtpLoaderThread::init() const
-{
- m_pHandle = curl_easy_init();
- osl_createThread(ftploaderthread_terminater,(void*)this);
+FtpLoaderThread::~FtpLoaderThread() {
+ osl_destroyThreadKey(m_threadKey);
}
-/********************************************************************************/
-/* */
-/* FtpLoaderThreadHashSet */
-/* */
-/********************************************************************************/
-
-
-
-size_t FtpLoaderThreadHash::operator()(const FtpLoaderThread& p) const
-{
- return size_t(p.threadId());
-}
-
-
-
-/********************************************************************************/
-/* */
-/* Static part of FtpLoaderThread */
-/* */
-/********************************************************************************/
-
-osl::Mutex FtpLoaderThread::ftploader_mutex;
-
-
-FtpLoaderThread::FtpLoaderThreadSet FtpLoaderThread::ftploaderthread_set;
-
-
-
-CURL* FtpLoaderThread::curlHandle()
-{
- osl::MutexGuard aGuard(ftploader_mutex);
-
- if(ftploaderthread_set.empty())
- curl_global_init(CURL_GLOBAL_DEFAULT);
-
- FtpLoaderThread loader;
- std::pair<FtpLoaderThreadSet::iterator,bool> p(ftploaderthread_set.insert(loader));
- if(p.second)
- p.first->init();
- return p.first->m_pHandle;
-}
-
-void FtpLoaderThread::remove(oslThreadIdentifier nThreadId)
-{
- osl::MutexGuard aGuard(ftploader_mutex);
+CURL* FtpLoaderThread::handle() {
+ CURL* ret;
+ if(!(ret = osl_getThreadKeyData(m_threadKey))) {
+ ret = curl_easy_init();
+ osl_setThreadKeyData(m_threadKey,static_cast<void*>(ret));
+ }
- ftploaderthread_set.erase(FtpLoaderThread(nThreadId));
- if(ftploaderthread_set.empty())
- curl_global_cleanup();
+ return ret;
}
diff --git a/ucb/source/ucp/ftp/ftploaderthread.hxx b/ucb/source/ucp/ftp/ftploaderthread.hxx
index 464016809cad..464c31fd2a35 100644
--- a/ucb/source/ucp/ftp/ftploaderthread.hxx
+++ b/ucb/source/ucp/ftp/ftploaderthread.hxx
@@ -1,72 +1,42 @@
#ifndef _FTP_FTPLOADERTHREAD_HXX_
#define _FTP_FTPLOADERTHREAD_HXX_
-#ifndef _OSL_MUTEX_HXX_
-#include <osl/mutex.hxx>
-#endif
#ifndef _OSL_THREAD_H_
#include <osl/thread.h>
#endif
#ifndef __CURL_TYPES_H
#include <curl/types.h>
#endif
-#ifndef _STL_HASH_SET_INCLUDED_
-#include <hash_set>
-#define _STL_HASH_SET_INCLUDED_
-#endif
namespace ftp {
-
- /*forward*/ class FtpLoaderThread;
-
- class FtpLoaderThreadHash
- {
- public:
-
- inline size_t operator()(const FtpLoaderThread& p) const;
-
- }; // end class FtpLoaderThreadHash
-
-
-
- /**
- * Purpose of FtpThread
- *
+ /** A loaderthread acts as factory for CURL-handles.
+ * Owner is a FtpContentProvider-instance
*/
class FtpLoaderThread
{
- typedef std::hash_set<FtpLoaderThread,FtpLoaderThreadHash> FtpLoaderThreadSet;
-
public:
- static CURL* curlHandle();
- static void remove(oslThreadIdentifier thread);
-
FtpLoaderThread();
- FtpLoaderThread(oslThreadIdentifier thread);
- FtpLoaderThread(const FtpLoaderThread&);
- FtpLoaderThread& operator=(const FtpLoaderThread&);
~FtpLoaderThread();
- /*inline*/ void init() const;
- /*inline*/ bool operator==(const FtpLoaderThread& r) const;
- /*inline*/ oslThreadIdentifier threadId() const;
+ CURL* handle();
+
private:
- /**
- * Don't enable assignment and copyconstruction.
+ /** Don't enable assignment and copyconstruction.
+ * Not defined:
*/
- oslThreadIdentifier m_nThreadId;
- mutable CURL* m_pHandle;
+ FtpLoaderThread(const FtpLoaderThread&);
+ FtpLoaderThread& operator=(const FtpLoaderThread&);
+
+ oslThreadKey m_threadKey;
- static osl::Mutex ftploader_mutex;
- static FtpLoaderThreadSet ftploaderthread_set;
- };
+ }; // end class FtpLoaderThread
}