VISH  0.2
exocoetida.cpp
Sailfin_flyingfish.jpg

(Image: Parexocoetus brachypterus)

This application of vish is without any fancy user interface, user interaction, module loading, scripting or whatsoever. It demonstrates the weak event loop, the synchroneous graph that allows immediate notification of events. As such, it deals with the very fast event notification mechanism, which is kind of flying, thuse the canonical name of this example is a flying fish, biological name Exocoetidae according to http://en.wikipedia.org/wiki/Flying_fish .

#include <ocean/plankton/VObject.hpp>
#include <ocean/plankton/VParameter.hpp>
#include <ocean/plankton/VInput.hpp>
#include <ocean/plankton/VCreator.hpp>



using namespace Wizt;

class   IntegerInput : public VInputValue<int>
{
public:
        IntegerInput(const RefPtr<VValueParameter<int> >&P)
        : VInputValue<int>(P)
        {}

        override void valueChanged(const RefPtr<VValueBase>&, const ValueNotifierList*, const ValueMap*)
        {
                puts("FirstIntegerInput: Retrieved valueChanged request!");
        }
};



/*
  A VObject which requires int's
 */
class   DataSink : public VObject
{
public:
        DataSink(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
        : VObject(name, p, VP)
        {
                // request an integer parameter
                addParam("alpha", 42 );
        }


        override bool update(VRequest&R, double precision)
        {
        int     alpha = 10101;
                if (!getParameterValue(alpha, "alpha", R ) )
                {
                        puts("DATASINK: update() unsuccessful");
                }
                else
                {
                        printf("DATASINK: update() got alpha=%d\n", alpha);
                }


                return true;
        }
};

static VCreator<DataSink>   VDataSinkCreator("DataSink");

int main( int argc, char **argv )
{
        puts("initialize"); 


RefPtr<VValueParameter<int> > P = new VValueParameter<int>( 33, "integername", NullPtr() );

RefPtr<VInputValue<int> > firstInput = new IntegerInput(P);
RefPtr<VInputValue<int> > secondInput = new IntegerInput(P);

        firstInput->activateNotification();
        secondInput->activateNotification();

VContext* myContext = 0;

        firstInput->setValue( myContext, "", 128);
        secondInput->setValue( myContext, "", 32);

// 
// 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;

        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; } 

RefPtr<VParameter> OldParam = DT->getParameter("alpha");
        if (!OldParam) { puts("Could not find DataSink.alpha"); return 1; } 

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

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


// 
// Done, now we are ready to issue a request chain 
//

VRequest myRequest; 

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

        firstInput->setValue( myContext, "", 256);
        DT->request(myRequest, 1.0);

        puts("done.");
        return 0;
}