2 * Server-side snapshots
4 * Copyright (C) 1999 Alexandre Julliard
6 * FIXME: only process snapshots implemented for now
25 struct object obj; /* object header */
26 struct process_snapshot *process; /* processes snapshot */
27 int process_count; /* count of processes */
28 int process_pos; /* current position in proc snapshot */
31 static void snapshot_dump( struct object *obj, int verbose );
32 static void snapshot_destroy( struct object *obj );
34 static const struct object_ops snapshot_ops =
36 sizeof(struct snapshot), /* size */
37 snapshot_dump, /* dump */
38 no_add_queue, /* add_queue */
39 NULL, /* remove_queue */
42 NULL, /* get_poll_events */
43 NULL, /* poll_event */
44 no_read_fd, /* get_read_fd */
45 no_write_fd, /* get_write_fd */
47 no_get_file_info, /* get_file_info */
48 snapshot_destroy /* destroy */
52 /* create a new snapshot */
53 static struct snapshot *create_snapshot( int flags )
55 struct snapshot *snapshot;
57 if ((snapshot = alloc_object( &snapshot_ops, -1 )))
59 if (flags & TH32CS_SNAPPROCESS)
60 snapshot->process = process_snap( &snapshot->process_count );
62 snapshot->process_count = 0;
63 snapshot->process_pos = 0;
68 /* get the next process in the snapshot */
69 static int snapshot_next_process( struct snapshot *snapshot, struct next_process_request *req )
71 struct process_snapshot *ptr;
73 if (!snapshot->process_count)
75 set_error( ERROR_INVALID_PARAMETER ); /* FIXME */
78 if (req->reset) snapshot->process_pos = 0;
79 else if (snapshot->process_pos >= snapshot->process_count)
81 set_error( ERROR_NO_MORE_FILES );
84 ptr = &snapshot->process[snapshot->process_pos++];
85 req->pid = ptr->process;
86 req->threads = ptr->threads;
87 req->priority = ptr->priority;
91 static void snapshot_dump( struct object *obj, int verbose )
93 struct snapshot *snapshot = (struct snapshot *)obj;
94 assert( obj->ops == &snapshot_ops );
95 fprintf( stderr, "Snapshot: %d processes\n",
96 snapshot->process_count );
99 static void snapshot_destroy( struct object *obj )
102 struct snapshot *snapshot = (struct snapshot *)obj;
103 assert( obj->ops == &snapshot_ops );
104 if (snapshot->process_count)
106 for (i = 0; i < snapshot->process_count; i++)
107 release_object( snapshot->process[i].process );
108 free( snapshot->process );
112 /* create a snapshot */
113 DECL_HANDLER(create_snapshot)
115 struct snapshot *snapshot;
118 if ((snapshot = create_snapshot( req->flags )))
120 req->handle = alloc_handle( current->process, snapshot, 0, req->inherit );
121 release_object( snapshot );
125 /* get the next process from a snapshot */
126 DECL_HANDLER(next_process)
128 struct snapshot *snapshot;
130 if ((snapshot = (struct snapshot *)get_handle_obj( current->process, req->handle,
133 snapshot_next_process( snapshot, req );
134 release_object( snapshot );