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
=
37 NULL
, /* should never get called */
38 NULL
, /* should never get called */
39 NULL
, /* should never get called */
48 /* create a new snapshot */
49 static struct object
*create_snapshot( int flags
)
51 struct snapshot
*snapshot
;
52 if (!(snapshot
= mem_alloc( sizeof(*snapshot
) ))) return NULL
;
53 init_object( &snapshot
->obj
, &snapshot_ops
, NULL
);
54 if (flags
& TH32CS_SNAPPROCESS
)
55 snapshot
->process
= process_snap( &snapshot
->process_count
);
57 snapshot
->process_count
= 0;
59 snapshot
->process_pos
= 0;
60 return &snapshot
->obj
;
63 /* get the next process in the snapshot */
64 static int snapshot_next_process( int handle
, int reset
, struct next_process_reply
*reply
)
66 struct snapshot
*snapshot
;
67 struct process_snapshot
*ptr
;
68 if (!(snapshot
= (struct snapshot
*)get_handle_obj( current
->process
, handle
,
71 if (!snapshot
->process_count
)
73 SET_ERROR( ERROR_INVALID_PARAMETER
); /* FIXME */
74 release_object( snapshot
);
77 if (reset
) snapshot
->process_pos
= 0;
78 else if (snapshot
->process_pos
>= snapshot
->process_count
)
80 SET_ERROR( ERROR_NO_MORE_FILES
);
81 release_object( snapshot
);
84 ptr
= &snapshot
->process
[snapshot
->process_pos
++];
85 reply
->pid
= ptr
->process
;
86 reply
->threads
= ptr
->threads
;
87 reply
->priority
= ptr
->priority
;
88 release_object( snapshot
);
92 static void snapshot_dump( struct object
*obj
, int verbose
)
94 struct snapshot
*snapshot
= (struct snapshot
*)obj
;
95 assert( obj
->ops
== &snapshot_ops
);
96 fprintf( stderr
, "Snapshot: %d processes\n",
97 snapshot
->process_count
);
100 static void snapshot_destroy( struct object
*obj
)
103 struct snapshot
*snapshot
= (struct snapshot
*)obj
;
104 assert( obj
->ops
== &snapshot_ops
);
105 if (snapshot
->process_count
)
107 for (i
= 0; i
< snapshot
->process_count
; i
++)
108 release_object( snapshot
->process
[i
].process
);
109 free( snapshot
->process
);
114 /* create a snapshot */
115 DECL_HANDLER(create_snapshot
)
118 struct create_snapshot_reply reply
= { -1 };
120 if ((obj
= create_snapshot( req
->flags
)))
122 reply
.handle
= alloc_handle( current
->process
, obj
, 0, req
->inherit
);
123 release_object( obj
);
125 send_reply( current
, -1, 1, &reply
, sizeof(reply
) );
128 /* get the next process from a snapshot */
129 DECL_HANDLER(next_process
)
131 struct next_process_reply reply
;
132 snapshot_next_process( req
->handle
, req
->reset
, &reply
);
133 send_reply( current
, -1, 1, &reply
, sizeof(reply
) );