]> Dogcows Code - chaz/yoink/blobdiff - src/moof/resource.cc
fixed documentation about where to find licenses
[chaz/yoink] / src / moof / resource.cc
index 3cf901b06473ae730fccd87d556a05d973460fa6..8188313b8442011b615925cd61e1aafcf6b81260 100644 (file)
@@ -1,38 +1,39 @@
 
-/*]  Copyright (c) 2009-2010, Charles McGarvey  [**************************
+/*]  Copyright (c) 2009-2011, Charles McGarvey  [*****************************
 **]  All rights reserved.
 *
-* vi:ts=4 sw=4 tw=75
-*
 * Distributable under the terms and conditions of the 2-clause BSD license;
 * see the file COPYING for a complete text of the license.
 *
-**************************************************************************/
+*****************************************************************************/
 
+#if HAVE_CONFIG_H
 #include "config.h"
+#endif
 
 #include <queue>
 
-#ifdef USE_HOTLOADING
-#include <sys/inotify.h>
-#include <sys/ioctl.h>
-#endif
-
 #include <boost/algorithm/string.hpp>
 #include <boost/weak_ptr.hpp>
+
 #include <stlplus/portability/file_system.hpp>
 
+#if ENABLE_HOTLOADING
+#include <sys/inotify.h>
+#include <sys/ioctl.h>
+#endif
+
 #include "hash.hh"
+#include "log.hh"
 #include "resource.hh"
 
-
 #ifndef BUF_SIZE
-#define BUF_SIZE 4096
+#define BUF_SIZE 8192
 #endif
 
 
 namespace moof {
-       
+
 
 /*] Filesystem searching
  *************************************************************************/
@@ -44,7 +45,6 @@ void resource::set_search_paths(const std::string& paths)
        boost::split(search_paths_, paths, boost::is_any_of(":"));
 }
 
-
 std::string resource::find_file(const std::string& name)
 {
        std::string ext = stlplus::extension_part(name);
@@ -63,12 +63,12 @@ std::string resource::find_file(const std::string& name)
                        // try it with the prefix first
                        path = stlplus::filespec_to_path(*it, prefix);
                        path = stlplus::filespec_to_path(path, name);
-                       log_info("looking for", name, "at", path);
+                       log_debug("looking for", name, "at", path);
                        if (stlplus::file_exists(path)) return path;
                }
 
                path = stlplus::filespec_to_path(*it, name);
-               log_info("looking for", name, "at", path);
+               log_debug("looking for", name, "at", path);
                if (stlplus::file_exists(path)) return path;
        }
 
@@ -76,8 +76,8 @@ std::string resource::find_file(const std::string& name)
        return std::string();
 }
 
-std::string resource::find_file(const std::string& name,
-                                                               const std::string& ext)
+std::string
+resource::find_file(const std::string& name, const std::string& ext)
 {
        std::string actual_ext = stlplus::extension_part(name);
        if (actual_ext != ext)
@@ -105,14 +105,12 @@ static struct rsrc_list
        {
                hash<std::string,resource_weakptr,hash_function>::iterator it;
                for (it = table.begin(); it != table.end(); ++it)
-               {
                        log_warning("leaked resource:", (*it).first);
-               }
        }
 #endif
 } rsrc_list;
 
-#ifdef USE_HOTLOADING
+#if ENABLE_HOTLOADING
 static struct watch_list
 {
        // this table associates a watch descriptor with a loaded resource
@@ -131,7 +129,7 @@ static struct watch_list
        int add(resource_ptr rsrc)
        {
                int wd = inotify_add_watch(fd, rsrc->path().c_str(),
-                                                                  IN_DELETE_SELF | IN_MODIFY);
+                               IN_DELETE_SELF | IN_MODIFY);
                table[wd] = rsrc;
                return wd;
        }
@@ -142,22 +140,19 @@ static struct watch_list
 } watch_list;
 #endif
 
-
 resource_ptr resource::load(const std::string& name)
 {
        std::string ext = stlplus::extension_part(name);
        return load_with_path(find_file(name, ext), ext);
 }
 
-resource_ptr resource::load(const std::string& name,
-                                                       const std::string& ext)
+resource_ptr resource::load(const std::string& name, const std::string& ext)
 {
        return load_with_path(find_file(name, ext), ext);
 }
 
-
-resource_ptr resource::load_with_path(const std::string& path,
-                                                                         const std::string& ext)
+resource_ptr
+resource::load_with_path(const std::string& path, const std::string& ext)
 {
        if (path.empty()) return resource_ptr();
 
@@ -179,7 +174,7 @@ resource_ptr resource::load_with_path(const std::string& path,
                rsrc_list.table[path] = rsrc;
                rsrc->path_ = path;
                rsrc->type_ = ext;
-#ifdef USE_HOTLOADING
+#if ENABLE_HOTLOADING
                rsrc->wd_ = watch_list.add(rsrc);
 #endif
                return rsrc;
@@ -189,7 +184,6 @@ resource_ptr resource::load_with_path(const std::string& path,
        return resource_ptr();
 }
 
-
 /*] Hotloading
  *************************************************************************/
 
@@ -197,7 +191,7 @@ int resource::reload_as_needed()
 {
        int count = 0;
 
-#ifdef USE_HOTLOADING
+#if ENABLE_HOTLOADING
        char bytes[BUF_SIZE];
        int num_bytes;
        // an inotify file descriptor lets your read inotify_event structures
@@ -237,7 +231,6 @@ int resource::reload_as_needed()
                }
        }
 #endif
-
        return count;
 }
 
@@ -255,37 +248,35 @@ void resource::reload()
 resource::~resource()
 {
        rsrc_list.table.erase(path_);
-#ifdef USE_HOTLOADING
+#if ENABLE_HOTLOADING
        watch_list.remove(wd_);
 #endif
 }
 
-
 /*] Resource registration
  *************************************************************************/
 
 bool resource::call_registry(const std::string& ext,
-                                                        loader_ptr& loader,
-                                                        registry_action action)
+               loader_ptr& loader, registry_action action)
 {
        static std::map<std::string,loader_ptr> table;
 
        switch (action)
        {
-               case set:
-               {
-                       if (loader) table[ext] = loader;
-                       else        table.erase(ext);
-                       break;
-               }
+       case lookup:
+       {
+               std::map<std::string,loader_ptr>::iterator it;
+               it = table.find(ext);
+               if (it != table.end()) loader = (*it).second;
+               break;
+       }
 
-               case lookup:
-               {
-                       std::map<std::string,loader_ptr>::iterator it;
-                       it = table.find(ext);
-                       if (it != table.end()) loader = (*it).second;
-                       break;
-               }
+       case set:
+               if (loader)
+                       table[ext] = loader;
+               else
+                       table.erase(ext);
+               break;
        }
 
        return loader;
This page took 0.023142 seconds and 4 git commands to generate.