VISH  0.2
abcexample.cpp

Demonstration of the data flow graph.We implement three objects, named DataSink, DataFilter and DataSource:

#include <ocean/plankton/VModules.hpp>
#include <ocean/plankton/VCreator.hpp>

#define override

using namespace Wizt;

// The Alpha type. We don't have content here, it is just for demonstration.
struct  Alpha
{
};

// The Beta type, also empty, since we are in demo mode here.
struct  Beta
{
};


namespace Wizt
{
        /*
          VISH provides generic I/O for input types via text.
          As such, we need to provide the information how to
          convert an Alpha type from and to text. This is done
          via a Type Trait class.

          In this case, the conversion functions always return
          false, indicating that no conversion was possible.
          We don't need that here, since the types are empty
          and have no state to save or load at all.
         */
        template <> 
        class VValueTrait<Alpha>
        {
        public:
                
        static  bool setValueFromText(Alpha&i, const string&s)
                {       return false;   }

        static  string Text(const Alpha&)
                {       return "";      }               
        };


        template <> 
        class VValueTrait<Beta>
        {
        public:
        static  bool setValueFromText(Beta&i, const string&s)
                {       return false;   }

        static  string Text(const Beta&)
                {       return ""; }            
        };
}



/*
  A VObject which provides alpha's
 */
class   DataSource : public Wizt::VObject
{
public:
        VOutput<Alpha>      AlphaParameter;

        DataSource(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
        : VObject(name, p, VP)
        , AlphaParameter( self(), "alpha", Alpha() )
        {}

        override bool update(VRequest&R, double precision)
        {
                puts("DATASOURCE: update");

                return true;
        }
};



/*
  A VObject which takes an alpha and converts it into a beta
 */
class   DataFilter : public Wizt::VObject
{
        TypedSlot<Alpha>                AlphaInput;
        VOutput<Beta>                   BetaParameter;

public:
        DataFilter(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
        : VObject(name, p, VP)
        , AlphaInput(this, "alphainput", Alpha() )
        , BetaParameter( self(), "beta", Beta() )
        {}

        override bool update(VRequest&R, double precision)
        {
                puts("DATAFILTER: update()");

                return true;
        }
};

/*
  A VObject which requires beta's
 */
class   DataSink : public Wizt::VObject
{
        TypedSlot<Beta> BetaSource;

public:
        DataSink(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
        : VObject(name, p, VP)
        , BetaSource(this, "betaInput", Beta() )
        {}

        override bool update(VRequest&R, double precision)
        {
                puts("DATASINK: update()");
                return true;
        }
};

static Ref<VCreator<DataSource>                     > VDataSourceCreator("Examples/DataSource", ObjectQuality::DEMO);
static  Ref<VCreator<DataFilter, AcceptList<Alpha> > > VDataFilterCreator("Examples/DataFilter", ObjectQuality::DEMO);
static Ref<VCreator<DataSink  , AcceptList<Beta > > > VDataSinkCreator  ("Examples/DataSink", ObjectQuality::DEMO);















#if 1
int do_stuff()
{
        puts("initialize"); 

// 
// Here, we create the VObjects through the VCreatorBase::find() interface. 
// Note that we could also create them using a simple C++ new. 
// Also, we could have found and created these objects through querying 
// VISH for a certain input type, e.g. asking for an input of Beta or 
// Alpha. This code here is just for simplification of this setup part. 
// 
//
RefPtr<VCreatorBase> VC = VCreatorBase::find("DataSource"); 
        if (!VC) { puts("DataSource creator not found"); return 1; } 
RefPtr<DataSource>   DS = VC->create("MySource");
        if (!DS) { puts("Could not create DataSource"); return 1; } 

        VC = VCreatorBase::find("DataFilter"); 
        if (!VC) { puts("DataFilter creator not found"); return 1; } 
RefPtr<DataFilter>  DF = VC->create("MyFilter"); 
        if (!DF) { puts("Could not create DataFilter"); return 1; } 

        VC = VCreatorBase::find("DataSink"); 
        if (!VC) { puts("DataSink creator not found"); return 1; } 
RefPtr<DataSink>  DT = VC->create("MySink"); 
        if (!DT) { puts("Could not create DataSink"); return 1; } 




// 
// Setting up link from DataSource to DataFilter via communication object type Alpha
// 
{
RefPtr<VParameter> OldParam = DF->getParameter("alphaInput"); 
RefPtr<VParameter> NewParam = DS->getImplementation( typeid(Alpha), "", "" ); 

        switch( DF->attach( OldParam, NewParam) )
        {
        default:
                puts("Error in setting up ALPHA parameter chain");
                return 0;

        case VObject::AttachmentOk:  puts("ALPHA parameter chain ok");
        } 
}


// 
// Setting up link from DataFilter to DataSink via object type Beta 
// 
{
RefPtr<VParameter> OldParam = DT->getParameter("betaInput"); 
RefPtr<VParameter> NewParam = DF->getImplementation( typeid(Beta), "", "" ); 

        switch( DT->attach( OldParam, NewParam) )
        {
        default:
                puts("Error in setting up BETA parameter chain");
                return 0;

        case VObject::AttachmentOk:  puts("BETA parameter chain ok");
        } 
}

// 
// Done, now we are ready to issue an (asynchroneous) request chain
//

VRequest myRequest(false);
        DS->age(myRequest).touch();

        puts("Chain Status:"); 
        printf("DS: %d\n", int(DS->age(myRequest).time_value()) ); 
        printf("DF: %d\n", int(DF->age(myRequest).time_value()) ); 
        printf("DT: %d\n", int(DT->age(myRequest).time_value()) );

        DT->request(myRequest, 1.0, DT, DT);


        puts("exit");
        return 0;
}
#endif


VISH_INITIALIZER bool VISH_abcexample(VInitialization*VInit)
{
        return VInit->IsCompatible();
}