33 #include "private/ArnMonitor_p.hpp" 46 ArnMonitorPrivate::ArnMonitorPrivate()
48 _arnClient = arnNullptr;
49 _reference = arnNullptr;
50 _localMonItem = arnNullptr;
54 ArnMonitorPrivate::~ArnMonitorPrivate()
59 void ArnMonitor::init()
66 , d_ptr( new ArnMonitorPrivate)
74 , d_ptr( new ArnMonitorPrivate)
93 if (d->_localMonItem) {
94 delete d->_localMonItem;
121 if (!d->_arnClient)
return QString();
122 return d->_arnClient->id();
130 return d->_arnClient;
148 if (!d->_monitorPath.endsWith(
"/")) d->_monitorPath +=
"/";
150 if (d->_localMonItem) {
151 delete d->_localMonItem;
152 d->_localMonItem = arnNullptr;
156 d->_arnClient.data()->getLocalRemotePath( d->_monitorPath, d->_localMountPath, d->_remoteMountPath);
158 if (!
open( d->_monitorPath))
return false;
163 if (
Arn::debugMonitor) qDebug() <<
"Monitor start: new=" << isNew <<
" path=" << d->_monitorPath;
166 QMetaObject::invokeMethod(
this,
168 Qt::QueuedConnection,
177 QMetaObject::invokeMethod(
this,
179 Qt::QueuedConnection,
185 if (!
open( d->_monitorPath))
return false;
187 d->_localMonItem =
new ArnItemNet( arnNullptr);
188 if (!d->_localMonItem->open( d->_monitorPath)) {
193 d->_localMonItem->setNetId(
linkId());
196 << d->_monitorPath <<
" id=" <<
linkId();
197 QMetaObject::invokeMethod(
this,
198 "setupLocalMonitorItem",
218 return d->_monitorPath;
226 d->_foundChilds.clear();
243 return d->_reference;
247 void ArnMonitor::sendArnMonEvent(
int type,
const QByteArray& data)
254 sendArnEventLink( &ev);
258 void ArnMonitor::setupLocalMonitorItem()
262 if (!d->_localMonItem)
return;
264 ArnSync::setupMonitorItem( d->_localMonItem);
268 void ArnMonitor::dispatchArnMonEvent(
int type,
const QByteArray& data,
bool isLocal)
273 qDebug() <<
"Dipatch Arn event (local): type=" << ArnMonEventType::txt().getTxt(
type)
274 <<
" data=" << data <<
" monPath=" << d->_monitorPath;
281 doEventItemFoundCreated(
type, data, isLocal);
284 doEventItemDeleted( data, isLocal);
287 doEventItemModeChg( data, isLocal);
290 if (!d->_arnClient && d->_localMonItem) {
292 ArnSync::doChildsToEvent( d->_localMonItem);
301 void ArnMonitor::doEventItemFoundCreated(
int type,
const QByteArray& data,
bool isLocal)
305 QString foundRemotePath = QString::fromUtf8( data.constData(), data.size());
306 QString foundLocalPath = toLocalPath( foundRemotePath);
314 qDebug() <<
"Dipatch Arn event: type=" << ArnMonEventType::txt().getTxt(
type)
315 <<
" remotePath=" << foundRemotePath <<
" localPath=" << foundLocalPath
316 <<
" monPath=" << d->_monitorPath;
322 if (!d->_foundChilds.contains(
childPath)) {
333 void ArnMonitor::doEventItemDeleted(
const QByteArray& data,
bool isLocal)
337 QString delRemotePath = QString::fromUtf8( data.constData(), data.size());
338 QString delLocalPath = toLocalPath( delRemotePath);
341 qDebug() <<
"Deleted Arn event: remotePath=" << delRemotePath
342 <<
" localPath=" << delLocalPath <<
" monPath=" << d->_monitorPath;
354 void ArnMonitor::doEventItemModeChg(
const QByteArray& data,
bool isLocal)
359 QString itemRemotePath = xsm.valueString(
"path");
360 QString itemLocalPath = toLocalPath( itemRemotePath);
361 Arn::ObjectMode mode = ArnItemNet::stringToObjectMode( xsm.value(
"mode"));
364 qDebug() <<
"ModeChg Arn event: remotePath=" << itemRemotePath
365 <<
" localPath=" << itemLocalPath <<
"mode=" << mode.toString()
366 <<
" monPath=" << d->_monitorPath;
381 int i = d->_foundChilds.indexOf( inPathConvert(
path));
384 d->_foundChilds.removeAt(i);
389 QString ArnMonitor::outPathConvert(
const QString& path)
395 QString ArnMonitor::inPathConvert(
const QString& path)
401 void ArnMonitor::customEvent( QEvent* ev)
433 ArnItemB::customEvent( ev);
437 QString ArnMonitor::toLocalPath(
const QString& remotePath)
const QString childPath(const QString &parentPath, const QString &posterityPath)
Get substring for child from a path (posterityPath)
static int baseType(int setVal=-1)
void reStart()
The monitor is restarted.
const QByteArray & data() const
Newly created Arn object.
void close()
Close the handle.
void foundChildDeleted(const QString &path)
Help telling the monitor about deletion of a previous found child.
Container class with string representation for serialized data.
void arnChildFoundFolder(const QString &path)
Signal emitted for present and newly created folder childs in the monitor folder. ...
void setMonitorPath(const QString &path, ArnClient *client=arnNullptr)
Set the path to be monitored.
void arnChildFoundLeaf(const QString &path)
Signal emitted for present and newly created leaf childs in the monitor folder.
void setClient(ArnClient *client)
Set the client to be used.
QString fullPath(const QString &path)
Convert a path to a full absolute path.
An Arn object changed mode.
void arnChildModeChanged(const QString &path, int mode)
Signal emitted for mode changing childs in the monitor folder.
void * reference() const
Get the stored external reference.
void setReference(void *reference)
Set an associated external reference.
QString monitorPath() const
Get the monitored path
bool start(const QString &path, ArnClient *client)
Starts the monitoring.
ArnClient * client() const
Get the used client
QString changeBasePath(const QString &oldBasePath, const QString &newBasePath, const QString &path)
Change the base (start) of a path.
An Arn object was deleted.
bool open(const QString &path)
Open a handle to an Arn Data Object
Class for connecting to an Arn Server.
ArnLink * startLink() const
void arnChildFound(const QString &path)
Signal emitted for present and newly created childs in the monitor folder.
void * sessionHandler() const
ArnMonitor(QObject *parent=arnNullptr)
bool isOpen() const
State of the handle.
QString path(Arn::NameF nameF=Arn::NameF::EmptyOk) const
Path of the Arn Data Object
Arn::DataType type() const
The type stored in the Arn Data Object
void arnItemDeleted(const QString &path)
Signal emitted when an Arn Data Object is deleted in the tree below.
Base class handle for an Arn Data Object.
void monitorClosed()
Signal emitted when the Arn Monitor is closed down.
void arnItemModeChanged(const QString &path, int mode)
Signal emitted when an Arn Data Object changes mode in the tree below.
uint linkId() const
Get the id for this Arn Data Object
Internal: start the Monitor.
void arnChildDeleted(const QString &path)
Signal emitted for deleted childs in the monitor folder.
Internal: restart the Monitor.
Found a present Arn object.
void arnLinkDestroyed()
Signal emitted when the Arn Data Object is destroyed.
A client remote monitor to detect changes at server.
static ArnClient * getClient(const QString &id)
Get a client by its id.
void arnItemCreated(const QString &path)
Signal emitted when an Arn Data Object is created in the tree below.
QString clientId() const
Get the id name of the used client
Base class handle for an Arn Data Object.