If there is enough space in the buffer and the type is REG_SZ and the
[wine.git] / server / snapshot.c
blob173fb9d6edd6c4760aee2a740e64119c426bc6d4
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"
17 #include "handle.h"
18 #include "process.h"
19 #include "thread.h"
20 #include "request.h"
23 struct snapshot
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 */
40 NULL, /* signaled */
41 NULL, /* satisfied */
42 NULL, /* get_poll_events */
43 NULL, /* poll_event */
44 no_read_fd, /* get_read_fd */
45 no_write_fd, /* get_write_fd */
46 no_flush, /* flush */
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 );
61 else
62 snapshot->process_count = 0;
63 snapshot->process_pos = 0;
65 return snapshot;
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 */
76 return 0;
78 if (req->reset) snapshot->process_pos = 0;
79 else if (snapshot->process_pos >= snapshot->process_count)
81 set_error( ERROR_NO_MORE_FILES );
82 return 0;
84 ptr = &snapshot->process[snapshot->process_pos++];
85 req->pid = ptr->process;
86 req->threads = ptr->threads;
87 req->priority = ptr->priority;
88 return 1;
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 )
101 int i;
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;
117 req->handle = -1;
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,
131 0, &snapshot_ops )))
133 snapshot_next_process( snapshot, req );
134 release_object( snapshot );