paul@102 | 1 | /* |
paul@102 | 2 | * An opener for a file provided via the filesystem client interface. |
paul@102 | 3 | * |
paul@102 | 4 | * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> |
paul@102 | 5 | * |
paul@102 | 6 | * This program is free software; you can redistribute it and/or |
paul@102 | 7 | * modify it under the terms of the GNU General Public License as |
paul@102 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@102 | 9 | * the License, or (at your option) any later version. |
paul@102 | 10 | * |
paul@102 | 11 | * This program is distributed in the hope that it will be useful, |
paul@102 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@102 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@102 | 14 | * GNU General Public License for more details. |
paul@102 | 15 | * |
paul@102 | 16 | * You should have received a copy of the GNU General Public License |
paul@102 | 17 | * along with this program; if not, write to the Free Software |
paul@102 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@102 | 19 | * Boston, MA 02110-1301, USA |
paul@102 | 20 | */ |
paul@102 | 21 | |
paul@102 | 22 | #include "client_file_accessor.h" |
paul@102 | 23 | #include "client_file_opener.h" |
paul@102 | 24 | |
paul@102 | 25 | /* Return a file identifier for the given 'path'. */ |
paul@102 | 26 | |
paul@102 | 27 | fileid_t ClientFileOpener::get_fileid(const char *path) |
paul@102 | 28 | { |
paul@102 | 29 | _paths.insert(FilePathEntry(_counter, path)); |
paul@102 | 30 | |
paul@102 | 31 | return _counter++; |
paul@102 | 32 | } |
paul@102 | 33 | |
paul@102 | 34 | /* Return a new accessor for 'fileid'. */ |
paul@102 | 35 | |
paul@102 | 36 | Accessor *ClientFileOpener::make_accessor(fileid_t fileid) |
paul@102 | 37 | { |
paul@102 | 38 | FilePaths::iterator found = _paths.find(fileid); |
paul@102 | 39 | |
paul@102 | 40 | if (found != _paths.end()) |
paul@102 | 41 | return new ClientFileAccessor(found->second, fileid); |
paul@102 | 42 | else |
paul@102 | 43 | return NULL; |
paul@102 | 44 | } |
paul@102 | 45 | |
paul@102 | 46 | // vim: tabstop=4 expandtab shiftwidth=4 |