1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <itemdel.hxx>
23 #include <svl/poolitem.hxx>
24 #include <vcl/idle.hxx>
26 #include <tools/debug.hxx>
28 class SfxItemDisruptor_Impl
30 std::unique_ptr
<SfxPoolItem
> pItem
;
34 DECL_LINK(Delete
, Timer
*, void);
37 explicit SfxItemDisruptor_Impl(std::unique_ptr
<SfxPoolItem
> pItemToDesrupt
);
38 void LaunchDeleteOnIdle();
39 ~SfxItemDisruptor_Impl();
40 SfxItemDisruptor_Impl(const SfxItemDisruptor_Impl
&) = delete;
41 SfxItemDisruptor_Impl
& operator=(const SfxItemDisruptor_Impl
&) = delete;
44 SfxItemDisruptor_Impl::SfxItemDisruptor_Impl(std::unique_ptr
<SfxPoolItem
> pItemToDisrupt
)
45 : pItem(std::move(pItemToDisrupt
))
46 , m_Idle("sfx SfxItemDisruptor_Impl::Delete")
48 m_Idle
.SetInvokeHandler(LINK(this, SfxItemDisruptor_Impl
, Delete
));
49 m_Idle
.SetPriority(TaskPriority::DEFAULT_IDLE
);
50 m_Idle
.SetDebugName("sfx::SfxItemDisruptor_Impl m_Idle");
52 DBG_ASSERT(0 == pItem
->GetRefCount(), "disrupting pooled item");
53 pItem
->SetKind(SfxItemKind::DeleteOnIdle
);
56 void SfxItemDisruptor_Impl::LaunchDeleteOnIdle() { m_Idle
.Start(); }
58 SfxItemDisruptor_Impl::~SfxItemDisruptor_Impl()
62 // reset RefCount (was set to SFX_ITEMS_SPECIAL before!)
63 pItem
->SetRefCount(0);
68 IMPL_LINK_NOARG(SfxItemDisruptor_Impl
, Delete
, Timer
*, void) { delete this; }
70 void DeleteItemOnIdle(std::unique_ptr
<SfxPoolItem
> pItem
)
72 DBG_ASSERT(0 == pItem
->GetRefCount(), "deleting item in use");
73 SfxItemDisruptor_Impl
* pDesruptor
= new SfxItemDisruptor_Impl(std::move(pItem
));
74 pDesruptor
->LaunchDeleteOnIdle();
75 // coverity[leaked_storage] - pDesruptor takes care of its own destruction at idle time
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */