95 lines
2.4 KiB
C++
95 lines
2.4 KiB
C++
/*
|
|
* SPDX-License-Identifier: LicenseRef-Unisoc-General-1.0
|
|
|
|
* Copyright 2016-2023 Unisoc (Shanghai) Technologies Co., Ltd
|
|
|
|
* Licensed under the Unisoc General Software License, version 1.0 (the License);
|
|
* you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
|
|
|
* https://www.unisoc.com/en_us/license/UNISOC_GENERAL_LICENSE_V1.0-EN_US
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OF ANY KIND, either express or implied.
|
|
* See the Unisoc General Software License, version 1.0 for more details.
|
|
*/
|
|
|
|
#include <Debug.h>
|
|
#include <dbus/dbus.h>
|
|
#include "CommonTimeout.h"
|
|
#include "CommonDispatcher.h"
|
|
#include "EventLoop.h"
|
|
using namespace UDBus;
|
|
|
|
CommonTimeout::CommonTimeout(Timeout::Internal* internal, EventLoop* eventLoop)
|
|
: Timeout(internal), DefaultTimeout(0, false, eventLoop)
|
|
{
|
|
CommonTimeoutCallback *cb = reinterpret_cast<CommonTimeoutCallback *>(internal);
|
|
|
|
bool enable = true;
|
|
int interval = cb->getInterval();
|
|
DEBUG("CommonTimeout:enable[%d],interval[%d]",enable,interval);
|
|
DefaultTimeout::SetEnabled(enable);
|
|
DefaultTimeout::SetInterval(interval);
|
|
DefaultTimeout::UpdateExpiration(interval);
|
|
this->mTimeoutCb = cb;
|
|
//dbus_timeout_set_data((DBusTimeout *)internal, this, nullptr);
|
|
|
|
}
|
|
CommonTimeout::~CommonTimeout()
|
|
{
|
|
if (this->mTimeoutCb)
|
|
{
|
|
DEBUG("timeout->mTimeoutCb %p", this->mTimeoutCb);
|
|
delete this->mTimeoutCb;
|
|
}
|
|
}
|
|
|
|
CommonTimeoutCallback* CommonTimeout:: getmTimeoutCb()
|
|
{
|
|
return this->mTimeoutCb;
|
|
}
|
|
|
|
void CommonTimeout:: setmTimeoutCb(CommonTimeoutCallback* mTimeoutCb)
|
|
{
|
|
this->mTimeoutCb = mTimeoutCb;
|
|
}
|
|
|
|
void CommonTimeout::Toggle()
|
|
{
|
|
bool enable = this->GetEnabled();
|
|
|
|
DEBUG("timeout %p toggled (%s)", this, enable ? "on" : "off");
|
|
DefaultTimeout::SetEnabled(!enable);
|
|
}
|
|
|
|
void CommonTimeout::Stop()
|
|
{
|
|
DEBUG("timeout %p status (%s)", this, this->GetEnabled() ? "on" : "off");
|
|
|
|
DefaultTimeout::SetEnabled(false);
|
|
}
|
|
|
|
bool CommonTimeout::Handle()
|
|
{
|
|
DEBUG("timeout %p Handle (%p)", this, mInternal);
|
|
|
|
if(mTimeoutCb)
|
|
{
|
|
if(mTimeoutCb->getFunc())
|
|
{
|
|
return mTimeoutCb->getFunc()(mTimeoutCb->getData());
|
|
}
|
|
else
|
|
{
|
|
DEBUG("mTimeoutCb->mFunc is null");
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
DEBUG("mTimeoutCb is null");
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|