virtualIO

Purpose

This behaviour allows the VCC model to communicate with the Window Dressing application. It sends the contents of the screen buffer out and receives mouse events sending them out to a Port.

Parameters

This behaviour takes a single parameter ClientString, this string is passed to the screenOut and mouseIn models inorder to generate the relevant kernel names.

VCC Symbol

Contents

Click on one of the above blocks contained within the virtualIO behaviour for further information.

Uniform Pulses

A predefined VCC block that generates trigger signals with a parameterised frequency.

screenOut

Purpose

screen_buffer type

This behaviour receives screen_buffer messages on the screenBuffersIn port and sends them across a Win32 pipe to the Window Dressing application. This module requires the vccStub.lib and win2vcc.lib in order to be built.

Parameters

This behaviour takes a single parameter ScreenString, this string is passed passed to the ScreenClient constructor and is used to generate kernel object names.

Code

screenOut: black.h

#include "black_interface.h" //generated by "fabricate"
#ifndef _screenOut_h_
#define _screenOut_h_

#include "VCCStub.h"

class CPP_MODEL_IMPLEMENTATION : public CPP_MODEL_INTERFACE
{
  private:
  ScreenClient *screenPipeOut;
  public:
  CPP_MODEL_IMPLEMENTATION(const ModuleProto &, InstanceInit &);

  void Init();

  void Run();

  void WrapUp();
}
;

#endif

 

screenOut: black.cpp

#include "black.h"

CPP_MODEL_IMPLEMENTATION::CPP_MODEL_IMPLEMENTATION(const ModuleProto &proto, InstanceInit &inst)
: CPP_MODEL_INTERFACE(proto, inst)
{}

void CPP_MODEL_IMPLEMENTATION::Init()
{
  typeObjectString name = ScreenString.Value();
  screenPipeOut = new ScreenClient( TString( name ) );

  ostream& Error = ErrorStream();

  switch( screenPipeOut->connect() ){
  case PC_CONNECTED:
  case PC_ALREADY_CONNECTED:
  break;
  default:
  Error << Start << "Error Connecting to Screen Server: " << name
     << End << Abort;
  break;
  }
}

void CPP_MODEL_IMPLEMENTATION::Run()
{
  Stratego_screen_buffer scrnBuff = buffersIn.Value();

  char tempPalette[768];
  char tempScreen[76800];

  Stratego_palette_t palette = scrnBuff.get_palette();
  for(int i=0; i<768; i++){
    tempPalette[i] = palette.get(i);
  }

  Stratego_screen_t screen = scrnBuff.get_screen();
  for(i=0; i<76800; i++){
    tempScreen[i] = screen.get(i);
  }

  bool result = screenPipeOut->write(
      scrnBuff.get_width(),
      scrnBuff.get_height(),
      256,
      8,
      (RGBTRIPLE*) tempPalette,
      (LPBYTE) tempScreen);

  if(!result){
  ostream& Warn = WarningStream();
  Warn << Start << "Didn't send screen-buffer successfully" <<
     End;
    if( !screenPipeOut->isConnected() ){
    ostream& Error = ErrorStream();
    Error << Start << "Connection to Screen Server lost" << End
       << Abort;
    }
  }
}

void CPP_MODEL_IMPLEMENTATION::WrapUp()
{
  screenPipeOut->disconnect();
  delete screenPipeOut;
}

mouseInput

Purpose

mouse_click type

On recieving a trigger this block attempts to deque a mouseMessage from a Win32 pipe connected to the Window Dressing application. If a message is dequed it is sent out on the mouseClicksOut port as a mouse_click type. This module requires the vccStub.lib and win2vcc.lib in order to be built.

Parameters

This behaviour takes a single parameter MouseString, this string is passed passed to the MouseClient constructor and is used to generate kernel object names.

Code

mouseIn: black.h

#include "black_interface.h" //generated by "fabricate"
#ifndef _mouseInput_h_
#define _mouseInput_h_

#include "VCCStub.h"

class CPP_MODEL_IMPLEMENTATION : public CPP_MODEL_INTERFACE
{
private:
MouseClient *mousePipeIn;
public:
CPP_MODEL_IMPLEMENTATION(const ModuleProto &, InstanceInit &);

  void Init();
  void Run();
  void WrapUp();
}
;

#endif

 

mouseIn: black.cpp

#include "black.h"

CPP_MODEL_IMPLEMENTATION::CPP_MODEL_IMPLEMENTATION(const ModuleProto &proto, InstanceInit &inst)
: CPP_MODEL_INTERFACE(proto, inst)
{}

void CPP_MODEL_IMPLEMENTATION::Init()
{
  typeObjectString name = MouseString.Value();
  mousePipeIn = new MouseClient( TString( name ) );

  ostream& Error = ErrorStream();

  switch( mousePipeIn->connect() ){
    case PC_CONNECTED:
    case PC_ALREADY_CONNECTED:
      break;
    default:
      Error << Start << "Error Connecting to Mouse Server: " <<
         name << End << Abort;
    break;
  }
}

void CPP_MODEL_IMPLEMENTATION::Run()
{
  Stratego_IO_mouse_click output;
  mouseMessage msg;

  ostream& Error = ErrorStream();
  typeObjectString name = MouseString.Value();

  switch( mousePipeIn->deQueueMessage(&msg) ){
    case MI_SUCCESS:
      output.set_status(msg.button);
      output.set_x(msg.x);
      output.set_y(msg.y);

      clicksOut.Post(output);
      break;
    case MI_NO_MESSAGE:
      break;
    case MI_NOT_CONNECTED:
    case MI_UNKNOWN_ERROR:
    default:
      Error << Start << "Connection to Mouse Server lost:" <<
         name << End << Abort;
      break;
    }
}

void CPP_MODEL_IMPLEMENTATION::WrapUp()
{
  mousePipeIn->disconnect();
  delete mousePipeIn;
}


Copyright © 2002 James Brown
Last Updated Fri, 29/3/02