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

Comparing GoogleTron/GoogleTron.cpp (file contents):
Revision 672 by douglas, 2006-03-02T17:47:49-08:00 vs.
Revision 680 by douglas, 2006-03-06T00:40:40-08:00

# Line 6 | Line 6
6  
7   #include <cxx/standard.hh>
8  
9 + #include <api/exename.hpp>
10 + #include <api/pcre/regex.hpp>
11 + #include <api/process.hpp>
12   #include <app/simple.hpp>
13 + #include <hop/bind.hpp>
14 + #include <xml/textwriter.hpp>
15 +
16 + #include "GoogleTron.hpp"
17 + #include "Sleep.hpp"
18 + #include "Zlib/GzipWriter.hpp"
19  
20   int Main(const app::Options &options)
21   {
22 +        cse::String sitemap(_B("sitemap.gz"));
23 +
24 +        api::Pcre::RegEx sitemap_(_B("^-sitemap=(.+)$"));
25 +
26 +        _foreach (const app::ArgumentList, arg, app::GetArguments())
27 +        {
28 +                api::Pcre::RegEx::Match match;
29 +
30 +                if (match = sitemap_(*arg))
31 +                        sitemap = match[1];
32 +                else
33 +                {
34 +                        api::Cout << _B("Usage: ") << api::GetExecutablePath().GetName() << _B(" [-sitemap=sitemap]") << ios::NewLine;
35 +
36 +                        return 1;
37 +                }
38 +        }
39 +
40 +        GoogleTron tron(sitemap);
41 +
42 +        return 0;
43 + }
44 +
45 + GoogleTron::GoogleTron(const cse::String &sitemap) : working(true), sitemap(sitemap), output(new _H<api::Thread>(hop::BindAll(&GoogleTron::Output, this)))
46 + {
47 +        // XXX: start some threads
48 + }
49 +
50 + GoogleTron::~GoogleTron()
51 + {
52 +        // XXX: wait on threads
53 +        
54 +        working = false;
55 +
56 +        output->Join();
57 + }
58 +
59 + int GoogleTron::Output()
60 + {
61 +        _S<Zlib::GzipWriter> gzip(sitemap);
62 +        _S<xml::TextWriter> writer(gzip);
63 +        xml::ScopeElement urlset(writer, _B("urlset"));
64 +
65 +        writer.SetAttribute(_B("xmlns"), _B("http://www.google.com/schemas/sitemap/0.84"));
66 +        writer.SetAttribute(_B("xmlns:xsi"), _B("http://www.w3.org/2001/XMLSchema-instance"));
67 +        writer.SetAttribute(_B("xsi:schemaLocation"), _B("http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"));
68 +
69 +        do
70 +        {
71 +                Sleep();
72 +
73 +                _synchronized (queueLock)
74 +                        if (queue.size())
75 +                        {
76 +                                xml::ScopeElement url_(writer, _B("url"));
77 +                                const Url &url(queue.front());
78 +
79 +                                {
80 +                                        xml::ScopeElement loc(writer, _B("loc"));
81 +
82 +                                        writer.OutputText(url.GetLocation());
83 +                                }
84 +
85 +                                {
86 +                                        xml::ScopeElement lastmod(writer, _B("lastmod"));
87 +
88 +                                        writer.OutputText(url.GetModified());
89 +                                }
90 +
91 +                                {
92 +                                        xml::ScopeElement changefreq(writer, _B("changefreq"));
93 +
94 +                                        writer.OutputText(url.GetFrequency());
95 +                                }
96 +
97 +                                {
98 +                                        xml::ScopeElement priority(writer, _B("priority"));
99 +
100 +                                        writer.OutputText(url.GetPriority());
101 +                                }
102 +
103 +                                queue.pop();
104 +                        }
105 +        }
106 +        while (working);
107 +
108          return 0;
109   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines