FSEvent Api を使用して、Mac で単純なファイルウォッチャーをテストしようとしています。イベントでコールバックを取得し、すべてが機能しているように見えますが、コンテキスト構造の情報フィールドに含まれる情報を回復できません。これが私のコードです:
void feCallback(ConstFSEventStreamRef streamRef,
void* pClientCallBackInfo,
size_t numEvents,
void* pEventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[]);
Watcher::Watcher(const QString& pathToFolder) :
folderPath_(pathToFolder)
{
CFStringCreateWithCString(kCFAllocatorDefault,path,kCFStringEncodingUTF8);
NSString *directory = [[NSString stringWithUTF8String:folderPath_.toStdString().c_str()] stringByDeletingLastPathComponent];
NSArray *pathToWatch = [NSArray arrayWithObjects:directory, nil];
FSEventStreamContext context = {0, (void*)this, NULL, NULL, NULL}; //the second parameter is the 'user info' field
CFAbsoluteTime latency = 3.0;
FSEventStreamRef stream;
stream = FSEventStreamCreate(NULL,
&feCallback,
&context,
(CFArrayRef)pathsToWatch,
kFSEventStreamEventIdSinceNow,
latency,
kFSEventStreamCreateFlagFileEvents | kFSEventStreamCreateFlagNoDefer);
if (!stream)
{
qDebug() << "Could not create event stream for path";
return;
}
else
{
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
FSEventStreamStart(stream);
qDebug() << "stream created";
}
}
QString Watcher::getFolderPath()
{
return folderPath_;
}
void feCallback(ConstFSEventStreamRef streamRef,
void* pClientCallBackInfo,
size_t numEvents,
void* pEventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[])
{
Q_UNUSED(streamRef)
Q_UNUSED(eventIds)
qDebug() << ((Watcher*)pClientCallBackInfo)->getFolderPath();
}
コールバックで sigsev エラーが発生します。さらに、コンテキストに int だけを挿入すると、たとえば次のようになります。
int testInt = 4;
FSEventStreamContext context = {0, &testInt, NULL, NULL, NULL};
コールバックで
qDebug() << *((int*)pClientCallBackInfo);
私を印刷します-1
それで、私は何を間違っていますか?事前にthx!