Moved tracker mode from fsh.c to new tracker.cpp, made the tracker stuff
a bit more mature, but still needs much work. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4897 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "myfs.h"
|
||||
#include "kprotos.h"
|
||||
#include "argv.h"
|
||||
#include "tracker.h"
|
||||
@@ -981,68 +980,6 @@ do_threadfiletest(int argc, char **argv)
|
||||
}
|
||||
|
||||
|
||||
port_id gTrackerPort;
|
||||
|
||||
|
||||
static void
|
||||
tracker_query_file(dev_t device, ino_t parent, char *name)
|
||||
{
|
||||
struct stat stat;
|
||||
int status, fd;
|
||||
|
||||
if (name == NULL || parent == 0)
|
||||
return;
|
||||
|
||||
fd = sys_open_entry_ref(1, device, parent, name, O_RDONLY, 0);
|
||||
if (fd < 0) {
|
||||
printf("tracker: could not open file: %s\n", name);
|
||||
return;
|
||||
}
|
||||
|
||||
status = sys_rstat(true, fd, NULL, &stat, 1);
|
||||
if (status < 0) {
|
||||
printf("tracker: could not stat file: %s\n", name);
|
||||
}
|
||||
|
||||
sys_close(true, fd);
|
||||
}
|
||||
|
||||
|
||||
static int32
|
||||
tracker_loop(void *data)
|
||||
{
|
||||
// create global messaging port
|
||||
|
||||
gTrackerPort = create_port(128, "fsh tracker port");
|
||||
if (gTrackerPort < B_OK)
|
||||
return gTrackerPort;
|
||||
|
||||
while (true) {
|
||||
update_message message;
|
||||
uint32 code;
|
||||
status_t status = read_port(gTrackerPort, &code, &message, sizeof(message));
|
||||
if (status < B_OK)
|
||||
continue;
|
||||
|
||||
if (code == FSH_KILL_TRACKER)
|
||||
break;
|
||||
|
||||
if (code == FSH_NOTIFY_LISTENER) {
|
||||
printf("tracker: notify listener received\n");
|
||||
if (message.op != B_ATTR_CHANGED && message.op != B_DEVICE_UNMOUNTED)
|
||||
tracker_query_file(message.device, message.parentNode, message.name);
|
||||
} else if (code == B_QUERY_UPDATE) {
|
||||
printf("tracker: query update received\n");
|
||||
tracker_query_file(message.device, message.parentNode, message.name);
|
||||
} else {
|
||||
printf("tracker: unknown code received: 0x%lx\n", code);
|
||||
}
|
||||
}
|
||||
|
||||
delete_port(gTrackerPort);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
do_tracker(int argc, char **argv)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#include "tracker.h"
|
||||
#include "kprotos.h"
|
||||
|
||||
//#include <map>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
port_id gTrackerPort;
|
||||
|
||||
|
||||
/*static void
|
||||
tracker_query_attributes(dev_t device, ino_t node, char *name)
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
static void
|
||||
tracker_query_file(dev_t device, ino_t parent, char *name)
|
||||
{
|
||||
if (name == NULL || parent == 0)
|
||||
return;
|
||||
|
||||
int fd = sys_open_entry_ref(1, device, parent, name, O_RDONLY, 0);
|
||||
if (fd < 0) {
|
||||
printf("tracker: could not open file: %s\n", name);
|
||||
return;
|
||||
}
|
||||
|
||||
struct stat stat;
|
||||
int status = sys_rstat(true, fd, NULL, &stat, 1);
|
||||
if (status < 0) {
|
||||
printf("tracker: could not stat file: %s\n", name);
|
||||
}
|
||||
|
||||
sys_close(true, fd);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
tracker_scan_files(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
extern "C" int32
|
||||
tracker_loop(void *data)
|
||||
{
|
||||
// create global messaging port
|
||||
|
||||
gTrackerPort = create_port(128, "fsh tracker port");
|
||||
if (gTrackerPort < B_OK)
|
||||
return gTrackerPort;
|
||||
|
||||
while (true) {
|
||||
update_message message;
|
||||
int32 code;
|
||||
status_t status = read_port(gTrackerPort, &code, &message, sizeof(message));
|
||||
if (status < B_OK)
|
||||
continue;
|
||||
|
||||
if (code == FSH_KILL_TRACKER)
|
||||
break;
|
||||
|
||||
if (code == FSH_NOTIFY_LISTENER) {
|
||||
printf("tracker: notify listener received\n");
|
||||
if (message.op != B_ATTR_CHANGED && message.op != B_DEVICE_UNMOUNTED)
|
||||
tracker_query_file(message.device, message.parentNode, message.name);
|
||||
} else if (code == B_QUERY_UPDATE) {
|
||||
printf("tracker: query update received\n");
|
||||
tracker_query_file(message.device, message.parentNode, message.name);
|
||||
} else {
|
||||
printf("tracker: unknown code received: 0x%lx\n", code);
|
||||
}
|
||||
}
|
||||
|
||||
delete_port(gTrackerPort);
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#define TRACKER_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <OS.h>
|
||||
#include <AppDefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -22,4 +23,10 @@ typedef struct update_message {
|
||||
|
||||
extern port_id gTrackerPort;
|
||||
|
||||
extern
|
||||
#ifdef __cplusplus
|
||||
"C"
|
||||
#endif
|
||||
int32 tracker_loop(void *data);
|
||||
|
||||
#endif /* TRACKER_H */
|
||||
|
||||
Reference in New Issue
Block a user