8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / print / libpapi-dynamic / common / job.c
blobe7bca751a0f58d55349380574519aaeb0d8166bc
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 /* $Id: job.c 146 2006-03-24 00:26:54Z njacobs $ */
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 /*LINTLIBRARY*/
34 #include <stdlib.h>
35 #include <papi_impl.h>
37 void
38 papiJobFree(papi_job_t job)
40 job_t *tmp = (job_t *)job;
42 if (tmp != NULL) {
43 void (*f)();
45 f = (void (*)())psm_sym(tmp->svc, "papiJobFree");
46 if (f != NULL)
47 f(tmp->job);
48 free(tmp);
52 void
53 papiJobListFree(papi_job_t *jobs)
55 if (jobs != NULL) {
56 int i;
58 for (i = 0; jobs[i] != NULL; i++)
59 papiJobFree(jobs[i]);
60 free(jobs);
64 papi_attribute_t **
65 papiJobGetAttributeList(papi_job_t job)
67 papi_attribute_t **result = NULL;
68 job_t *j = job;
70 if (job != NULL) {
71 papi_attribute_t **(*f)();
73 f = (papi_attribute_t **(*)())psm_sym(j->svc,
74 "papiJobGetAttributeList");
75 if (f != NULL)
76 result = f(j->job);
79 return (result);
82 char *
83 papiJobGetPrinterName(papi_job_t job)
85 char *result = NULL;
86 job_t *j = job;
88 if (job != NULL) {
89 char *(*f)();
91 f = (char *(*)())psm_sym(j->svc, "papiJobGetPrinterName");
92 if (f != NULL)
93 result = f(j->job);
96 return (result);
99 int32_t
100 papiJobGetId(papi_job_t job)
102 int32_t result = -1;
103 job_t *j = job;
105 if (job != NULL) {
106 int32_t (*f)();
108 f = (int32_t (*)())psm_sym(j->svc, "papiJobGetId");
109 if (f != NULL)
110 result = f(j->job);
113 return (result);
116 papi_job_ticket_t *
117 papiJobGetJobTicket(papi_job_t job)
119 papi_job_ticket_t *result = NULL;
120 job_t *j = job;
122 if (job != NULL) {
123 papi_job_ticket_t *(*f)();
125 f = (papi_job_ticket_t *(*)())psm_sym(j->svc,
126 "papiJobGetJobTicket");
127 if (f != NULL)
128 result = f(j->job);
131 return (result);
134 /* common support for papiJob{Submit|SubmitByReference|Validate} */
135 static papi_status_t
136 _papi_job_submit_reference_or_validate(papi_service_t handle, char *printer,
137 papi_attribute_t **job_attributes,
138 papi_job_ticket_t *job_ticket, char **files, papi_job_t *job,
139 char *function)
141 papi_status_t result = PAPI_INTERNAL_ERROR;
142 service_t *svc = handle;
143 job_t *j = NULL;
144 papi_status_t (*f)();
146 if ((svc == NULL) || (printer == NULL) || (files == NULL) ||
147 (job == NULL))
148 return (PAPI_BAD_ARGUMENT);
150 if ((result = service_connect(svc, printer)) != PAPI_OK)
151 return (result);
153 if ((*job = j = calloc(1, sizeof (*j))) == NULL)
154 return (PAPI_TEMPORARY_ERROR);
156 j->svc = svc;
157 f = (papi_status_t (*)())psm_sym(j->svc, function);
158 if (f != NULL)
159 result = f(svc->svc_handle, svc->name, job_attributes,
160 job_ticket, files, &j->job);
162 return (result);
165 papi_status_t
166 papiJobSubmit(papi_service_t handle, char *printer,
167 papi_attribute_t **job_attributes,
168 papi_job_ticket_t *job_ticket, char **files, papi_job_t *job)
170 return (_papi_job_submit_reference_or_validate(handle, printer,
171 job_attributes, job_ticket, files, job,
172 "papiJobSubmit"));
175 papi_status_t
176 papiJobSubmitByReference(papi_service_t handle, char *printer,
177 papi_attribute_t **job_attributes,
178 papi_job_ticket_t *job_ticket, char **files, papi_job_t *job)
180 return (_papi_job_submit_reference_or_validate(handle, printer,
181 job_attributes, job_ticket, files, job,
182 "papiJobSubmitByReference"));
185 papi_status_t
186 papiJobValidate(papi_service_t handle, char *printer,
187 papi_attribute_t **job_attributes,
188 papi_job_ticket_t *job_ticket, char **files, papi_job_t *job)
190 return (_papi_job_submit_reference_or_validate(handle, printer,
191 job_attributes, job_ticket, files, job,
192 "papiJobValidate"));
195 papi_status_t
196 papiJobStreamOpen(papi_service_t handle, char *printer,
197 papi_attribute_t **job_attributes,
198 papi_job_ticket_t *job_ticket, papi_stream_t *stream)
200 papi_status_t result = PAPI_INTERNAL_ERROR;
201 service_t *svc = handle;
202 papi_status_t (*f)();
204 if ((svc == NULL) || (printer == NULL) || (stream == NULL))
205 return (PAPI_BAD_ARGUMENT);
207 if ((result = service_connect(svc, printer)) != PAPI_OK)
208 return (result);
210 f = (papi_status_t (*)())psm_sym(svc, "papiJobStreamOpen");
211 if (f != NULL)
212 result = f(svc->svc_handle, svc->name, job_attributes,
213 job_ticket, stream);
215 return (result);
218 papi_status_t
219 papiJobStreamWrite(papi_service_t handle,
220 papi_stream_t stream, void *buffer, size_t buflen)
222 papi_status_t result = PAPI_INTERNAL_ERROR;
223 service_t *svc = handle;
224 papi_status_t (*f)();
226 if ((svc == NULL) || (stream == NULL) || (buffer == NULL) ||
227 (buflen == 0))
228 return (PAPI_BAD_ARGUMENT);
230 f = (papi_status_t (*)())psm_sym(svc, "papiJobStreamWrite");
231 if (f != NULL)
232 result = f(svc->svc_handle, stream, buffer, buflen);
234 return (result);
237 papi_status_t
238 papiJobStreamClose(papi_service_t handle, papi_stream_t stream, papi_job_t *job)
240 papi_status_t result = PAPI_INTERNAL_ERROR;
241 service_t *svc = handle;
242 job_t *j = NULL;
243 papi_status_t (*f)();
245 if ((svc == NULL) || (stream == NULL) || (job == NULL))
246 return (PAPI_BAD_ARGUMENT);
248 if ((*job = j = calloc(1, sizeof (*j))) == NULL)
249 return (PAPI_TEMPORARY_ERROR);
251 j->svc = svc;
252 f = (papi_status_t (*)())psm_sym(j->svc, "papiJobStreamClose");
253 if (f != NULL)
254 result = f(svc->svc_handle, stream, &j->job);
256 return (result);
259 papi_status_t
260 papiJobQuery(papi_service_t handle, char *printer, int32_t job_id,
261 char **requested_attrs, papi_job_t *job)
263 papi_status_t result = PAPI_INTERNAL_ERROR;
264 service_t *svc = handle;
265 job_t *j = NULL;
266 papi_status_t (*f)();
268 if ((svc == NULL) || (printer == NULL))
269 return (PAPI_BAD_ARGUMENT);
271 if ((result = service_connect(svc, printer)) != PAPI_OK)
272 return (result);
274 if ((*job = j = calloc(1, sizeof (*j))) == NULL)
275 return (PAPI_TEMPORARY_ERROR);
277 j->svc = svc;
278 f = (papi_status_t (*)())psm_sym(j->svc, "papiJobQuery");
279 if (f != NULL)
280 result = f(svc->svc_handle, svc->name, job_id,
281 requested_attrs, &j->job);
283 return (result);
286 papi_status_t
287 papiJobMove(papi_service_t handle, char *printer, int32_t job_id,
288 char *destination)
290 papi_status_t result = PAPI_INTERNAL_ERROR;
291 service_t *svc = handle;
292 papi_status_t (*f)();
294 if ((svc == NULL) || (printer == NULL) || (job_id < 0))
295 return (PAPI_BAD_ARGUMENT);
297 if ((result = service_connect(svc, printer)) != PAPI_OK)
298 return (result);
300 f = (papi_status_t (*)())psm_sym(svc, "papiJobMove");
301 if (f != NULL) {
302 papi_attribute_t **attrs = getprinterbyname(destination, NULL);
304 papiAttributeListGetString(attrs, NULL,
305 "printer-uri-supported", &destination);
306 result = f(svc->svc_handle, svc->name, job_id, destination);
307 papiAttributeListFree(attrs);
310 return (result);
313 /* common support for papiJob{Cancel|Release|Restart|Promote} */
314 static papi_status_t
315 _papi_job_handle_printer_id(papi_service_t handle,
316 char *printer, int32_t job_id, char *function)
318 papi_status_t result = PAPI_INTERNAL_ERROR;
319 service_t *svc = handle;
320 papi_status_t (*f)();
322 if ((svc == NULL) || (printer == NULL) || (job_id < 0))
323 return (PAPI_BAD_ARGUMENT);
325 if ((result = service_connect(svc, printer)) != PAPI_OK)
326 return (result);
328 f = (papi_status_t (*)())psm_sym(svc, function);
329 if (f != NULL)
330 result = f(svc->svc_handle, svc->name, job_id);
332 return (result);
335 papi_status_t
336 papiJobCancel(papi_service_t handle, char *printer, int32_t job_id)
338 return (_papi_job_handle_printer_id(handle, printer, job_id,
339 "papiJobCancel"));
342 papi_status_t
343 papiJobRelease(papi_service_t handle, char *printer, int32_t job_id)
345 return (_papi_job_handle_printer_id(handle, printer, job_id,
346 "papiJobRelease"));
349 papi_status_t
350 papiJobRestart(papi_service_t handle, char *printer, int32_t job_id)
352 return (_papi_job_handle_printer_id(handle, printer, job_id,
353 "papiJobRestart"));
356 papi_status_t
357 papiJobPromote(papi_service_t handle, char *printer, int32_t job_id)
359 return (_papi_job_handle_printer_id(handle, printer, job_id,
360 "papiJobPromote"));
363 papi_status_t
364 papiJobCommit(papi_service_t handle, char *printer, int32_t job_id)
366 return (_papi_job_handle_printer_id(handle, printer, job_id,
367 "papiJobCommit"));
370 papi_status_t
371 papiJobHold(papi_service_t handle, char *printer, int32_t job_id)
373 return (_papi_job_handle_printer_id(handle, printer, job_id,
374 "papiJobHold"));
377 papi_status_t
378 papiJobModify(papi_service_t handle, char *printer, int32_t job_id,
379 papi_attribute_t **attributes, papi_job_t *job)
381 papi_status_t result = PAPI_INTERNAL_ERROR;
382 service_t *svc = handle;
383 job_t *j = NULL;
384 papi_status_t (*f)();
386 if ((svc == NULL) || (printer == NULL) || (job_id < 0) ||
387 (attributes == NULL))
388 return (PAPI_BAD_ARGUMENT);
390 if ((result = service_connect(svc, printer)) != PAPI_OK)
391 return (result);
393 if ((*job = j = calloc(1, sizeof (*j))) == NULL)
394 return (PAPI_TEMPORARY_ERROR);
396 j->svc = svc;
397 f = (papi_status_t (*)())psm_sym(j->svc, "papiJobModify");
398 if (f != NULL)
399 result = f(svc->svc_handle, svc->name, job_id, attributes,
400 &j->job);
402 return (result);
406 * The functions defined below are private to Solaris. They are here
407 * temporarily, until equivalent functionality makes it's way into the PAPI
408 * spec. This is expected in the next minor version after v1.0.
410 papi_status_t
411 papiJobCreate(papi_service_t handle, char *printer,
412 papi_attribute_t **job_attributes,
413 papi_job_ticket_t *job_ticket, papi_job_t *job)
415 papi_status_t result = PAPI_INTERNAL_ERROR;
416 service_t *svc = handle;
417 job_t *j = NULL;
418 papi_status_t (*f)();
420 if ((svc == NULL) || (printer == NULL) || (job == NULL))
421 return (PAPI_BAD_ARGUMENT);
423 if ((result = service_connect(svc, printer)) != PAPI_OK)
424 return (result);
426 if ((*job = j = calloc(1, sizeof (*j))) == NULL)
427 return (PAPI_TEMPORARY_ERROR);
429 j->svc = svc;
430 f = (papi_status_t (*)())psm_sym(j->svc, "papiJobCreate");
431 if (f != NULL)
432 result = f(svc->svc_handle, svc->name, job_attributes,
433 job_ticket, &j->job);
435 return (result);
438 papi_status_t
439 papiJobStreamAdd(papi_service_t handle, char *printer, int32_t id,
440 papi_stream_t *stream)
442 papi_status_t result = PAPI_INTERNAL_ERROR;
443 service_t *svc = handle;
444 papi_status_t (*f)();
446 if ((svc == NULL) || (printer == NULL))
447 return (PAPI_BAD_ARGUMENT);
449 if ((result = service_connect(svc, printer)) != PAPI_OK)
450 return (result);
452 f = (papi_status_t (*)())psm_sym(svc, "papiJobStreamAdd");
453 if (f != NULL)
454 result = f(svc->svc_handle, svc->name, id, stream);
456 return (result);