summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore10
-rw-r--r--SConstruct16
-rw-r--r--main.cpp12
-rw-r--r--music.cpp44
-rw-r--r--music.h30
5 files changed, 112 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c2fa971
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,10 @@
+*.swp
+*.o
+*.conf
+*.sock
+*.vim
+/audistd
+.sconf_temp
+.sconsign.dblite
+.sconf_temp
+config.log
diff --git a/SConstruct b/SConstruct
new file mode 100644
index 0000000..325abe5
--- /dev/null
+++ b/SConstruct
@@ -0,0 +1,16 @@
+AddOption('--release', action = 'store_true')
+
+env = Environment(CPPPATH = ['.'], CCFLAGS = ['-pthread'], LINKFLAGS = ['-pthread'])
+
+conf = Configure(env)
+conf.CheckLib('boost_system')
+env = conf.Finish()
+
+if GetOption('release'):
+ env.Append(CCFLAGS = ['-O2'])
+else:
+ env.Append(CCFLAGS = ['-Wall', '-g'])
+
+env.Program('audistd', Glob('*.cpp'))
+
+# vim: syn=python
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..55c1de0
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,12 @@
+#include <iostream>
+#include "music.h"
+
+int main(int argc, char **argv) {
+ try {
+ music::init(argv[1]);
+ } catch(std::exception& e) {
+ std::cerr << e.what() << std::endl;
+ }
+
+ return 0;
+}
diff --git a/music.cpp b/music.cpp
new file mode 100644
index 0000000..bd50719
--- /dev/null
+++ b/music.cpp
@@ -0,0 +1,44 @@
+#include "music.h"
+
+#include <cstdio>
+#include <stdexcept>
+#include <sys/types.h>
+#include <dirent.h>
+#include <errno.h>
+#include <string.h>
+
+namespace music {
+
+MusicDirectory *root_directory = NULL;
+
+void init(const std::string root) {
+ root_directory = new MusicDirectory(root);
+}
+
+};
+
+MusicTrack::MusicTrack(const std::string filename) {
+ printf("%s\n", filename.c_str());
+ this->filename = filename;
+}
+
+MusicDirectory::MusicDirectory(const std::string root) {
+ printf("%s\n", root.c_str());
+
+ DIR *d = opendir(root.c_str());
+ if(!d) {
+ throw std::runtime_error(strerror(errno));
+ }
+
+ struct dirent *dir;
+ while((dir = readdir(d)) != NULL) {
+ if(strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) continue;
+ if(dir->d_type == DT_DIR) {
+ directories.push_back(MusicDirectory(root + "/" + dir->d_name));
+ } else if(dir->d_type == DT_REG) {
+ tracks.push_back(MusicTrack(root + "/" + dir->d_name));
+ }
+ }
+
+ closedir(d);
+}
diff --git a/music.h b/music.h
new file mode 100644
index 0000000..8e0bd9e
--- /dev/null
+++ b/music.h
@@ -0,0 +1,30 @@
+#ifndef MUSIC_H
+#define MUSIC_H
+
+#include <string>
+#include <vector>
+
+class MusicTrack {
+ public:
+ MusicTrack(const std::string filename);
+ std::string filename;
+};
+
+class MusicDirectory;
+typedef std::vector<MusicDirectory> MusicDirectories;
+typedef std::vector<MusicTrack> MusicTracks;
+
+class MusicDirectory {
+ public:
+ MusicDirectory(const std::string root);
+ std::string path;
+ MusicDirectories directories;
+ MusicTracks tracks;
+};
+
+namespace music {
+ extern MusicDirectory *root_directory;
+ void init(const std::string root);
+};
+
+#endif