Added support for forwarded ordinals in built-in dlls.
[wine/multimedia.git] / server / snapshot.c
blobee189937658cf3e32fb754213816b0b5a0a246e2
1 /*
2 * Server-side snapshots
4 * Copyright (C) 1999 Alexandre Julliard
6 * FIXME: only process snapshots implemented for now
7 */
9 #include <assert.h>
10 #include <stdio.h>
11 #include <stdlib.h>
13 #include "winerror.h"
14 #include "winnt.h"
15 #include "tlhelp32.h"
16 #include "server/process.h"
17 #include "server/thread.h"
20 struct snapshot
22 struct object obj; /* object header */
23 struct process_snapshot *process; /* processes snapshot */
24 int process_count; /* count of processes */
25 int process_pos; /* current position in proc snapshot */
28 static void snapshot_dump( struct object *obj, int verbose );
29 static void snapshot_destroy( struct object *obj );
31 static const struct object_ops snapshot_ops =
33 snapshot_dump,
34 no_add_queue,
35 NULL, /* should never get called */
36 NULL, /* should never get called */
37 NULL, /* should never get called */
38 no_read_fd,
39 no_write_fd,
40 no_flush,
41 no_get_file_info,
42 snapshot_destroy
46 /* create a new snapshot */
47 struct object *create_snapshot( int flags )
49 struct snapshot *snapshot;
50 if (!(snapshot = mem_alloc( sizeof(*snapshot) ))) return NULL;
51 init_object( &snapshot->obj, &snapshot_ops, NULL );
52 if (flags & TH32CS_SNAPPROCESS)
53 snapshot->process = process_snap( &snapshot->process_count );
54 else
55 snapshot->process_count = 0;
57 snapshot->process_pos = 0;
58 return &snapshot->obj;
61 /* get the next process in the snapshot */
62 int snapshot_next_process( int handle, int reset, struct next_process_reply *reply )
64 struct snapshot *snapshot;
65 struct process_snapshot *ptr;
66 if (!(snapshot = (struct snapshot *)get_handle_obj( current->process, handle,
67 0, &snapshot_ops )))
68 return 0;
69 if (!snapshot->process_count)
71 SET_ERROR( ERROR_INVALID_PARAMETER ); /* FIXME */
72 release_object( snapshot );
73 return 0;
75 if (reset) snapshot->process_pos = 0;
76 else if (snapshot->process_pos >= snapshot->process_count)
78 SET_ERROR( ERROR_NO_MORE_FILES );
79 release_object( snapshot );
80 return 0;
82 ptr = &snapshot->process[snapshot->process_pos++];
83 reply->pid = ptr->process;
84 reply->threads = ptr->threads;
85 reply->priority = ptr->priority;
86 release_object( snapshot );
87 return 1;
90 static void snapshot_dump( struct object *obj, int verbose )
92 struct snapshot *snapshot = (struct snapshot *)obj;
93 assert( obj->ops == &snapshot_ops );
94 fprintf( stderr, "Snapshot: %d processes\n",
95 snapshot->process_count );
98 static void snapshot_destroy( struct object *obj )
100 int i;
101 struct snapshot *snapshot = (struct snapshot *)obj;
102 assert( obj->ops == &snapshot_ops );
103 if (snapshot->process_count)
105 for (i = 0; i < snapshot->process_count; i++)
106 release_object( snapshot->process[i].process );
107 free( snapshot->process );
109 free( snapshot );