コード例 #1
0
ファイル: file_watch.cpp プロジェクト: kahrl/buildat
	CMultiFileWatch()
	{
		m_fd = inotify_init1(IN_NONBLOCK);
		log_d(MODULE, "CMultiFileWatch(): m_fd=%i", m_fd);
		if(m_fd == -1){
			throw Exception(ss_()+"inotify_init() failed: "+strerror(errno));
		}
	}
コード例 #2
0
ファイル: file_watch.cpp プロジェクト: kahrl/buildat
	CFileWatch(const sv_<ss_> &paths, std::function<void()> cb):
		m_cb(cb)
	{
		m_fd = inotify_init1(IN_NONBLOCK);
		if(m_fd == -1){
			throw Exception(ss_()+"inotify_init() failed: "+strerror(errno));
		}
		for(const ss_ &path : paths){
			int r = inotify_add_watch(m_fd, path.c_str(), IN_CLOSE_WRITE |
					IN_MOVED_TO | IN_CREATE | IN_MOVED_FROM | IN_DELETE |
					IN_MODIFY | IN_ATTRIB);
			if(r == -1){
				throw Exception(ss_()+"inotify_add_watch() failed: "+
						strerror(errno)+" (path="+path+")");
			}
			log_d(MODULE, "Watching path \"%s\" (inotify fd=%i)", cs(path), m_fd);
			m_watch_paths[r] = path;
		}
	}
コード例 #3
0
ファイル: rccpp.cpp プロジェクト: t0suj4/buildat
	bool compile(const std::string &in_path, const std::string &out_path,
			const ss_ &extra_cxxflags, const ss_ &extra_ldflags)
	{
		ss_ command = m_compiler_command;
		command += " -DRCCPP -g -fPIC -fvisibility=hidden -shared";
		command += " -std=c++11";
		if(extra_cxxflags != "")
			command += ss_()+" "+extra_cxxflags;
		if(extra_ldflags != "")
			command += ss_()+" "+extra_ldflags;

		for(const std::string &dir : include_directories) command += " -I"+dir;
		for(const std::string &dir : library_directories) command += " -L"+dir;

		command += " -o"+out_path;
		command += " "+in_path;

		int exit_status = interface::process::shell_exec(command);

		return exit_status == 0;
	}
コード例 #4
0
ファイル: arduino_controls.hpp プロジェクト: celeron55/opts
static void arduino_serial_write(const char *data, size_t len)
{
	if(arduino_serial_debug_mode == "raw" && data != NULL && len != 0){
		printf("%s", cs(ss_(data, len)));
	}
	if(arduino_serial_fd != -1){
		int r = write(arduino_serial_fd, data, len);
		if(r == -1){
			printf("Arduino write error\n");
			arduino_serial_fd = -1;
		} else if((size_t)r != len){
			printf("WARNING: Arduino serial didn't take the entire message\n");
			// TODO: Maybe handle this properly
		}
	}
}
コード例 #5
0
ファイル: rccpp.cpp プロジェクト: t0suj4/buildat
	bool build(const std::string &module_name,
			const std::string &in_path, const std::string &out_path,
			const ss_ &extra_cxxflags, const ss_ &extra_ldflags)
	{
		log_ni(MODULE, "Building %s: %s -> %s... ", cs(module_name), cs(in_path),
				cs(out_path));

		std::string out_dir = c55fs::stripFilename(out_path);
		c55fs::CreateAllDirs(out_dir);

		if(!compile(in_path, out_path, extra_cxxflags, extra_ldflags)){
			log_i(MODULE, "Failed!");
			return false;
		}
		log_i(MODULE, "Success!");

		void *new_module = library_load(out_path.c_str());
		if(new_module == NULL){
			log_i(MODULE, "Failed to load compiled library: %s", dlerror());
			return false;
		}

		ss_ constructor_name = ss_()+"createModule_"+module_name;
		RCCPP_Constructor constructor = (RCCPP_Constructor)library_get_address(
				new_module, constructor_name.c_str());
		if(constructor == nullptr){
			log_i(MODULE, "%s is missing from the library", cs(constructor_name));
			return false;
		}

		auto it = m_module_info.find(module_name);
		if(it != m_module_info.end()){
			RCCPP_Info &funcs = it->second;
			funcs.constructor = constructor;
			funcs.module = new_module;
		} else {
			RCCPP_Info funcs;
			funcs.constructor = constructor;
			funcs.module = new_module;
			m_module_info.emplace(module_name, std::move(funcs));
		}
		return true;
	}
コード例 #6
0
ファイル: file_watch.cpp プロジェクト: kahrl/buildat
	void add(const ss_ &path, std::function<void(const ss_ &path)> cb)
	{
		for(auto &pair : m_watch){
			sp_<WatchThing> &watch = pair.second;
			if(watch->path == path){
				log_d(MODULE, "Adding callback to path \"%s\" (inotify fd=%i)",
						cs(path), pair.first);
				watch->cbs.push_back(cb);
				return;
			}
		}
		int r = inotify_add_watch(m_fd, path.c_str(), IN_CLOSE_WRITE |
				IN_MOVED_TO | IN_CREATE | IN_MOVED_FROM | IN_DELETE |
				IN_MODIFY | IN_ATTRIB);
		if(r == -1){
			throw Exception(ss_()+"inotify_add_watch() failed: "+
					strerror(errno)+" (path="+path+")");
		}
		log_d(MODULE, "Watching path \"%s\" (inotify fd=%i)", cs(path), m_fd);
		m_watch[r] = sp_<WatchThing>(new WatchThing(path, {cb}));
	}