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),
39 NULL, /* should never get called */
40 NULL, /* should never get called */
41 NULL, /* should never get called */
50 /* create a new snapshot */
51 static struct snapshot *create_snapshot( int flags )
53 struct snapshot *snapshot;
55 if ((snapshot = alloc_object( &snapshot_ops )))
57 if (flags & TH32CS_SNAPPROCESS)
58 snapshot->process = process_snap( &snapshot->process_count );
60 snapshot->process_count = 0;
61 snapshot->process_pos = 0;
66 /* get the next process in the snapshot */
67 static int snapshot_next_process( struct snapshot *snapshot, struct next_process_request *req )
69 struct process_snapshot *ptr;
71 if (!snapshot->process_count)
73 set_error( ERROR_INVALID_PARAMETER ); /* FIXME */
76 if (req->reset) snapshot->process_pos = 0;
77 else if (snapshot->process_pos >= snapshot->process_count)
79 set_error( ERROR_NO_MORE_FILES );
82 ptr = &snapshot->process[snapshot->process_pos++];
83 req->pid = ptr->process;
84 req->threads = ptr->threads;
85 req->priority = ptr->priority;
89 static void snapshot_dump( struct object *obj, int verbose )
91 struct snapshot *snapshot = (struct snapshot *)obj;
92 assert( obj->ops == &snapshot_ops );
93 fprintf( stderr, "Snapshot: %d processes\n",
94 snapshot->process_count );
97 static void snapshot_destroy( struct object *obj )
100 struct snapshot *snapshot = (struct snapshot *)obj;
101 assert( obj->ops == &snapshot_ops );
102 if (snapshot->process_count)
104 for (i = 0; i < snapshot->process_count; i++)
105 release_object( snapshot->process[i].process );
106 free( snapshot->process );
110 /* create a snapshot */
111 DECL_HANDLER(create_snapshot)
113 struct snapshot *snapshot;
116 if ((snapshot = create_snapshot( req->flags )))
118 req->handle = alloc_handle( current->process, snapshot, 0, req->inherit );
119 release_object( snapshot );
123 /* get the next process from a snapshot */
124 DECL_HANDLER(next_process)
126 struct snapshot *snapshot;
128 if ((snapshot = (struct snapshot *)get_handle_obj( current->process, req->handle,
131 snapshot_next_process( snapshot, req );
132 release_object( snapshot );