Overview
Features
Download
Documentation
Community
Add-Ons & Services

Adding event to DirectoryWatcher

Please post support and help requests here.

Adding event to DirectoryWatcher

Postby DaveD » 21 Sep 2012, 22:32

Hello all. I'm no expert on using templates, so I can't figure out what I'm doing wrong when trying to add an item to a DirectoryWatcher event.

Function to catch the event:

void DirectoryMonitorMgr::EventItemAdded(const void *pSender, DirectoryWatcher::DirectoryEvent &arg)
{
std::cout << "EventItemAdded: " << arg.event << " : " << arg.item.path() << std::endl;
}


Inside a method of my DirectoryMonitorMgr class:

newDirectoryWatcher = new DirectoryWatcher(theDirectory, DirectoryWatcher::DW_FILTER_ENABLE_ALL, 30);
newDirectoryWatcher->itemAdded += Delegate<DirectoryMonitorMgr, DirectoryWatcher::DirectoryEvent>(this, &DirectoryMonitorMgr::EventItemAdded);


The error given at the "newDirectoryWatcher->itemAdded += ..." line is:

error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'Poco::Delegate<TObj,TArgs>' (or there is no acceptable conversion)
1> with
1> [
1> TObj=DirectoryMonitorMgr,
1> TArgs=Poco::DirectoryWatcher::DirectoryEvent
1> ]
1> c:\sandbox\trunk\poco\include\poco\abstractevent.h(193): could be 'void Poco::AbstractEvent<TArgs,TStrategy,TDelegate,TMutex>::operator +=(const TDelegate &)'
1> with
1> [
1> TArgs=const Poco::DirectoryWatcher::DirectoryEvent,
1> TStrategy=Poco::DefaultStrategy<const Poco::DirectoryWatcher::DirectoryEvent,Poco::AbstractDelegate<const Poco::DirectoryWatcher::DirectoryEvent>>,
1> TDelegate=Poco::AbstractDelegate<const Poco::DirectoryWatcher::DirectoryEvent>,
1> TMutex=Poco::FastMutex
1> ]
1> while trying to match the argument list '(Poco::BasicEvent<TArgs>, Poco::Delegate<TObj,TArgs>)'
1> with
1> [
1> TArgs=const Poco::DirectoryWatcher::DirectoryEvent
1> ]
1> and
1> [
1> TObj=DirectoryMonitorMgr,
1> TArgs=Poco::DirectoryWatcher::DirectoryEvent
1> ]


Can anyone decipher this and tell me how to do this correctly?

Thanks,
Dave
DaveD
 
Posts: 3
Joined: 21 Sep 2012, 22:22

Re: Adding event to DirectoryWatcher

Postby DaveD » 25 Sep 2012, 14:48

Apologies for the bump, but this has really got me stumped. I've read the docs regarding Events and looked at all the samples I could find (Ping for example). My code follows the samples, and yet there's still something wrong. It's probably something silly I missed, but being a template noob, I don't see it.

Any pointers would be greatly appreciated!

Thanks,
Dave
DaveD
 
Posts: 3
Joined: 21 Sep 2012, 22:22

Re: Adding event to DirectoryWatcher

Postby guenter » 26 Sep 2012, 01:28

Have a look at the DirectoryWatcher test in the testsuite.

Code: Select all
DirectoryWatcher dw("path", DirectoryWatcher::DW_FILTER_ENABLE_ALL, 2);
dw.itemAdded += Poco::delegate(this, &DirectoryWatcherTest::onItemAdded);
dw.itemRemoved += Poco::delegate(this, &DirectoryWatcherTest::onItemRemoved);
dw.itemModified += Poco::delegate(this, &DirectoryWatcherTest::onItemModified);
dw.itemMovedFrom += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedFrom);
dw.itemMovedTo += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedTo);


and


Code: Select all
void DirectoryWatcherTest::onItemAdded(const Poco::DirectoryWatcher::DirectoryEvent& ev)
{
    ...
}
guenter
 
Posts: 1106
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Adding event to DirectoryWatcher

Postby DaveD » 26 Sep 2012, 15:13

Thanks guenter, that solved it. I didn't see that test code before.

I started re-reading my C++ STL book last night so hopefully this kind of thing doesn't trip me up so much.
DaveD
 
Posts: 3
Joined: 21 Sep 2012, 22:22


Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron