1141cc406Sopenharmony_ci/* sane - Scanner Access Now Easy.
2141cc406Sopenharmony_ci
3141cc406Sopenharmony_ci   Copyright (C) 2005 Gerhard Jaeger <gerhard@gjaeger.de>
4141cc406Sopenharmony_ci
5141cc406Sopenharmony_ci   This file is part of the SANE package.
6141cc406Sopenharmony_ci
7141cc406Sopenharmony_ci   This program is free software; you can redistribute it and/or
8141cc406Sopenharmony_ci   modify it under the terms of the GNU General Public License as
9141cc406Sopenharmony_ci   published by the Free Software Foundation; either version 2 of the
10141cc406Sopenharmony_ci   License, or (at your option) any later version.
11141cc406Sopenharmony_ci
12141cc406Sopenharmony_ci   This program is distributed in the hope that it will be useful, but
13141cc406Sopenharmony_ci   WITHOUT ANY WARRANTY; without even the implied warranty of
14141cc406Sopenharmony_ci   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15141cc406Sopenharmony_ci   General Public License for more details.
16141cc406Sopenharmony_ci
17141cc406Sopenharmony_ci   You should have received a copy of the GNU General Public License
18141cc406Sopenharmony_ci   along with this program.  If not, see <https://www.gnu.org/licenses/>.
19141cc406Sopenharmony_ci
20141cc406Sopenharmony_ci   As a special exception, the authors of SANE give permission for
21141cc406Sopenharmony_ci   additional uses of the libraries contained in this release of SANE.
22141cc406Sopenharmony_ci
23141cc406Sopenharmony_ci   The exception is that, if you link a SANE library with other files
24141cc406Sopenharmony_ci   to produce an executable, this does not by itself cause the
25141cc406Sopenharmony_ci   resulting executable to be covered by the GNU General Public
26141cc406Sopenharmony_ci   License.  Your use of that executable is in no way restricted on
27141cc406Sopenharmony_ci   account of linking the SANE library code into it.
28141cc406Sopenharmony_ci
29141cc406Sopenharmony_ci   This exception does not, however, invalidate any other reasons why
30141cc406Sopenharmony_ci   the executable file might be covered by the GNU General Public
31141cc406Sopenharmony_ci   License.
32141cc406Sopenharmony_ci
33141cc406Sopenharmony_ci   If you submit changes to SANE to the maintainers to be included in
34141cc406Sopenharmony_ci   a subsequent release, you agree by submitting the changes that
35141cc406Sopenharmony_ci   those changes may be distributed with this exception intact.
36141cc406Sopenharmony_ci
37141cc406Sopenharmony_ci   If you write modifications of your own for SANE, it is your choice
38141cc406Sopenharmony_ci   whether to permit this exception to apply to your modifications.
39141cc406Sopenharmony_ci   If you do not wish that, delete this exception notice.
40141cc406Sopenharmony_ci
41141cc406Sopenharmony_ci*/
42141cc406Sopenharmony_ci
43141cc406Sopenharmony_ci/** @file sanei_access.h
44141cc406Sopenharmony_ci *  Interface file for the sanei_access functions.
45141cc406Sopenharmony_ci *
46141cc406Sopenharmony_ci *  The idea is to provide some simple locking/unlocking mechanism, which
47141cc406Sopenharmony_ci *  can be used to protect device access from more than one frontend
48141cc406Sopenharmony_ci *  simultaneously.
49141cc406Sopenharmony_ci */
50141cc406Sopenharmony_ci
51141cc406Sopenharmony_ci#ifndef sanei_access_h
52141cc406Sopenharmony_ci#define sanei_access_h
53141cc406Sopenharmony_ci
54141cc406Sopenharmony_ci#include "../include/sane/config.h"
55141cc406Sopenharmony_ci#include "../include/sane/sane.h"
56141cc406Sopenharmony_ci
57141cc406Sopenharmony_ci/** Initialize sanei_access.
58141cc406Sopenharmony_ci *
59141cc406Sopenharmony_ci * This function must be called before any other sanei_access function.
60141cc406Sopenharmony_ci *
61141cc406Sopenharmony_ci * @param backend - backend name, who uses this lib
62141cc406Sopenharmony_ci */
63141cc406Sopenharmony_ciextern void sanei_access_init( const char * backend );
64141cc406Sopenharmony_ci
65141cc406Sopenharmony_ci/** Set a lock.
66141cc406Sopenharmony_ci *
67141cc406Sopenharmony_ci * The function tries to open/create exclusively a lock file in
68141cc406Sopenharmony_ci * $PATH_SANE_LOCK_DIR.
69141cc406Sopenharmony_ci * If the file could be created successfully, the function fills in the
70141cc406Sopenharmony_ci * process ID.
71141cc406Sopenharmony_ci * The complete filename of the lockfile is created as follows:
72141cc406Sopenharmony_ci * $PATH_SANE_LOCK_DIR/LCK..&lt;devicename&gt;
73141cc406Sopenharmony_ci * If the lock could not be set, the function tries it until the timeout
74141cc406Sopenharmony_ci * period has been elapsed.
75141cc406Sopenharmony_ci *
76141cc406Sopenharmony_ci * @param devicename - unique part of the lockfile name
77141cc406Sopenharmony_ci * @param timeout    - time in seconds to try to set a lock
78141cc406Sopenharmony_ci * @return
79141cc406Sopenharmony_ci * - SANE_STATUS_GOOD          - if the lock has been successfully set
80141cc406Sopenharmony_ci * - SANE_STATUS_ACCESS_DENIED - the lock could not set
81141cc406Sopenharmony_ci */
82141cc406Sopenharmony_ciextern SANE_Status sanei_access_lock( const char * devicename, SANE_Word timeout );
83141cc406Sopenharmony_ci
84141cc406Sopenharmony_ci/** Unlock a previously set lock.
85141cc406Sopenharmony_ci *
86141cc406Sopenharmony_ci * The function tries to unlock a previously created lock. The lockfile will be
87141cc406Sopenharmony_ci * closed and removed.
88141cc406Sopenharmony_ci *
89141cc406Sopenharmony_ci * @param devicename - part of the lockfile name, use for sanei_acess_lock()
90141cc406Sopenharmony_ci * @return
91141cc406Sopenharmony_ci * - SANE_STATUS_GOOD - currently the one and only return value
92141cc406Sopenharmony_ci */
93141cc406Sopenharmony_ciextern SANE_Status sanei_access_unlock( const char * devicename );
94141cc406Sopenharmony_ci
95141cc406Sopenharmony_ci#endif /* sanei_access_h */
96