Xcos MVC: implement pin / pout / pein / peout 39/14939/5
Clément DAVID [Wed, 23 Jul 2014 11:12:41 +0000 (13:12 +0200)]
 * Controller uses ctor / dstor to ease future lock / transaction
 * GraphicsAdapter implements complex port management as a sample

Change-Id: Ic9e5d0e320ace0957abb583e6aff0f9304feb31c

13 files changed:
scilab/modules/scicos/includes/Controller.hxx
scilab/modules/scicos/includes/utilities.hxx
scilab/modules/scicos/sci_gateway/cpp/sci_scicos_new.cpp
scilab/modules/scicos/src/cpp/Controller.cpp
scilab/modules/scicos/src/cpp/LoggerView.cpp
scilab/modules/scicos/src/cpp/Model_getObjectProperties.cpp
scilab/modules/scicos/src/cpp/Model_setObjectProperties.cpp
scilab/modules/scicos/src/cpp/model/Block.hxx
scilab/modules/scicos/src/cpp/model/Port.hxx
scilab/modules/scicos/src/cpp/view_scilab/BaseAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/BlockAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/DiagramAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/GraphicsAdapter.cpp

index 87c3ab0..858fb61 100644 (file)
@@ -31,11 +31,13 @@ namespace org_scilab_modules_scicos
 class Controller
 {
 public:
-    static Controller* get_instance();
-    static void delete_instance();
+    Controller();
+    ~Controller();
 
-    void register_view(View* v);
-    void unregister_view(View* v);
+    static void delete_all_instances();
+
+    static void register_view(View* v);
+    static void unregister_view(View* v);
 
     ScicosID createObject(kind_t k);
     void deleteObject(ScicosID uid);
@@ -43,59 +45,49 @@ public:
     model::BaseObject* getObject(ScicosID uid);
     update_status_t setObject(model::BaseObject* o);
 
-    bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, double& v);
-    bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, int& v);
-    bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, bool& v);
-    bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::string& v);
-    bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, ScicosID& v);
-    bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector<double>& v);
-    bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector<int>& v);
-    bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector< std::string >& v);
-    bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector<ScicosID>& v);
-
-    update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, double v);
-    update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, int v);
-    update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, bool v);
-    update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, ScicosID v);
-    update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::string v);
-    update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector<double>& v);
-    update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector<int>& v);
-    update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector< std::string >& v);
-    update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector<ScicosID>& v);
+    template<typename T>
+    inline bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, T& v) const
+    {
+        return _instance->model.getObjectProperty(uid, k, p, v);
+    };
 
-private:
-    void dispatch(update_status_t status, ScicosID uid, kind_t k, object_properties_t p)
+    template<typename T>
+    inline update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, T v)
     {
+        update_status_t status = _instance->model.setObjectProperty(uid, k, p, v);
         if (status == SUCCESS)
         {
-            for (view_set_t::iterator iter = allViews.begin(); iter != allViews.end(); iter++)
+            for (view_set_t::iterator iter = _instance->allViews.begin(); iter != _instance->allViews.end(); iter++)
             {
                 (*iter)->propertyUpdated(uid, k, p);
             }
         }
-        for (view_set_t::iterator iter = allViews.begin(); iter != allViews.end(); iter++)
+        for (view_set_t::iterator iter = _instance->allViews.begin(); iter != _instance->allViews.end(); iter++)
         {
             (*iter)->propertyUpdated(uid, k, p, status);
         }
-    }
-
-    template<typename T>
-    update_status_t generic_setObjectProp(ScicosID uid, kind_t k, object_properties_t p, T v)
-    {
-        update_status_t status = model.setObjectProperty(uid, k, p, v);
-        dispatch(status, uid, k, p);
         return status;
     }
 
 private:
-    static Controller* _instance;
 
-    Model model;
     typedef std::vector<View*> view_set_t;
-    view_set_t allViews;
 
-    Controller();
-    ~Controller();
+    /**
+     * Shared data through all instance of the controllers
+     */
+    struct SharedData
+    {
+        Model model;
+        view_set_t allViews;
+    };
+
+    /**
+     * Shared instance of the data
+     *
+     * This will be allocated on-demand be Controller::get_instance()
+     */
+    static SharedData* _instance;
 };
 
 } /* namespace org_scilab_modules_scicos */
index 6823958..5ffda49 100644 (file)
@@ -90,7 +90,7 @@ enum object_properties_t
     EVENT_INPUTS,       //!< model::Block::ein value
     EVENT_OUTPUTS,      //!< model::Block::eout value
     PARENT_BLOCK,       //!< model::Block::parentBlock value
-    CHILDREN,           //!< model::Block::children value
+    CHILDREN,           //!< model::Block::children for superblocks or model::Diagram::children value
     PORT_REFERENCE,     //!< model::Block::portReference value
     DESTINATION_PORT,   //!< model::Link::destinationPort value
     SOURCE_PORT,        //!< model::Link::sourcePort value
index f29ae4f..c338ed2 100644 (file)
@@ -53,15 +53,15 @@ static const std::string funame = "scicos_new";
 template<class Adaptor, class Adaptee>
 Adaptor* alloc_and_set(kind_t k, types::String* type_name, types::typed_list &in)
 {
-    Controller* controller = Controller::get_instance();
-    ScicosID o = controller->createObject(k);
-    Adaptor* adaptor = new Adaptor(static_cast<Adaptee*>(controller->getObject(o)));
+    Controller controller = Controller();
+    ScicosID o = controller.createObject(k);
+    Adaptor* adaptor = new Adaptor(static_cast<Adaptee*>(controller.getObject(o)));
 
     // the first header entry is the type
     for (int i = 1; i < in.size(); i++)
     {
         std::wstring name = type_name->get(i);
-        if (!adaptor->setProperty(name, in[i]))
+        if (!adaptor->setProperty(name, in[i], controller))
         {
             Scierror(999, _("%s: Wrong value for input argument #%d: unable to set \"%ls\".\n"), funame.data(), i, name.data());
             delete adaptor;
index d6a8322..76520b8 100644 (file)
 namespace org_scilab_modules_scicos
 {
 
-Controller* Controller::_instance = 0;
+Controller::SharedData* Controller::_instance = 0;
 
-Controller* Controller::get_instance()
-{
-    if (_instance == 0)
-    {
-        _instance = new Controller();
-    }
-    return _instance;
-}
-
-void Controller::delete_instance()
+void Controller::delete_all_instances()
 {
     if (_instance != 0)
     {
+        for (view_set_t::iterator iter = _instance->allViews.begin(); iter != _instance->allViews.end(); iter++)
+        {
+            delete *iter;
+        }
+        _instance->allViews.clear();
+
         delete _instance;
     }
 }
 
 Controller::Controller()
 {
-    LoggerView* v = new LoggerView();
+    if (_instance == 0)
+    {
+        _instance = new SharedData();
 
-    register_view(v);
+        LoggerView* v = new LoggerView();
+        register_view(v);
+    }
 }
 
 Controller::~Controller()
 {
-    for (view_set_t::iterator iter = allViews.begin(); iter != allViews.end(); iter++)
-    {
-        delete *iter;
-    }
-    allViews.clear();
 }
 
 void Controller::register_view(View* v)
 {
-    allViews.push_back(v);
+    _instance->allViews.push_back(v);
 }
 
 void Controller::unregister_view(View* v)
 {
-    view_set_t::iterator it = std::find(allViews.begin(), allViews.end(), v);
-    if (it != allViews.end())
+    view_set_t::iterator it = std::find(_instance->allViews.begin(), _instance->allViews.end(), v);
+    if (it != _instance->allViews.end())
     {
-        allViews.erase(it);
+        _instance->allViews.erase(it);
     }
 }
 
 ScicosID Controller::createObject(kind_t k)
 {
-    ScicosID id = model.createObject(k);
+    ScicosID id = _instance->model.createObject(k);
 
-    for (view_set_t::iterator iter = allViews.begin(); iter != allViews.end(); iter++)
+    for (view_set_t::iterator iter = _instance->allViews.begin(); iter != _instance->allViews.end(); iter++)
     {
         (*iter)->objectCreated(id, k);
     }
@@ -82,9 +78,9 @@ ScicosID Controller::createObject(kind_t k)
 
 void Controller::deleteObject(ScicosID uid)
 {
-    model.deleteObject(uid);
+    _instance->model.deleteObject(uid);
 
-    for (view_set_t::iterator iter = allViews.begin(); iter != allViews.end(); iter++)
+    for (view_set_t::iterator iter = _instance->allViews.begin(); iter != _instance->allViews.end(); iter++)
     {
         (*iter)->objectDeleted(uid);
     }
@@ -92,16 +88,16 @@ void Controller::deleteObject(ScicosID uid)
 
 model::BaseObject* Controller::getObject(ScicosID uid)
 {
-    return model.getObject(uid);
+    return _instance->model.getObject(uid);
 }
 
 update_status_t Controller::setObject(model::BaseObject* o)
 {
-    update_status_t status = model.setObject(o);
+    update_status_t status = _instance->model.setObject(o);
 
     if (status == SUCCESS)
     {
-        for (view_set_t::iterator iter = allViews.begin(); iter != allViews.end(); iter++)
+        for (view_set_t::iterator iter = _instance->allViews.begin(); iter != _instance->allViews.end(); iter++)
         {
             (*iter)->objectUpdated(o->id(), o->kind());
         }
@@ -109,102 +105,4 @@ update_status_t Controller::setObject(model::BaseObject* o)
     return status;
 }
 
-bool Controller::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p,
-                                   double& v)
-{
-    return model.getObjectProperty(uid, k, p, v);
-}
-
-bool Controller::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, int& v)
-{
-    return model.getObjectProperty(uid, k, p, v);
-}
-
-bool Controller::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, bool& v)
-{
-    return model.getObjectProperty(uid, k, p, v);
-}
-
-bool Controller::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p,
-                                   std::string& v)
-{
-    return model.getObjectProperty(uid, k, p, v);
-}
-
-bool Controller::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p,
-                                   ScicosID& v)
-{
-    return model.getObjectProperty(uid, k, p, v);
-}
-
-bool Controller::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector<double>& v)
-{
-    return model.getObjectProperty(uid, k, p, v);
-}
-
-bool Controller::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector<int>& v)
-{
-    return model.getObjectProperty(uid, k, p, v);
-}
-
-bool Controller::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector<std::string>& v)
-{
-    return model.getObjectProperty(uid, k, p, v);
-}
-
-bool Controller::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector<ScicosID>& v)
-{
-    return model.getObjectProperty(uid, k, p, v);
-}
-
-update_status_t Controller::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p,
-        double v)
-{
-    return generic_setObjectProp<double>(uid, k, p, v);
-}
-
-update_status_t Controller::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p,
-        int v)
-{
-    return generic_setObjectProp<int>(uid, k, p, v);
-}
-
-update_status_t Controller::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p,
-        bool v)
-{
-    return generic_setObjectProp<bool>(uid, k, p, v);
-}
-
-update_status_t Controller::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p,
-        ScicosID v)
-{
-    return generic_setObjectProp<ScicosID>(uid, k, p, v);
-}
-
-update_status_t Controller::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p,
-        std::string v)
-{
-    return generic_setObjectProp<std::string>(uid, k, p, v);
-}
-
-update_status_t Controller::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector<double>& v)
-{
-    return generic_setObjectProp< std::vector<double> >(uid, k, p, v);
-}
-
-update_status_t Controller::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector<int>& v)
-{
-    return generic_setObjectProp< std::vector<int> >(uid, k, p, v);
-}
-
-update_status_t Controller::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector< std::string >& v)
-{
-    return generic_setObjectProp< std::vector<std::string> >(uid, k, p, v);
-}
-
-update_status_t Controller::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector<ScicosID>& v)
-{
-    return generic_setObjectProp< std::vector<ScicosID> >(uid, k, p, v);
-}
-
 } /* namespace org_scilab_modules_scicos */
