ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/DecentralizedMedia/DecentralizedMedia.cpp
(Generate patch)

Comparing DecentralizedMedia/DecentralizedMedia.cpp (file contents):
Revision 464 by douglas, 2005-06-07T05:40:41-07:00 vs.
Revision 476 by douglas, 2005-06-08T13:41:10-07:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 < #include <iostream>
7 > #include <menes/standard.hh>
8  
9 < #include "BeepRemote.hpp"
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 < int main(int argc, char* argv[])
16 > #include "DecentralizedMedia.hpp"
17 >
18 > int Main(const app::Options& options)
19   {
20 <        std::vector<std::string> list;
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 <        for (int index(1); index != argc; ++index)
34 <                list.push_back(argv[index]);
33 >        if (extensions.IsEmpty())
34 >                extensions.InsertLast(_B("mp3"));
35  
36 <        BeepRemote bmp;
36 >        DecentralizedMedia media(extensions, locals);
37  
38 <        bmp.PlaylistAdd(list);
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 +                        if (extension != _set.Begin())
52 +                                args.InsertLast(_B("-or"));
53 +
54 +                        args.InsertLast(_B("-name"));
55 +                        args.InsertLast(_S<ios::String>() << _B("*.") << *extension);
56 +                }
57 +
58 +                _H<api::Process> find(new api::Process(_B("/usr/bin/find"), args));
59 +                ext::String file;
60 +
61 +                while (ios::ReadLine(*find->GetReader(), file))
62 +                        /*media.Insert(file)*/;
63 +
64 +                find->Join();
65 +        }
66 +
67 +        AddPort(6996);
68 + }
69 +
70 + DecentralizedMedia::~DecentralizedMedia()
71 + {
72 +        if (!process.IsEmpty())
73 +        {
74 +                _H<api::Thread> thread(new api::Thread(etl::BindAll(&DecentralizedMedia::Destroy, this)));
75 +
76 +                bmp.Quit();
77 +
78 +                thread->Join();
79 +        }
80 + }
81 +
82 + void DecentralizedMedia::Process(const net::Http::Request& request, net::Http::Response& response)
83 + {
84 +        if (request.method_ == _B("EXTENSIONS"))
85 +        {
86 +                response.SetStatus(200);
87 +
88 +                _foreach (const _L<ext::String>, extension, extensions)
89 +                        response << *extension << ios::NewLineNoFlush;
90 +        }
91 +        else if (request.method_ == _B("MEDIA"))
92 +        {
93 +                // XXX: implement
94 +        }
95 +        else
96 +                waf::Server::Process(request, response);
97 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines