[Debtags-commits] [svn] r1913 - in daemon: . src

Enrico Zini enrico at costa.debian.org
Sun Sep 17 13:44:16 UTC 2006


Author: enrico
Date: Sun Sep 17 13:44:16 2006
New Revision: 1913

Modified:
   daemon/   (props changed)
   daemon/src/debtagsd.cpp
Log:
 r3341 at viaza:  enrico | 2006-09-17 15:43:27 +0200
 Added first bits of tagcoll
 


Modified: daemon/src/debtagsd.cpp
==============================================================================
--- daemon/src/debtagsd.cpp	(original)
+++ daemon/src/debtagsd.cpp	Sun Sep 17 13:44:16 2006
@@ -8,7 +8,11 @@
 #include <wibble/sys/childprocess.h>
 #include <wibble/sys/process.h>
 
+#include <tagcoll/coll/fast.h>
+#include <tagcoll/TextFormat.h>
+
 #include <iostream>
+#include <set>
 
 #include "lib/SignalCatcher.h"
 
@@ -187,6 +191,30 @@
 	}
 };
 
+std::set<std::string> parseTagset(const std::string& str)
+{
+	std::set<std::string> res;
+	size_t beg = 0;
+	size_t end = 0;
+	while (true)
+	{
+		//cerr << "Str: -" << str << "- " << beg << "-" << end << endl;
+		end = str.find(" ", beg);
+		if (end == string::npos)
+		{
+			if (beg != str.size())
+				res.insert(str.substr(beg));
+			break;
+		}
+		else
+		{
+			if (end != beg)
+				res.insert(str.substr(beg, end-beg));
+			beg = end + 1;
+		}
+	}
+	return res;
+}
 
 class Debtagsd : public wibble::sys::ChildProcess
 {
@@ -199,26 +227,51 @@
 	bool detach;
 
 	ostream& log;
+
+	tagcoll::Fast<string, string> coll;
 	
 	void handleConnection(Connection& conn)
 	{
+		using namespace std;
 		try {
 			// Read a line from fd
 			string line = conn.readline();
 			log << "Got line " << line << endl;
+			//conn.write("Hello " + line + "\n");
 
 			// compute output
+			size_t pos = line.find(" ");
+			if (pos == string::npos)
+				return;
+			string cmd = line.substr(0, pos);
+			line = line.substr(pos + 1);
 
+			if (cmd == "PKGS")
+			{
+				set<string> tags = parseTagset(line);
+				for (set<string>::const_iterator i = tags.begin();
+						i != tags.end(); ++i)
+				{
+					//cerr << "Print " << *i << endl;
+					conn.write(*i + "\n");
+				}
+			}
+			else
+				conn.write("Lippocippo\n");
 
 			// write output to fd
-			conn.write("Hello " + line + "\n");
+			//conn.write("Hello " + line + "\n");
 		} catch (std::exception& e) {
 			log << e.what() << endl;
 		}
 	}
 	
 public:
-	Debtagsd(ostream& log, bool detach) : log(log), detach(detach) {}
+	Debtagsd(ostream& log, bool detach) : log(log), detach(detach)
+	{
+		input::Stdio input("/var/lib/debtags/package-tags");
+		tagcoll::textformat::parse(input, tagcoll::inserter(coll));
+	}
 #if 0
 	Stated(MainState& state, const string& socket, bool detach, bool createPidfile) throw ()
 		: state(state), socket(socket), detach(detach), createPidfile(createPidfile) {}
@@ -234,7 +287,7 @@
 
 #if 0
 			// Setup and create the pidfile
-			Pidfile pidfile("stated");
+			Pidfile pidfile("debtagsd");
 			if (createPidfile)
 				pidfile.takeover();
 #endif
@@ -247,9 +300,6 @@
 			// TODO: if needed, change process privileges
 
 #if 0
-			// Create main communication queue
-			SyncQueue<Message> queue;
-
 			// Install signal catcher thread
 			SigHandler handler(queue);
 			int handled_signals[] = { SIGTERM, SIGQUIT, SIGHUP, SIGUSR1 };
@@ -421,4 +471,7 @@
 	}
 }
 
+#include <tagcoll/TextFormat.tcc>
+
+
 // vim:set ts=4 sw=4:



More information about the Debtags-commits mailing list