index ee5a83f..4d15fa5 100644 (file)
@@ -101,6 +101,12 @@ static std::ostream& operator<<(std::ostream& os, object_properties_t p)
         case SIM_SCHEDULE:
             os << "SIM_SCHEDULE";
             break;
+        case ANGLE:
+            os << "ANGLE";
+            break;
+        case EXPRS:
+            os << "EXPRS";
+            break;
         case INPUTS:
             os << "INPUTS";
             break;
@@ -149,7 +155,6 @@ static std::ostream& operator<<(std::ostream& os, object_properties_t p)
     }
     return os;
 }
-;
 
 static const bool USE_SCILAB_WRITE = true;
 
index cd362b5..b6b75e0 100644 (file)
@@ -273,6 +273,12 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, Sci
             case PARENT_DIAGRAM:
                 v = o->getParentDiagram();
                 return true;
+            case SOURCE_PORT:
+                v = o->getSourcePort();
+                return true;
+            case DESTINATION_PORT:
+                v = o->getDestinationPort();
+                return true;
             default:
                 break;
         }
@@ -280,6 +286,14 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, Sci
     else if (k == PORT)
     {
         model::Port* o = static_cast<model::Port*>(getObject(uid));
+        switch (p)
+        {
+            case CONNECTED_SIGNALS:
+                v = o->getConnectedSignals().front();
+                return true;
+            default:
+                break;
+        }
     }
     else
     {
@@ -458,10 +472,16 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
         switch (p)
         {
             case INPUTS:
-                v = o->getIn();
+                o->getIn(v);
                 return true;
             case OUTPUTS:
-                v = o->getOut();
+                o->getOut(v);
+                return true;
+            case EVENT_INPUTS:
+                o->getEin(v);
+                return true;
+            case EVENT_OUTPUTS:
+                o->getEout(v);
                 return true;
             default:
                 break;
@@ -472,6 +492,9 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
         model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
         switch (p)
         {
+            case CHILDREN:
+                v = o->getChildren();
+                return true;
             default:
                 break;
         }
@@ -490,6 +513,9 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
         model::Port* o = static_cast<model::Port*>(getObject(uid));
         switch (p)
         {
+            case CONNECTED_SIGNALS:
+                v = o->getConnectedSignals();
+                return true;
             default:
                 break;
         }
index 5215849..f3649e1 100644 (file)
@@ -459,19 +459,13 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
         switch (p)
         {
             case INPUTS:
-                if (v.size() > o->in.size()); // FIXME: Input port creation
-                if (v.size() < o->in.size()); // FIXME: Input port deletion
-                {
-                    o->setIn(v);
-                }
-                return SUCCESS;
+                return o->setIn(v);
             case OUTPUTS:
-                if (v.size() > o->out.size()); // FIXME: Output port creation
-                if (v.size() < o->out.size()); // FIXME: Output port deletion
-                {
-                    o->setOut(v);
-                }
-                return SUCCESS;
+                return o->setOut(v);
+            case EVENT_INPUTS:
+                return o->setEin(v);
+            case EVENT_OUTPUTS:
+                return o->setEout(v);
             default:
                 break;
         }
index b1579b8..5f33a61 100644 (file)
@@ -134,26 +134,6 @@ private:
         this->children = children;
     }
 
-    const std::vector<ScicosID>& getEin() const
-    {
-        return ein;
-    }
-
-    void setEin(const std::vector<ScicosID>& ein)
-    {
-        this->ein = ein;
-    }
-
-    const std::vector<ScicosID>& getEout() const
-    {
-        return eout;
-    }
-
-    void setEout(const std::vector<ScicosID>& eout)
-    {
-        this->eout = eout;
-    }
-
     void getGeometry(std::vector<double>& v) const
     {
         geometry.fill(v);
@@ -214,14 +194,19 @@ private:
         return SUCCESS;
     }
 
-    const std::vector<ScicosID>& getIn() const
+    void getIn(std::vector<ScicosID>& v) const
     {
-        return in;
+        v = in;
     }
 
-    void setIn(const std::vector<ScicosID>& in)
+    update_status_t setIn(const std::vector<ScicosID>& in)
     {
+        if (in == this->in)
+        {
+            return NO_CHANGES;
+        }
         this->in = in;
+        return SUCCESS;
     }
 
     const std::string& getInterfaceFunction() const
@@ -234,14 +219,49 @@ private:
         this->interfaceFunction = interfaceFunction;
     }
 
-    const std::vector<ScicosID>& getOut() const
+    void getOut(std::vector<ScicosID>& v) const
     {
-        return out;
+        v = out;
     }
 
-    void setOut(const std::vector<ScicosID>& out)
+    update_status_t setOut(const std::vector<ScicosID>& out)
     {
+        if (out == this->out)
+        {
+            return NO_CHANGES;
+        }
         this->out = out;
+        return SUCCESS;
+    }
+
+    void getEin(std::vector<ScicosID>& v) const
+    {
+        v = ein;
+    }
+
+    update_status_t setEin(const std::vector<ScicosID>& ein)
+    {
+        if (ein == this->ein)
+        {
+            return NO_CHANGES;
+        }
+        this->ein = ein;
+        return SUCCESS;
+    }
+
+    void getEout(std::vector<ScicosID>& v) const
+    {
+        v = eout;
+    }
+
+    update_status_t setEout(const std::vector<ScicosID>& eout)
+    {
+        if (eout == this->eout)
+        {
+            return NO_CHANGES;
+        }
+        this->eout = eout;
+        return SUCCESS;
     }
 
     const Parameter& getParameter() const
index 8910b9d..1b4b2b8 100644 (file)
@@ -33,8 +33,8 @@ class Port: public BaseObject
     friend class ::org_scilab_modules_scicos::Model;
 
 private:
-    Port() : BaseObject(PORT), dataType(0), sourceBlock(0), kind(UNDEF), portNumber(0) {};
-    Port(const Port& o) : BaseObject(PORT), dataType(o.dataType), sourceBlock(o.sourceBlock), kind(o.kind), portNumber(o.portNumber) {};
+    Port() : BaseObject(PORT), dataType(0), sourceBlock(0), kind(UNDEF) {};
+    Port(const Port& o) : BaseObject(PORT), dataType(o.dataType), sourceBlock(o.sourceBlock), kind(o.kind) {};
     ~Port() {};
 
     const std::vector<ScicosID>& getConnectedSignals() const
@@ -67,16 +67,6 @@ private:
         this->kind = kind;
     }
 
-    unsigned int getPortNumber() const
-    {
-        return portNumber;
-    }
-
-    void setPortNumber(unsigned int portNumber)
-    {
-        this->portNumber = portNumber;
-    }
-
     ScicosID getSourceBlock() const
     {
         return sourceBlock;
@@ -91,7 +81,6 @@ private:
     Datatype* dataType;
     ScicosID sourceBlock;
     portKind kind;
-    unsigned int portNumber;
 
     std::vector<ScicosID> connectedSignals;
 };
index fad0473..4a7b73c 100644 (file)
@@ -37,8 +37,8 @@ template<typename Adaptor>
 struct property
 {
 public:
-    typedef types::InternalType* (*getter_t)(const Adaptor& adaptor);
-    typedef bool (*setter_t)(Adaptor& adaptor, types::InternalType* v);
+    typedef types::InternalType* (*getter_t)(const Adaptor& adaptor, const Controller& controller);
+    typedef bool (*setter_t)(Adaptor& adaptor, types::InternalType* v, Controller& controller);
 
     typedef std::vector< property<Adaptor> > props_t;
     typedef typename props_t::iterator props_t_it;
@@ -104,22 +104,22 @@ public:
         return found != property<Adaptor>::fields.end();
     }
 
-    types::InternalType* getProperty(const std::wstring& _sKey) const
+    types::InternalType* getProperty(const std::wstring& _sKey, Controller controller = Controller()) const
     {
         typename property<Adaptor>::props_t_it found = std::lower_bound(property<Adaptor>::fields.begin(), property<Adaptor>::fields.end(), _sKey);
         if (found != property<Adaptor>::fields.end())
         {
-            return found->get(static_cast<Adaptor*>(this));
+            return found->get(static_cast<Adaptor*>(this), controller);
         }
         return 0;
     }
 
