2 * Server-side snapshots
4 * Copyright (C) 1999 Alexandre Julliard
6 * FIXME: only process snapshots implemented for now
16 #include "server/process.h"
17 #include "server/thread.h"
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
=
35 NULL
, /* should never get called */
36 NULL
, /* should never get called */
37 NULL
, /* should never get called */
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
);
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
,
69 if (!snapshot
->process_count
)
71 SET_ERROR( ERROR_INVALID_PARAMETER
); /* FIXME */
72 release_object( snapshot
);
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
);
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
);
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
);