Updated license
[anna.git] / include / anna / io / functions.hpp
1 // ANNA - Anna is Not Nothingness Anymore
2 //
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
4 //
5 // https://bitbucket.org/testillano/anna
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 //
11 //     * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //     * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 //     * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Authors: eduardo.ramos.testillano@gmail.com
34 //          cisco.tierra@gmail.com
35
36
37 #ifndef anna_io_functions_hpp
38 #define anna_io_functions_hpp
39
40 #include <sys/stat.h>
41 #include <unistd.h>
42
43 #include <anna/config/defines.hpp>
44 #include <anna/core/RuntimeException.hpp>
45 #include <anna/core/util/Millisecond.hpp>
46
47 namespace anna {
48
49 namespace io {
50
51 /**
52    Grupo de metodos relacionadas con operaciones de entrada/salida
53 */
54 struct functions {
55   /**
56      Crea el arbol de directorios recibido como parametro.
57   */
58   static void mkdir(const std::string& path) throw(RuntimeException);
59
60   /**
61      Indica si el PATH recibido como parametro existe o no.
62      \return Devuelve \em true si el PATH recibido como parametro existe o \em false
63      en otro caso.
64   */
65   static bool exists(const std::string& path) throw(RuntimeException) { return exists(path.c_str()); }
66
67   /**
68      Indica si el PATH recibido como parametro existe o no.
69      \return Devuelve \em true si el PATH recibido como parametro existe o \em false
70      en otro caso.
71   */
72   static bool exists(const char* path) throw(RuntimeException);
73
74   /**
75      Indica si el PATH recibido como parametro es un directorio o no.
76      \return Devuelve \em true si el PATH recibido como parametro es un directorio o \em false
77      en otro caso.
78   */
79   static bool isADirectory(const std::string& path) throw(RuntimeException) { return isADirectory(path.c_str()); }
80
81   /**
82      Indica si el PATH recibido como parametro es un directorio o no.
83      \return Devuelve \em true si el PATH recibido como parametro es un directorio o \em false
84      en otro caso.
85   */
86   static bool isADirectory(const char* path) throw(RuntimeException);
87
88   /**
89    * Devuelve el i-nodo asociado al nombre de fichero de recibido como parámetro.
90    * \param path Ruta completa del fichero a comprobar.
91    * \return El nº de i-nodo asociado al fichero
92    */
93   static ino_t getINode(const std::string& path) throw(RuntimeException) { return getINode(path.c_str()); }
94
95   /**
96    * Devuelve el i-nodo asociado al nombre de fichero de recibido como parámetro.
97    * \param path Ruta completa del fichero a comprobar.
98    * \return El nº de i-nodo asociado al fichero
99    */
100   static ino_t getINode(const char* path) throw(RuntimeException);
101
102   /**
103    * Espera a que haya actividad de entrada en el fd recibido como parámetro.
104    * \param fd File descriptor sobre el que vamos a comprobar la actividad.
105    * \param timeout Número máximo de milisegundos que puede quedar a la espera. Si vale 0 no realiza ninguna espera.
106    * \return \em true si el proceso detecta actividad o \em false si se cumplió el timeout sin recibir información.
107    */
108   static bool waitInput(const int fd, const Millisecond&) throw(RuntimeException);
109 };
110
111 }
112 }
113 #endif