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]
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"
35 #include <papi_impl.h>
38 papiJobFree(papi_job_t job
)
40 job_t
*tmp
= (job_t
*)job
;
45 f
= (void (*)())psm_sym(tmp
->svc
, "papiJobFree");
53 papiJobListFree(papi_job_t
*jobs
)
58 for (i
= 0; jobs
[i
] != NULL
; i
++)
65 papiJobGetAttributeList(papi_job_t job
)
67 papi_attribute_t
**result
= NULL
;
71 papi_attribute_t
**(*f
)();
73 f
= (papi_attribute_t
**(*)())psm_sym(j
->svc
,
74 "papiJobGetAttributeList");
83 papiJobGetPrinterName(papi_job_t job
)
91 f
= (char *(*)())psm_sym(j
->svc
, "papiJobGetPrinterName");
100 papiJobGetId(papi_job_t job
)
108 f
= (int32_t (*)())psm_sym(j
->svc
, "papiJobGetId");
117 papiJobGetJobTicket(papi_job_t job
)
119 papi_job_ticket_t
*result
= NULL
;
123 papi_job_ticket_t
*(*f
)();
125 f
= (papi_job_ticket_t
*(*)())psm_sym(j
->svc
,
126 "papiJobGetJobTicket");
134 /* common support for papiJob{Submit|SubmitByReference|Validate} */
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
,
141 papi_status_t result
= PAPI_INTERNAL_ERROR
;
142 service_t
*svc
= handle
;
144 papi_status_t (*f
)();
146 if ((svc
== NULL
) || (printer
== NULL
) || (files
== NULL
) ||
148 return (PAPI_BAD_ARGUMENT
);
150 if ((result
= service_connect(svc
, printer
)) != PAPI_OK
)
153 if ((*job
= j
= calloc(1, sizeof (*j
))) == NULL
)
154 return (PAPI_TEMPORARY_ERROR
);
157 f
= (papi_status_t (*)())psm_sym(j
->svc
, function
);
159 result
= f(svc
->svc_handle
, svc
->name
, job_attributes
,
160 job_ticket
, files
, &j
->job
);
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
,
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"));
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
,
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
)
210 f
= (papi_status_t (*)())psm_sym(svc
, "papiJobStreamOpen");
212 result
= f(svc
->svc_handle
, svc
->name
, job_attributes
,
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
) ||
228 return (PAPI_BAD_ARGUMENT
);
230 f
= (papi_status_t (*)())psm_sym(svc
, "papiJobStreamWrite");
232 result
= f(svc
->svc_handle
, stream
, buffer
, buflen
);
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
;
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
);
252 f
= (papi_status_t (*)())psm_sym(j
->svc
, "papiJobStreamClose");
254 result
= f(svc
->svc_handle
, stream
, &j
->job
);
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
;
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
)
274 if ((*job
= j
= calloc(1, sizeof (*j
))) == NULL
)
275 return (PAPI_TEMPORARY_ERROR
);
278 f
= (papi_status_t (*)())psm_sym(j
->svc
, "papiJobQuery");
280 result
= f(svc
->svc_handle
, svc
->name
, job_id
,
281 requested_attrs
, &j
->job
);
287 papiJobMove(papi_service_t handle
, char *printer
, int32_t job_id
,
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
)
300 f
= (papi_status_t (*)())psm_sym(svc
, "papiJobMove");
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
);
313 /* common support for papiJob{Cancel|Release|Restart|Promote} */
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
)
328 f
= (papi_status_t (*)())psm_sym(svc
, function
);
330 result
= f(svc
->svc_handle
, svc
->name
, job_id
);
336 papiJobCancel(papi_service_t handle
, char *printer
, int32_t job_id
)
338 return (_papi_job_handle_printer_id(handle
, printer
, job_id
,
343 papiJobRelease(papi_service_t handle
, char *printer
, int32_t job_id
)
345 return (_papi_job_handle_printer_id(handle
, printer
, job_id
,
350 papiJobRestart(papi_service_t handle
, char *printer
, int32_t job_id
)
352 return (_papi_job_handle_printer_id(handle
, printer
, job_id
,
357 papiJobPromote(papi_service_t handle
, char *printer
, int32_t job_id
)
359 return (_papi_job_handle_printer_id(handle
, printer
, job_id
,
364 papiJobCommit(papi_service_t handle
, char *printer
, int32_t job_id
)
366 return (_papi_job_handle_printer_id(handle
, printer
, job_id
,
371 papiJobHold(papi_service_t handle
, char *printer
, int32_t job_id
)
373 return (_papi_job_handle_printer_id(handle
, printer
, job_id
,
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
;
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
)
393 if ((*job
= j
= calloc(1, sizeof (*j
))) == NULL
)
394 return (PAPI_TEMPORARY_ERROR
);
397 f
= (papi_status_t (*)())psm_sym(j
->svc
, "papiJobModify");
399 result
= f(svc
->svc_handle
, svc
->name
, job_id
, attributes
,
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.
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
;
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
)
426 if ((*job
= j
= calloc(1, sizeof (*j
))) == NULL
)
427 return (PAPI_TEMPORARY_ERROR
);
430 f
= (papi_status_t (*)())psm_sym(j
->svc
, "papiJobCreate");
432 result
= f(svc
->svc_handle
, svc
->name
, job_attributes
,
433 job_ticket
, &j
->job
);
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
)
452 f
= (papi_status_t (*)())psm_sym(svc
, "papiJobStreamAdd");
454 result
= f(svc
->svc_handle
, svc
->name
, id
, stream
);