2 * Server-side snapshots
4 * Copyright (C) 1999 Alexandre Julliard
6 * FIXME: only process snapshots implemented for now
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 */
41 NULL
, /* get_poll_events */
42 NULL
, /* poll_event */
43 no_read_fd
, /* get_read_fd */
44 no_write_fd
, /* get_write_fd */
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
);
61 snapshot
->process_count
= 0;
62 snapshot
->process_pos
= 0;
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 */
77 if (req
->reset
) snapshot
->process_pos
= 0;
78 else if (snapshot
->process_pos
>= snapshot
->process_count
)
80 set_error( STATUS_NO_MORE_FILES
);
83 ptr
= &snapshot
->process
[snapshot
->process_pos
++];
84 req
->pid
= ptr
->process
;
85 req
->threads
= ptr
->threads
;
86 req
->priority
= ptr
->priority
;
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
)
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
;
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
,
132 snapshot_next_process( snapshot
, req
);
133 release_object( snapshot
);