-    bool setProperty(const std::wstring& _sKey, types::InternalType* v)
+    bool setProperty(const std::wstring& _sKey, types::InternalType* v, Controller controller = Controller())
     {
         typename property<Adaptor>::props_t_it found = std::lower_bound(property<Adaptor>::fields.begin(), property<Adaptor>::fields.end(), _sKey);
         if (found != property<Adaptor>::fields.end())
         {
-            return found->set(*static_cast<Adaptor*>(this), v);
+            return found->set(*static_cast<Adaptor*>(this), v, controller);
         }
         return false;
     }
index 3225ede..495d52d 100644 (file)
@@ -36,13 +36,12 @@ namespace view_scilab
 
 struct graphics
 {
-
-    static types::InternalType* get(const BlockAdapter& adaptor)
+    static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
         return new GraphicsAdapter(adaptor.getAdaptee());
     }
 
-    static bool set(BlockAdapter& adaptor, types::InternalType* v)
+    static bool set(BlockAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         if (v->getType() == types::InternalType::ScilabUserType
                 && v->getShortTypeStr() == GraphicsAdapter::getSharedTypeStr())
@@ -57,13 +56,12 @@ struct graphics
 
 struct model
 {
-
-    static types::InternalType* get(const BlockAdapter& adaptor)
+    static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
         return new ModelAdapter(adaptor.getAdaptee());
     }
 
-    static bool set(BlockAdapter& adaptor, types::InternalType* v)
+    static bool set(BlockAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         if (v->getType() == types::InternalType::ScilabUserType
                 && v->getShortTypeStr() == ModelAdapter::getSharedTypeStr())
@@ -78,17 +76,16 @@ struct model
 
 struct gui
 {
-
-    static types::InternalType* get(const BlockAdapter& adaptor)
+    static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
         std::string interface;
         org_scilab_modules_scicos::model::Block* adaptee = adaptor.getAdaptee();
-        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), INTERFACE_FUNCTION, interface);
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), INTERFACE_FUNCTION, interface);
 
         return new types::String(interface.data());
     }
 
-    static bool set(BlockAdapter& adaptor, types::InternalType* v)
+    static bool set(BlockAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         if (v->getType() != types::InternalType::ScilabString)
         {
@@ -107,20 +104,19 @@ struct gui
         FREE(name);
 
         org_scilab_modules_scicos::model::Block* adaptee = adaptor.getAdaptee();
-        Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), INTERFACE_FUNCTION, stName);
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), INTERFACE_FUNCTION, stName);
         return true;
     }
 };
 
 struct doc
 {
-
-    static types::InternalType* get(const BlockAdapter& adaptor)
+    static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
         return adaptor.getDocContent();
     }
 
