]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/driver.cpp
Fix critical block logic
[r2c2.git] / source / libr2c2 / driver.cpp
index a587b962d230ed021bfbda24f12a133a370b667f..6fbef93e1f13be64a90afcf3fb5a0037d11fe04a 100644 (file)
@@ -1,17 +1,12 @@
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2010  Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
-#include <msp/core/except.h>
+#include <msp/strings/utils.h>
+#include "arducontrol.h"
 #include "centralstation.h"
 #include "driver.h"
 #include "dummy.h"
 #include "intellibox.h"
 
 using namespace std;
+using namespace Msp;
 
 namespace R2C2 {
 
@@ -28,10 +23,34 @@ Driver *Driver::create(const string &str)
                return new Intellibox(params);
        else if(type=="cs" || type=="centralstation")
                return new CentralStation(params);
+       else if(type=="ac" || type=="arducontrol")
+               return new ArduControl(params);
        else if(type=="dummy")
-               return new Dummy;
+               return new Dummy(params);
+
+       throw invalid_argument("Driver::create");
+}
+
 
-       throw Msp::InvalidParameterValue("Unknown driver");
+Driver::Options::Options(const string &optstr)
+{
+       vector<string> parts = split(optstr, ':');
+       for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+       {
+               string::size_type equals = i->find('=');
+               if(equals==0)
+                       throw invalid_argument("Driver::Options::Options");
+
+               if(equals==string::npos)
+                       set(string(), *i);
+               else
+                       set(i->substr(0, equals), i->substr(equals+1));
+       }
+}
+
+void Driver::Options::set(const string &key, const string &value)
+{
+       opts[key] = value;
 }
 
 } // namespace R2C2