ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/DecentralizedMedia/DecentralizedMedia.cpp
Revision: 474
Committed: 2005-06-08T12:45:23-07:00 (20 years ago) by douglas
File size: 2169 byte(s)
Log Message:
Getting somewhere.

File Contents

# Content
1 // Decentralized Media
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 #include <menes/standard.hh>
8
9 #include <menes-api/pcre/regex.hpp>
10 #include <menes-app/simple.hpp>
11 #include <menes-etl/fnbind.hpp>
12 #include <menes-ios/helpers.hpp>
13 #include <menes-net/http/request.hpp>
14 #include <menes-net/http/response.hpp>
15
16 #include "DecentralizedMedia.hpp"
17
18 int Main(const app::Options& options)
19 {
20 _L<ext::String> extensions, locals;
21 api::Pcre::RegEx extension(_B("^-extension=(.+)$")), local(_B("^-local=(.+)$"));
22
23 _foreach (const app::ArgumentList, arg, app::GetArguments())
24 {
25 api::Pcre::RegEx::Match match;
26
27 if (match = extension(*arg))
28 extensions.InsertLast(match[1]);
29 else if (match = local(*arg))
30 locals.InsertLast(match[1]);
31 }
32
33 if (extensions.IsEmpty())
34 extensions.InsertLast(_B("mp3"));
35
36 DecentralizedMedia media(extensions, locals);
37
38 media.Block();
39
40 return 0;
41 }
42
43 DecentralizedMedia::DecentralizedMedia(const _L<ext::String>& extensions, const _L<ext::String>& locals) : waf::Server(_B("Web")), process(bmp.IsRunning() ? NULL : new api::Process(_B("/usr/X11R6/bin/beep-media-player"))), extensions(extensions)
44 {
45 if (!locals.IsEmpty())
46 {
47 _L<ext::String> args(locals);
48
49 _foreach (const _L<ext::String>, extension, extensions)
50 {
51 args.InsertLast(_B("-name"));
52 args.InsertLast(_S<ios::String>() << _B("*.") << *extension);
53 }
54
55 _H<api::Process> find(new api::Process(_B("/usr/bin/find"), args));
56 ext::String file;
57
58 while (ios::ReadLine(*find->GetReader(), file))
59 media.Insert(file);
60
61 find->Join();
62 }
63
64 AddPort(6996);
65 }
66
67 DecentralizedMedia::~DecentralizedMedia()
68 {
69 if (!process.IsEmpty())
70 {
71 _H<api::Thread> thread(new api::Thread(etl::BindAll(&DecentralizedMedia::Destroy, this)));
72
73 bmp.Quit();
74
75 thread->Join();
76 }
77 }
78
79 void DecentralizedMedia::Process(const net::Http::Request& request, net::Http::Response& response)
80 {
81 if (request.method_ == _B("EXTENSIONS"))
82 {
83 response.SetStatus(200);
84
85 _foreach (const _L<ext::String>, extension, extensions)
86 response << *extension << "\r\n";
87
88 response << ios::Flush;
89 }
90 else if (request.method_ == _B("MEDIA"))
91 {
92 // XXX: implement
93 }
94 else
95 waf::Server::Process(request, response);
96 }

Properties

Name Value
svn:eol-style native
svn:keywords Id