差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
translation:working:翻訳5 [2016-04-27 21:21] Decomo |
translation:working:翻訳5 [2016-08-24 13:46] (現在) Decomo |
||
---|---|---|---|
行 50: | 行 50: | ||
</ | </ | ||
- | 例えば、バックアップソフトウェアは | + | 例えば、バックアップソフトウェアは、変更の見落としがないことを確実にするために、定期的に全てのボリュームをフルスキャンするべきです。 |
- | 変更がない事は無視される事を確実にする | + | ルートファイルシステム上のファイルを監視する場合は、どちらのストリーム機構も同じような振る舞いをします。 |
- | For example, backup software should still periodically perform a full sweep of any volume to ensure that no changes fall through the cracks. | + | |
- | ルートファイルシステムのファイルを監視する場合は、 | + | 例として、以下の< |
- | If you are monitoring files on the root file system, either | + | <code c> |
+ | /* 監視するパスのCFStringオブジェクトを含む | ||
+ | | ||
+ | */ | ||
+ | CFStringRef mypath = CFSTR("/ | ||
+ | CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)& | ||
+ | void *callbackInfo = NULL; // ここでストリーム固有データを入れられる。 | ||
+ | FSEventStreamRef | ||
+ | CFAbsoluteTime latency = 3.0; /* レイテンシは秒数 */ | ||
- | For example, the following snippet shows how to create an event stream: | + | /* コールバックを渡してストリームを生成する */ |
+ | stream | ||
+ | & | ||
+ | callbackInfo, | ||
+ | pathsToWatch, | ||
+ | kFSEventStreamEventIdSinceNow, | ||
+ | latency, | ||
+ | kFSEventStreamCreateFlagNone /* 関数リファレンスで説明されているフラグ */ | ||
+ | ); | ||
+ | </ | ||
- | | + | イベントストリームを生成した時点で、それをアプリケーションの実行ループにスケジューリングすべきです。 |
+ | これを行うには、生成した新規ストリーム、実行ループ、実行ループモードを引数として'' | ||
+ | 実行ループに関する更なる情報は[[https: | ||
- | | + | もし、まだ実行ループを持っていなければ、このタスクのためにスレッドを割り当てる必要があるでしょう。 |
+ | あなたが選択したAPIを使ってスレッドを生成した後は、そのスレッドに最初の実行ループを確保するために'' | ||
+ | 以後'' | ||
- | */ | + | 例として、以下の< |
- | CFStringRef mypath = CFSTR(" | + | <code c> |
+ | FSEventStreamRef stream; | ||
+ | /* 以下の関数を呼ぶ前にストリームを生成する。 */ | ||
+ | FSEventStreamScheduleWithRunLoop(stream, | ||
+ | </ | ||
- | CFArrayRef pathsToWatch = CFArrayCreate(NULL, | + | イベントストリーム設定の最終工程は'' |
+ | この関数は、イベントストリームにイベントの送信開始を指示します。 | ||
+ | 開始させるイベントストリームが唯一の引数です。 | ||
- | void *callbackInfo = NULL; // could put stream-specific data here. | + | イベントストリームの生成とスケジュールを行い、もしまだ実行ループを走らせていなければ、'' |
- | FSEventStreamRef stream; | + | ===== イベントの取り扱い ===== |
- | CFAbsoluteTime latency = 3.0; /* Latency in seconds */ | + | イベントハンドラーコールバックは'' |
+ | パラメータは'' | ||
- | + | イベントハンドラは、パス、識別子、フラグの3つのリストを受け取ります。 | |
+ | 実質的に、これらがイベントのリストを表します。 | ||
+ | The first event consists of the first entry taken from each of the arrays, and so on. | ||
+ | イベント処理の必要に応じて、ハンドラはこれらリストをイテレートして下さい。 | ||
- | /* Create | + | For each event, you should scan the directory at the specified path, processing its contents as desired. |
+ | 通常、そのパスによって示されるディレクトリだけを走査する必要があります。しかしながら、そのケースに当てはまらない3つの状況があります: | ||
- | stream = FSEventStreamCreate(NULL, | + | |
- | + | * カーネルとユーザー空間の間でコミュニケーションエラーが発生した場合、'' | |
- | & | + | |
- | + | ||
- | callbackInfo, | + | |
- | + | ||
- | pathsToWatch, | + | |
- | + | ||
- | kFSEventStreamEventIdSinceNow, | + | |
- | + | ||
- | latency, | + | |
- | + | ||
- | kFSEventStreamCreateFlagNone /* Flags explained in reference */ | + | |
- | + | ||
- | ); | + | |
- | + | ||
- | Once you have created an event stream, you must schedule it on your application’s run loop. To do this, call FSEventStreamScheduleWithRunLoop, | + | |
- | + | ||
- | If you don’t already have a run loop, you will need to devote a thread to this task. After creating a thread using your API of choice, call CFRunLoopGetCurrent to allocate an initial run loop for that thread. Any future calls to CFRunLoopGetCurrent will return the same run loop. | + | |
- | + | ||
- | For example, the following snippet shows how to schedule a stream, called stream, on the current thread’s run loop (not yet running): | + | |
- | + | ||
- | FSEventStreamRef stream; | + | |
- | + | ||
- | /* Create the stream before calling this. */ | + | |
- | + | ||
- | FSEventStreamScheduleWithRunLoop(stream, | + | |
- | + | ||
- | The final step in setting up an event stream is to call FSEventStreamStart. This function tells the event stream to begin sending events. Its sole parameter is the event stream to start. | + | |
- | + | ||
- | Once the event stream has been created and scheduled, if your run loop is not already running, you should start it by calling CFRunLoopRun. | + | |
- | Handling Events | + | |
- | + | ||
- | Your event handler callback must conform to the prototype for FSEventStreamCallback. The parameters are described in the reference documentation for the FSEventStreamCallback data type. | + | |
- | + | ||
- | Your event handler receives three lists: a list of paths, a list of identifiers, | + | |
- | + | ||
- | For each event, you should scan the directory at the specified path, processing its contents as desired. Normally, you need to scan only the exact directory specified by the path. However, there are three situations in which this is not the case: | + | |
- | + | ||
- | If an event in a directory occurs at about the same time as one or more events in a subdirectory of that directory, the events may be coalesced into a single event. In this case, you will receive an event with the kFSEventStreamEventFlagMustScanSubDirs flag set. When you receive such an event, you must recursively rescan the path listed in the event. The additional changes are not necessarily in an immediate child of the listed path. | + | |
- | + | ||
- | If a communication error occurs between the kernel and the user-space daemon, you may receive an event with either the kFSEventStreamEventFlagKernelDropped | + | |
+ | < | ||
+ | イベントのドロップ時は'' | ||
+ | 上で述べたように、パスのフルスキャンを行うべきかどうかの判断では、 | ||
Note: When an event is dropped, the kFSEventStreamEventFlagMustScanSubDirs flag is also set. Thus, it is not necessary to explicitly check for the dropped event flags when determining whether to perform a full rescan of a path. The dropped event flags are provided purely for informational purposes. | Note: When an event is dropped, the kFSEventStreamEventFlagMustScanSubDirs flag is also set. Thus, it is not necessary to explicitly check for the dropped event flags when determining whether to perform a full rescan of a path. The dropped event flags are provided purely for informational purposes. | ||