Sample Application Code

Using the application data manager to share information within your application is very easy and powerful. You only need to do the following:

Once you have completed this simple tasks you will have a custom data type that is being synchronized across all cluster nodes behind the scenes. This can make the process of sharing the transformation matrix a simple task that can be implemented in 50 lines of code.

Example 6.1. Define Your Data Structure

  1 #include <vpr/IO/SerializableObject.h>
    struct MyType1 
    { 
       int something; 
  5    float otherStuff;
       char stupid;
       bool drawBool;
    }; 
    
 10 template<class MyType> 
    vpr::ReturnStatus 
    vpr::SerializableObjectMixin<MyType>::writeObject(vpr::ObjectWriter* writer) 2 
    {
       writer->writeUint16(something); 
 15    writer->writeBool(drawBool); 
    }
       
    template<class MyType> 
    vpr::ReturnStatus
 20 vpr::SerializableObjectMixin<MyType>::readObject(vpr::ObjectReader* reader)3 
    { 
       something = reader->readUint16();
       drawBool = reader->readBool(); 
    }
1

Define the data type that you want to share across the cluster.

2

Implement the function that will serialize the structure.

3

Implement the function that will de-serialize the structure.

Example 6.2. Declare an Instance

cluster::UserData<vpr::SerializableObjectMixin<MyType> > mMyData;1
1

Declare an instance of your data type called mMyData

Example 6.3. Initialize the Data Structure

vpr::GUID new_guid("d6be4359-e8cf-41fc-a72b-a5b4f3f29aa2");1 
        std::string hostname = "gfxn1";2 
        mMyData.init(new_guid, hostname);3
1

Create a new GUID to identify the new data.

2

Store the hostname of the cluster node that will be responsible for updating the value of the data structure.

3

Initialize the data structure to be shared across the cluster.

Example 6.4. Calculate the Value of the Data Structure

  1 if (mMyData.isLocal())1 
    {
       if(0 != mButton0->getData())2 
       { 
  5       mMyData->drawBool = true;3 
       } 
       else
       {
          mMyData->drawBool = false; 
 10    } 
    }
1

Determine if the data structure is local, the value is being updated by the local machine.

2

Get the current state of Button0.

3

Change the value of the shared data structure to match Button0.

Example 6.5. Use the Data Structure

if (mMyData->drawBool == true)1 
{
   drawNetwork();2 
}
1

Test if the value of the mMyData is true.

2

If true then call a function that draws the representation of the cluster network.