-    static bool set(BlockAdapter& adaptor, types::InternalType* v)
+    static bool set(BlockAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         adaptor.setDocContent(v->clone());
         return true;
index cc2a3c0..b0bfcfd 100644 (file)
@@ -35,13 +35,13 @@ namespace view_scilab
 struct props
 {
 
-    static types::InternalType* get(const DiagramAdapter& adaptor)
+    static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
     {
 
         return new ParamsAdapter(adaptor.getAdaptee());
     }
 
-    static bool set(DiagramAdapter& adaptor, types::InternalType* v)
+    static bool set(DiagramAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         if (v->getType() == types::InternalType::ScilabUserType
                 && v->getShortTypeStr() == ParamsAdapter::getSharedTypeStr())
@@ -57,13 +57,13 @@ struct props
 struct objs
 {
 
-    static types::InternalType* get(const DiagramAdapter& adaptor)
+    static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
     {
 
         return 0;
     }
 
-    static bool set(DiagramAdapter& adaptor, types::InternalType* v)
+    static bool set(DiagramAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         return false;
     }
@@ -72,7 +72,7 @@ struct objs
 struct version
 {
 
-    static types::InternalType* get(const DiagramAdapter& adaptor)
+    static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
     {
         std::stringstream str;
         str << SCI_VERSION_MAJOR << '.' << SCI_VERSION_MINOR << '.' << SCI_VERSION_MAINTENANCE;
@@ -80,7 +80,7 @@ struct version
         return new types::String(str.str().c_str());
     }
 
-    static bool set(DiagramAdapter& adaptor, types::InternalType* v)
+    static bool set(DiagramAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         //FIXME: handle version upgrade of the whole model
         return true;
@@ -90,12 +90,12 @@ struct version
 struct contrib
 {
 
-    static types::InternalType* get(const DiagramAdapter& adaptor)
+    static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
     {
         return 0;
     }
 
-    static bool set(DiagramAdapter& adaptor, types::InternalType* v)
+    static bool set(DiagramAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         return false;
     }
index 4f93e59..7779adb 100644 (file)
 #include "Controller.hxx"
 #include "GraphicsAdapter.hxx"
 
+extern "C" {
+#include "sci_mem_alloc.h"
+}
+
 namespace org_scilab_modules_scicos
 {
 namespace view_scilab
@@ -29,14 +33,14 @@ namespace view_scilab
 struct orig
 {
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
         double* data;
         types::Double* o = new types::Double(1, 2, &data);
         model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<double> geom;
-        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
 
         data[0] = geom[0];
         data[1] = geom[1];
@@ -44,8 +48,9 @@ struct orig
         return o;
     }
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
+
         if (v->getType() != types::InternalType::ScilabDouble)
         {
             return false;
@@ -59,12 +64,12 @@ struct orig
 
         model::Block* adaptee = adaptor.getAdaptee();
         std::vector<double> geom;
-        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
 
         geom[0] = current->get(0);
         geom[1] = current->get(1);
 
-        Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
         return true;
     }
 };
@@ -72,21 +77,21 @@ struct orig
 struct sz
 {
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
         double* data;
         types::Double* o = new types::Double(1, 2, &data);
         model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<double> geom;
-        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
 
         data[0] = geom[2];
         data[1] = geom[3];
         return o;
     }
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -101,12 +106,12 @@ struct sz
 
         model::Block* adaptee = adaptor.getAdaptee();
         std::vector<double> geom;
-        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
 
         geom[2] = current->get(0);
         geom[3] = current->get(1);
 
-        Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
         return true;
     }
 };
@@ -114,20 +119,20 @@ struct sz
 struct flip
 {
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
         int* data;
         types::Bool* o = new types::Bool(1, 1, &data);
         model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<double> angle;
-        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
 
         data[0] = angle[0];
         return o;
     }
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         if (v->getType() != types::InternalType::ScilabBool)
         {
@@ -142,11 +147,11 @@ struct flip
 
         model::Block* adaptee = adaptor.getAdaptee();
         std::vector<double> angle;
-        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
 
         angle[0] = (current->get(0) == false) ? 0 : 1;
 
-        Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
         return true;
     }
 };
@@ -154,20 +159,20 @@ struct flip
 struct theta
 {
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
         double* data;
         types::Double* o = new types::Double(1, 1, &data);
         model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<double> angle;
-        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
 
         data[0] = angle[1];
         return o;
     }
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -182,11 +187,11 @@ struct theta
 
         model::Block* adaptee = adaptor.getAdaptee();
         std::vector<double> angle;
-        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
 
         angle[1] = current->get(0);
 
-        Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
         return true;
     }
 };
@@ -194,23 +199,23 @@ struct theta
 struct exprs
 {
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
         model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<std::string> exprs;
-        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
 
         types::String* o = new types::String(exprs.size(), 1);
-
         for (size_t i = 0; i < exprs.size(); ++i)
         {
             o->set(i, exprs[i].data());
         }
+
         return o;
     }
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         if (v->getType() == types::InternalType::ScilabString)
         {
@@ -222,22 +227,19 @@ struct exprs
             }
 
             model::Block* adaptee = adaptor.getAdaptee();
-            std::vector<std::string> exprs;
-            Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
-
-            exprs.resize(current->getRows());
-            for (int i = 0; i < exprs.size(); ++i)
+            std::vector<std::string> exprs = std::vector<std::string>(current->getSize());
+            for (size_t i = 0; i < exprs.size(); ++i)
             {
-                exprs[i] = (char*) current->get(i);
+                char* c_str = wide_string_to_UTF8(current->get(i));
+                exprs[i] = std::string(c_str);
+                FREE(c_str);
             }
 
-            Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
+            controller.setObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
             return true;
         }
-
-        if (v->getType() == types::InternalType::ScilabDouble)
+        else if (v->getType() == types::InternalType::ScilabDouble)
         {
-
             types::Double* current = v->getAs<types::Double>();
             if (current->getRows() != 0 || current->getCols() != 0)
             {
@@ -246,144 +248,286 @@ struct exprs
 
             model::Block* adaptee = adaptor.getAdaptee();
             std::vector<std::string> exprs;
-            Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
-
-            exprs.clear();
-
-            Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
+            controller.setObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
             return true;
         }
+        return false;
     }
 };
 
-struct pin
+static types::Double* get_port(const GraphicsAdapter& adaptor, object_properties_t p, const Controller& controller)
 {
+    model::Block* adaptee = adaptor.getAdaptee();
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
-    {
-        model::Block* adaptee = adaptor.getAdaptee();
+    // retrieve the identifiers
+    std::vector<ScicosID> ids;
+    controller.getObjectProperty(adaptee->id(), adaptee->kind(), p, ids);
 
-        std::vector<ScicosID> ids;
-        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), INPUTS, ids);
+    // allocate some space for the return value
+    double* ports;
+    types::Double* o = new types::Double(ids.size(), 1, &ports);
 
