Do not erase local files on uninstall if install dir does not exist.
[wine/multimedia.git] / server / snapshot.c
blob2a16ac5b1b78f0c6c15492cf065cc17c4b2aebf2
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 "winnt.h"
14 #include "tlhelp32.h"
16 #include "handle.h"
17 #include "process.h"
18 #include "thread.h"
19 #include "request.h"
22 struct snapshot
24 struct object obj; /* object header */
25 struct process_snapshot *process; /* processes snapshot */
26 int process_count; /* count of processes */
27 int process_pos; /* current position in proc snapshot */
30 static void snapshot_dump( struct object *obj, int verbose );
31 static void snapshot_destroy( struct object *obj );
33 static const struct object_ops snapshot_ops =
35 sizeof(struct snapshot), /* size */
36 snapshot_dump, /* dump */
37 no_add_queue, /* add_queue */
38 NULL, /* remove_queue */
39 NULL, /* signaled */
40 NULL, /* satisfied */
41 NULL, /* get_poll_events */
42 NULL, /* poll_event */
43 no_read_fd, /* get_read_fd */
44 no_write_fd, /* get_write_fd */
45 no_flush, /* flush */
46 no_get_file_info, /* get_file_info */
47 snapshot_destroy /* destroy */
51 /* create a new snapshot */
52 static struct snapshot *create_snapshot( int flags )
54 struct snapshot *snapshot;
56 if ((snapshot = alloc_object( &snapshot_ops, -1 )))
58 if (flags & TH32CS_SNAPPROCESS)
59 snapshot->process = process_snap( &snapshot->process_count );
60 else
61 snapshot->process_count = 0;
62 snapshot->process_pos = 0;
64 return snapshot;
67 /* get the next process in the snapshot */
68 static int snapshot_next_process( struct snapshot *snapshot, struct next_process_request *req )
70 struct process_snapshot *ptr;
72 if (!snapshot->process_count)
74 set_error( STATUS_INVALID_PARAMETER ); /* FIXME */
75 return 0;
77 if (req->reset) snapshot->process_pos = 0;
78 else if (snapshot->process_pos >= snapshot->process_count)
80 set_error( STATUS_NO_MORE_FILES );
81 return 0;
83 ptr = &snapshot->process[snapshot->process_pos++];
84 req->pid = ptr->process;
85 req->threads = ptr->threads;
86 req->priority = ptr->priority;
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 );
111 /* create a snapshot */
112 DECL_HANDLER(create_snapshot)
114 struct snapshot *snapshot;
116 req->handle = -1;
117 if ((snapshot = create_snapshot( req->flags )))
119 req->handle = alloc_handle( current->process, snapshot, 0, req->inherit );
120 release_object( snapshot );
124 /* get the next process from a snapshot */
125 DECL_HANDLER(next_process)
127 struct snapshot *snapshot;
129 if ((snapshot = (struct snapshot *)get_handle_obj( current->process, req->handle,
130 0, &snapshot_ops )))
132 snapshot_next_process( snapshot, req );
133 release_object( snapshot );