1 #ifndef _MADARA_KNOWLEDGE_BASE_FILES_CPP_ 2 #define _MADARA_KNOWLEDGE_BASE_FILES_CPP_ 6 #include "ace/OS_NS_fcntl.h" 33 ACE_Mem_Map & mem_map)
37 ACE_Mem_Map mapped_file (filename);
38 return mem_map.map (filename);
50 std::stringstream source_filename;
51 std::stringstream dest_filename;
54 source_filename << filename;
59 dest_filename << knowledge_key;
62 "Files::read_file : %s->%s\n",
63 source_filename.str ().c_str (), dest_filename.str ().c_str ());
67 ACE_Mem_Map mapped_file;
68 read_file (source_filename.str ().c_str (), mapped_file);
69 void * file_contents = mapped_file.addr ();
70 size_t size = mapped_file.size ();
73 "Files::read_file : file size is %d, loaded at 0x%x\n",
80 size_t actual =
write_file (dest_filename.str ().c_str (),
90 "Files::read_file : file imported with %" PRIu64
" bytes\n", actual);
97 mapped_file.close_filemapping_handle ();
103 "Files::read_file : read file failed with %d\n", ret);
118 std::stringstream source_filename;
119 std::stringstream dest_filename;
123 source_filename <<
"/";
124 source_filename << knowledge_key;
127 dest_filename << filename;
130 "Files::write_file : %s->%s\n",
131 source_filename.str ().c_str (), dest_filename.str ().c_str ());
135 ACE_Mem_Map mapped_file;
136 read_file (source_filename.str ().c_str (), mapped_file);
137 void * file_contents = mapped_file.addr ();
138 size_t size = mapped_file.size ();
141 "Files::write_file : file size is %d, loaded at 0x%x\n",
142 size, file_contents);
148 size_t actual =
write_file (dest_filename.str ().c_str (),
149 file_contents, size);
158 "Files::write_file : file saved with %" PRIu64
" bytes\n", actual);
165 mapped_file.close_filemapping_handle ();
166 mapped_file.close ();
171 "Files::write_file : write file failed with %d\n", ret);
180 void *& buffer,
size_t & size)
186 ACE_HANDLE file_handle = ACE_OS::open (filename,
187 O_RDWR | O_CREAT | O_TRUNC,
188 ACE_DEFAULT_FILE_PERMS);
191 "Files::write_file : beginning write of %" PRIu64
" bytes\n", size);
193 if (file_handle != ACE_INVALID_HANDLE)
196 actual = ACE_OS::write (file_handle, buffer, size);
197 ACE_OS::close (file_handle);
215 std::stringstream source_filename;
216 std::stringstream dest_filename;
219 source_filename << policy_file;
223 dest_filename <<
"/";
224 dest_filename << policy_key;
227 "Files::read_policy : %s->%s\n",
228 source_filename.str ().c_str (), dest_filename.str ().c_str ());
232 ACE_Mem_Map mapped_file;
233 read_file (source_filename.str ().c_str (), mapped_file);
234 void * file_contents = mapped_file.addr ();
235 size_t size = mapped_file.size ();
238 "Files::read_policy : file size is %d, loaded at 0x%x\n",
239 size, file_contents);
245 size_t actual =
write_file (dest_filename.str ().c_str (),
246 file_contents, size);
255 "Files::read_policy : file imported with %zu bytes\n", actual);
262 mapped_file.close_filemapping_handle ();
263 mapped_file.close ();
268 "Files::read_policy : read file failed with %d\n", ret);
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
static const std::string files_folder_
MADARA_Export int read_policy(const std::string &policy_key, const std::string &policy_file)
Read a policy into the knowledge base.
static const std::string policies_folder_
MADARA_Export int shape_file(const std::string &source_key, const std::string &target_key, const std::string &policy_key)
Shape a file according to a shaping policy.
MADARA_Export int read_file(const std::string &knowledge_key, const std::string &filename)
Read a file into the knowledge base.
This class stores variables and their values for use by any entity needing state information in a thr...
#define madara_logger_log(logger, level,...)
Fast version of the madara::logger::log method.
Files(ThreadSafeContext &map)
Constructor.
MADARA_Export ssize_t write_file(const std::string &knowledge_key, const std::string &filename)
Write a file from the knowledge base to a specified location.
logger::Logger & get_logger(void) const
Gets the logger used for information printing.