1 /* sane - Scanner Access Now Easy.
2 
3    Copyright (C) 2005 Gerhard Jaeger <gerhard@gjaeger.de>
4 
5    This file is part of the SANE package.
6 
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2 of the
10    License, or (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 
20    As a special exception, the authors of SANE give permission for
21    additional uses of the libraries contained in this release of SANE.
22 
23    The exception is that, if you link a SANE library with other files
24    to produce an executable, this does not by itself cause the
25    resulting executable to be covered by the GNU General Public
26    License.  Your use of that executable is in no way restricted on
27    account of linking the SANE library code into it.
28 
29    This exception does not, however, invalidate any other reasons why
30    the executable file might be covered by the GNU General Public
31    License.
32 
33    If you submit changes to SANE to the maintainers to be included in
34    a subsequent release, you agree by submitting the changes that
35    those changes may be distributed with this exception intact.
36 
37    If you write modifications of your own for SANE, it is your choice
38    whether to permit this exception to apply to your modifications.
39    If you do not wish that, delete this exception notice.
40 
41 */
42 
43 /** @file sanei_access.h
44  *  Interface file for the sanei_access functions.
45  *
46  *  The idea is to provide some simple locking/unlocking mechanism, which
47  *  can be used to protect device access from more than one frontend
48  *  simultaneously.
49  */
50 
51 #ifndef sanei_access_h
52 #define sanei_access_h
53 
54 #include "../include/sane/config.h"
55 #include "../include/sane/sane.h"
56 
57 /** Initialize sanei_access.
58  *
59  * This function must be called before any other sanei_access function.
60  *
61  * @param backend - backend name, who uses this lib
62  */
63 extern void sanei_access_init( const char * backend );
64 
65 /** Set a lock.
66  *
67  * The function tries to open/create exclusively a lock file in
68  * $PATH_SANE_LOCK_DIR.
69  * If the file could be created successfully, the function fills in the
70  * process ID.
71  * The complete filename of the lockfile is created as follows:
72  * $PATH_SANE_LOCK_DIR/LCK..&lt;devicename&gt;
73  * If the lock could not be set, the function tries it until the timeout
74  * period has been elapsed.
75  *
76  * @param devicename - unique part of the lockfile name
77  * @param timeout    - time in seconds to try to set a lock
78  * @return
79  * - SANE_STATUS_GOOD          - if the lock has been successfully set
80  * - SANE_STATUS_ACCESS_DENIED - the lock could not set
81  */
82 extern SANE_Status sanei_access_lock( const char * devicename, SANE_Word timeout );
83 
84 /** Unlock a previously set lock.
85  *
86  * The function tries to unlock a previously created lock. The lockfile will be
87  * closed and removed.
88  *
89  * @param devicename - part of the lockfile name, use for sanei_acess_lock()
90  * @return
91  * - SANE_STATUS_GOOD - currently the one and only return value
92  */
93 extern SANE_Status sanei_access_unlock( const char * devicename );
94 
95 #endif /* sanei_access_h */
96