7. Ivy c++ Windows port

The API is very similiar to the java port, that's why we include this little section within the ivy java documentation. The author is not familiar with windows programming or C++ programming so that this documentation might be inaccurate. Here is a sample listing that might be useful:

// ivytest.cpp : Defines the entry point for the console application.
#include <iostream.h>

#include <stdlib.h>

#include "ivy.h"
#include "IvyApplication.h"

static bool TheGrassIsGreenAndTheWindBlows = true;

class cIvyTranslater : public IvyApplicationCallback 
{   
public:
    cIvyTranslater(void);
protected:
	void OnApplicationConnected   ( IvyApplication *app );
	void OnApplicationDisconnected( IvyApplication *app );
	void HelloCallback  ( IvyApplication *app, int argc, const char **argv );
	void ByeCallback    ( IvyApplication *app, int argc, const char **argv );
	Ivy *bus;
};



cIvyTranslater::cIvyTranslater(void) 
{
    // initialization
	bus = new Ivy( "cIvyTranslater","cIvyTranslater READY",this,FALSE);

    int count;
    count = bus->BindMsg( "^Hello(.*)", BUS_CALLBACK_OF(cIvyTranslater, HelloCallback ));
    count = bus->BindMsg( "^Bye$",      BUS_CALLBACK_OF(cIvyTranslater, ByeCallback ));
    
    bus->start("127.255.255.255:2010");
}

void cIvyTranslater::HelloCallback(IvyApplication *app, int argc, const char **argv)
{
    const char* arg = (argc < 1) ? "" : argv[0];
	cout << "cIvyTranslater received msg: Hello'" << arg
	<< "'" << endl;
    bus->SendMsg( "Bonjour%s!", arg );
}

void cIvyTranslater::ByeCallback(IvyApplication *app, int argc, const char **argv)
{
	cout << "cIvyTranslater stops bus" << endl;
    if (bus) {
        TheGrassIsGreenAndTheWindBlows = false;
        bus->stop(); 
        delete bus; // This statement is never reached! Don't know why!
    }
	
}

void cIvyTranslater::OnApplicationConnected(IvyApplication *app)
{
	cout << "cIvyTranslater is ready to accept messages from "
	<< app->GetName() << endl;
}

void cIvyTranslater::OnApplicationDisconnected(IvyApplication *app)
{
	cout << "cIvyTranslater good buy '" << app->GetName()
	<< "'" << endl;
}


void main(int argc, char* argv[]) 
{
    cIvyTranslater aIvyTL;

    while (TheGrassIsGreenAndTheWindBlows) {
        Sleep(2000);
        cout << "new cycle..." << endl;
    }
	cout << "Good buy, world\n";
}

7.1. Win32 API