ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/GoogleTron/GoogleTron.cpp
Revision: 681
Committed: 2006-03-06T02:00:10-08:00 (19 years, 3 months ago) by douglas
File size: 2183 byte(s)
Log Message:
Stackallocate!

File Contents

# User Rev Content
1 douglas 672 // Google Tron
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #include <cxx/standard.hh>
8    
9 douglas 679 #include <api/exename.hpp>
10     #include <api/pcre/regex.hpp>
11 douglas 673 #include <api/process.hpp>
12 douglas 672 #include <app/simple.hpp>
13 douglas 680 #include <hop/bind.hpp>
14 douglas 673 #include <xml/textwriter.hpp>
15 douglas 672
16 douglas 676 #include "GoogleTron.hpp"
17 douglas 677 #include "Sleep.hpp"
18 douglas 680 #include "Zlib/GzipWriter.hpp"
19 douglas 674
20 douglas 672 int Main(const app::Options &options)
21     {
22 douglas 679 cse::String sitemap(_B("sitemap.gz"));
23 douglas 676
24 douglas 679 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 douglas 676 return 0;
43     }
44    
45 douglas 681 GoogleTron::GoogleTron(const cse::String &sitemap) : working(true), sitemap(sitemap), output(hop::BindAll(&GoogleTron::Output, this))
46 douglas 676 {
47 douglas 677 // XXX: start some threads
48 douglas 676 }
49    
50     GoogleTron::~GoogleTron()
51     {
52 douglas 681 threads.Join();
53    
54 douglas 677 working = false;
55    
56 douglas 681 output.Join();
57 douglas 676 }
58    
59     int GoogleTron::Output()
60     {
61 douglas 680 _S<Zlib::GzipWriter> gzip(sitemap);
62 douglas 674 _S<xml::TextWriter> writer(gzip);
63 douglas 673 xml::ScopeElement urlset(writer, _B("urlset"));
64    
65     writer.SetAttribute(_B("xmlns"), _B("http://www.google.com/schemas/sitemap/0.84"));
66 douglas 679 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 douglas 673
69 douglas 677 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 douglas 672 return 0;
109     }

Properties

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