-        types::Double* o = new types::Double(ids.size(), 1);
+    // translate identifiers to return values
+    for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++ports)
+    {
+        std::vector<ScicosID> connectedSignals;
 
-        for (size_t i = 0; i < ids.size(); ++i)
-        {
-            o->set(i, ids[i]);
-        }
-        return o;
-    }
+        controller.getObjectProperty(*it, PORT, CONNECTED_SIGNALS, connectedSignals);
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
-    {
-        if (v->getType() != types::InternalType::ScilabDouble)
+        // always return the first connected signals, at scilab level a port can only be connected to one signal at a time.
+        if (connectedSignals.empty())
         {
-            return false;
+            // if the port is not connected returns 0
+            *ports = 0;
         }
+        else
+        {
+            // if the port is connected, return the index of the link in the parent diagram
+            ScicosID link = connectedSignals[0];
 
-        types::Double* current = v->getAs<types::Double>();
+            ScicosID parentDiagram = 0;
+            controller.getObjectProperty(link, LINK, PARENT_DIAGRAM, parentDiagram);
 
-        model::Block* adaptee = adaptor.getAdaptee();
-        std::vector<ScicosID> ids;
-        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), INPUTS, ids);
+            std::vector<ScicosID> children;
+            controller.getObjectProperty(parentDiagram, DIAGRAM, CHILDREN, children);
 
-        ids.resize(current->getSize());
-        for (int i = 0; i < ids.size(); ++i)
-        {
-            ids[i] = current->get(i);
+            std::vector<ScicosID>::iterator it = std::find(children.begin(), children.end(), link);
+            if (it != children.end())
+            {
+                int index = std::distance(children.begin(), it);
+                *ports = index;
+            }
+            else
+            {
+                *ports = 0;
+            }
         }
 
-        Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), INPUTS, ids);
-        return true;
+        ports++;
     }
-};
 
-struct pout
+    return o;
+}
+
+static bool set_port(const GraphicsAdapter& adaptor, types::InternalType* v, object_properties_t p, Controller& controller)
 {
+    model::Block* adaptee = adaptor.getAdaptee();
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    if (v->getType() != types::InternalType::ScilabDouble)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        return false;
+    }
+    types::Double* value = v->getAs<types::Double>();
 
-        std::vector<ScicosID> ids;
-        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), OUTPUTS, ids);
+    ScicosID parentDiagram;
+    controller.getObjectProperty(adaptee->id(), BLOCK, PARENT_DIAGRAM, parentDiagram);
 
-        types::Double* o = new types::Double(ids.size(), 1);
+    std::vector<ScicosID> children;
+    if (parentDiagram != 0)
+    {
+        controller.getObjectProperty(parentDiagram, DIAGRAM, CHILDREN, children);
+    }
 
-        for (size_t i = 0; i < ids.size(); ++i)
+    std::vector<int> newPorts = std::vector<int>(value->getSize());
+    double* d = value->getReal();
+    for (std::vector<int>::iterator it = newPorts.begin(); it != newPorts.end(); ++it, ++d)
+    {
+        if (0 > *d && *d >= children.size())
         {
-            o->set(i, ids[i]);
+            return false;
         }
-        return o;
+
+        *it = (int) * d;
     }
+    std::vector<ScicosID> deletedObjects;
+
+    // retrieve old data
+    std::vector<ScicosID> oldPorts;
+    controller.getObjectProperty(adaptee->id(), adaptee->kind(), p, oldPorts);
+    std::vector<ScicosID> previousPorts = oldPorts;
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    // updated ports
+    while (!oldPorts.empty() || !newPorts.empty())
     {
-        if (v->getType() != types::InternalType::ScilabDouble)
+        ScicosID oldPort = oldPorts.back();
+        oldPorts.pop_back();
+        int newPort = newPorts.back();
+        newPorts.pop_back();
+
+        ScicosID oldSignal;
+        controller.getObjectProperty(oldPort, PORT, CONNECTED_SIGNALS, oldSignal);
+        ScicosID newSignal = children[newPort];
+
+        if (oldSignal != newSignal)
         {
-            return false;
+            // disconnect the old link
+            ScicosID oldSignalSrc;
+            controller.getObjectProperty(oldSignal, LINK, SOURCE_PORT, oldSignalSrc);
+            ScicosID oldSignalDst;
+            controller.getObjectProperty(oldSignal, LINK, DESTINATION_PORT, oldSignalDst);
+
+            ScicosID unconnected = 0;
+            if (oldSignalSrc == oldPort)
+            {
+                controller.setObjectProperty(oldSignalDst, PORT, CONNECTED_SIGNALS, unconnected);
+            }
+            else // oldSignalDst == oldPort
+            {
+                controller.setObjectProperty(oldSignalSrc, PORT, CONNECTED_SIGNALS, unconnected);
+            }
+            // Link de-association is not performed as the link will be removed
+
+            // connect the new link
+            controller.setObjectProperty(newSignal, LINK, SOURCE_PORT, 0);
+            controller.setObjectProperty(oldPort, PORT, CONNECTED_SIGNALS, newSignal);
+
+            children.erase(std::find(children.begin(), children.end(), oldSignal));
+            deletedObjects.push_back(oldSignal);
         }
+    }
 
