1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * Copyright 2008 by Sun Microsystems, Inc.
6 * OpenOffice.org - a multi-platform office productivity suite
8 * $RCSfile: onlogrotate_job.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
28 ************************************************************************/
30 // MARKER(update_precomp.py): autogen include statement, do not remove
31 #include "precompiled_extensions.hxx"
33 #include "onlogrotate_job.hxx"
35 #include "logpacker.hxx"
36 #include "logstorage.hxx"
37 #include "soaprequest.hxx"
38 #include "soapsender.hxx"
40 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
41 #include <osl/mutex.hxx>
42 #include <osl/thread.hxx>
46 using namespace ::com::sun::star::beans
;
47 using namespace ::com::sun::star::lang
;
48 using namespace ::com::sun::star::task
;
49 using namespace ::com::sun::star::uno
;
50 using ::com::sun::star::ucb::XSimpleFileAccess
;
51 using ::rtl::OUString
;
56 using namespace oooimprovement
;
58 static void packLogs(const Reference
<XMultiServiceFactory
>& sf
)
63 LogPacker
log_packer(sf
);
64 vector
<OUString
> csvfiles
= LogStorage(sf
).getUnzippedLogFiles();
66 vector
<OUString
>::iterator item
= csvfiles
.begin();
69 config
.incrementEventCount(log_packer
.pack(*item
));
73 static void uploadLogs(const Reference
<XMultiServiceFactory
>& sf
)
78 Reference
<XSimpleFileAccess
> file_access(
79 sf
->createInstance(OUString::createFromAscii("com.sun.star.ucb.SimpleFileAccess")),
81 SoapSender
sender(sf
, config
.getSoapUrl());
82 OUString soap_id
= config
.getSoapId();
83 vector
<OUString
> zipfiles
= LogStorage(sf
).getZippedLogFiles();
85 vector
<OUString
>::iterator item
= zipfiles
.begin();
89 if(config
.incrementFailedAttempts(1) > 25)
91 config
.giveupUploading();
92 LogStorage(sf
).clear();
95 sender
.send(SoapRequest(sf
, soap_id
, *item
));
96 config
.incrementReportCount(1);
97 file_access
->kill(*item
);
98 config
.resetFailedAttempts();
103 class OnLogRotateThread
: public ::osl::Thread
106 OnLogRotateThread(Reference
<XMultiServiceFactory
> sf
);
107 virtual void SAL_CALL
run();
110 Reference
<XMultiServiceFactory
> m_ServiceFactory
;
111 ::osl::Mutex m_ServiceFactoryMutex
;
114 OnLogRotateThread::OnLogRotateThread(Reference
<XMultiServiceFactory
> sf
)
115 : m_ServiceFactory(sf
)
118 void SAL_CALL
OnLogRotateThread::run()
121 ::osl::Thread::yield();
122 TimeValue wait_intervall
= {30,0};
123 osl_waitThread(&wait_intervall
);
126 ::osl::Guard
< ::osl::Mutex
> service_factory_guard(m_ServiceFactoryMutex
);
127 if(m_ServiceFactory
.is())
129 if(Config(m_ServiceFactory
).getInvitationAccepted())
131 packLogs(m_ServiceFactory
);
132 uploadLogs(m_ServiceFactory
);
135 LogStorage(m_ServiceFactory
).clear();
137 m_ServiceFactory
.clear();
141 void OnLogRotateThread::disposing()
143 ::osl::Guard
< ::osl::Mutex
> service_factory_guard(m_ServiceFactoryMutex
);
144 m_ServiceFactory
.clear();
148 namespace oooimprovement
150 OnLogRotateJob::OnLogRotateJob(const Reference
<XComponentContext
>& context
)
151 : m_ServiceFactory(Reference
<XMultiServiceFactory
>(
152 context
->getServiceManager()->createInstanceWithContext(
153 OUString::createFromAscii("com.sun.star.lang.XMultiServiceFactory"), context
),
157 OnLogRotateJob::OnLogRotateJob(const Reference
<XMultiServiceFactory
>& sf
)
158 : m_ServiceFactory(sf
)
161 OnLogRotateJob::~OnLogRotateJob()
164 void SAL_CALL
OnLogRotateJob::executeAsync(
165 const Sequence
<NamedValue
>&,
166 const Reference
<XJobListener
>& listener
)
167 throw(RuntimeException
)
169 OnLogRotateThread
* thread
= new OnLogRotateThread(m_ServiceFactory
);
173 listener
->jobFinished(Reference
<XAsyncJob
>(this), result
);
176 sal_Bool SAL_CALL
OnLogRotateJob::supportsService(const OUString
& service_name
) throw(RuntimeException
)
178 const Sequence
<OUString
> service_names(getSupportedServiceNames());
179 for (sal_Int32 idx
= service_names
.getLength()-1; idx
>=0; --idx
)
180 if(service_name
== service_names
[idx
]) return sal_True
;
184 OUString SAL_CALL
OnLogRotateJob::getImplementationName() throw(RuntimeException
)
185 { return getImplementationName_static(); }
187 Sequence
<OUString
> SAL_CALL
OnLogRotateJob::getSupportedServiceNames() throw(RuntimeException
)
188 { return getSupportedServiceNames_static(); }
190 OUString SAL_CALL
OnLogRotateJob::getImplementationName_static()
191 { return OUString::createFromAscii("com.sun.star.comp.extensions.oooimprovement.OnLogRotateJob"); }
193 Sequence
<OUString
> SAL_CALL
OnLogRotateJob::getSupportedServiceNames_static()
195 Sequence
<OUString
> aServiceNames(1);
196 aServiceNames
[0] = OUString::createFromAscii("com.sun.star.task.XAsyncJob");
197 return aServiceNames
;
200 Reference
<XInterface
> OnLogRotateJob::Create(const Reference
<XComponentContext
>& context
)
201 { return *(new OnLogRotateJob(context
)); }
203 Reference
<XInterface
> OnLogRotateJob::Create(const Reference
<XMultiServiceFactory
>& sf
)
204 { return *(new OnLogRotateJob(sf
)); }