-        types::Double* current = v->getAs<types::Double>();
+    // removed ports
+    if (!oldPorts.empty())
+    {
+        previousPorts.erase(previousPorts.begin() + oldPorts.size(), previousPorts.end());
 
-        model::Block* adaptee = adaptor.getAdaptee();
-        std::vector<ScicosID> ids;
-        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), OUTPUTS, ids);
+        while (!oldPorts.empty())
+        {
+            ScicosID oldPort = oldPorts.back();
+            oldPorts.pop_back();
+
+            ScicosID signal;
+            controller.getObjectProperty(oldPort, PORT, CONNECTED_SIGNALS, signal);
+            if (signal != 0)
+            {
+                // the link is connected, disconnect the other side
+                ScicosID oldSignalSrc;
+                controller.getObjectProperty(signal, LINK, SOURCE_PORT, oldSignalSrc);
+                ScicosID oldSignalDst;
+                controller.getObjectProperty(signal, LINK, DESTINATION_PORT, oldSignalDst);
+
+                ScicosID unconnected = 0;
+                if (oldSignalSrc == oldPort)
+                {
+                    controller.setObjectProperty(oldSignalDst, PORT, CONNECTED_SIGNALS, unconnected);
+                }
+                else     // oldSignalDst == oldPort
+                {
+                    controller.setObjectProperty(oldSignalSrc, PORT, CONNECTED_SIGNALS, unconnected);
+                }
+
+                children.erase(std::find(children.begin(), children.end(), signal));
+                deletedObjects.push_back(signal);
+            }
+
+            deletedObjects.push_back(oldPort);
+        }
 
-        ids.resize(current->getSize());
-        for (int i = 0; i < ids.size(); ++i)
+        controller.setObjectProperty(adaptee->id(), BLOCK, p, previousPorts);
+    }
+
+    // added ports
+    if (!newPorts.empty())
+    {
+        while (!newPorts.empty())
         {
-            ids[i] = current->get(i);
+            int newPort = newPorts.back();
+            oldPorts.pop_back();
+
+            ScicosID id = controller.createObject(PORT);
+            controller.setObjectProperty(id, PORT, SOURCE_BLOCK, adaptee->id());
+            // set the connected signal if applicable
+            if (newPort != 0)
+            {
+                ScicosID signal = children[newPort];
+                controller.setObjectProperty(id, PORT, CONNECTED_SIGNALS, signal);
+            }
+
+            previousPorts.push_back(id);
         }
 
-        Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), OUTPUTS, ids);
-        return true;
+        controller.setObjectProperty(adaptee->id(), BLOCK, p, previousPorts);
+    }
+
+    // remove objects from the model after de-association
+    if (parentDiagram != 0)
+    {
+        controller.setObjectProperty(parentDiagram, DIAGRAM, CHILDREN, children);
+    }
+    for (std::vector<ScicosID>::iterator it = deletedObjects.begin(); it != deletedObjects.end(); ++it)
+    {
+        controller.deleteObject(*it);
+    }
+
+    return true;
+}
+
+struct pin
+{
+
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
+    {
+        return get_port(adaptor, INPUTS, controller);
+    }
+
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+        return set_port(adaptor, v, INPUTS, controller);
+    }
+};
+
+struct pout
+{
+
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
+    {
+        return get_port(adaptor, OUTPUTS, controller);
+    }
+
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+        return set_port(adaptor, v, OUTPUTS, controller);
     }
 };
 
 struct pein
 {
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        //FIXME: implement
-        return 0;
+        return get_port(adaptor, EVENT_INPUTS, controller);
     }
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        //FIXME: implement
-        return false;
+        return set_port(adaptor, v, EVENT_INPUTS, controller);
     }
 };
 
 struct peout
 {
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        //FIXME: implement
-        return 0;
+        return get_port(adaptor, EVENT_OUTPUTS, controller);
     }
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        //FIXME: implement
-        return false;
+        return set_port(adaptor, v, EVENT_OUTPUTS, controller);
     }
 };
 
 struct in_implicit
 {
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
         //FIXME: implement
         return 0;
     }
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         //FIXME: implement
         return false;
@@ -393,13 +537,13 @@ struct in_implicit
 struct out_implicit
 {
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
         //FIXME: implement
         return 0;
     }
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         //FIXME: implement
         return false;
@@ -409,13 +553,13 @@ struct out_implicit
 struct in_style
 {
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
         //FIXME: implement
         return 0;
     }
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         //FIXME: implement
         return false;
@@ -425,13 +569,13 @@ struct in_style
 struct out_style
 {
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
         //FIXME: implement
         return 0;
     }
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         //FIXME: implement
         return false;
@@ -441,13 +585,13 @@ struct out_style
 struct in_label
 {
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
         //FIXME: implement
         return 0;
     }
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         //FIXME: implement
         return false;
@@ -457,13 +601,13 @@ struct in_label
 struct out_label
 {
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
         //FIXME: implement
         return 0;
     }
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         //FIXME: implement
         return false;
@@ -473,13 +617,13 @@ struct out_label
 struct style
 {
 
-    static types::InternalType* get(const GraphicsAdapter& adaptor)
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
         //FIXME: implement
         return 0;
     }
 
-    static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         //FIXME: implement
         return false;