From ca9ed29613974218347a1229458be9b19472eef9 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:13:10 +0000 Subject: Utilisateur : Fcolin Date : 3/10/02 Heure : 10:55 Créé Commentaire: (vss 1) --- comIvy/Bus.cpp | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 comIvy/Bus.cpp diff --git a/comIvy/Bus.cpp b/comIvy/Bus.cpp new file mode 100644 index 0000000..cad7a36 --- /dev/null +++ b/comIvy/Bus.cpp @@ -0,0 +1,115 @@ +// Bus.cpp : implémentation de CBus + +#include "stdafx.h" +#include "Bus.h" +#include "Ivy.h" +#include "IvyApplication.h" +#include "Expression.h" + + +char * ConvBSTR( BSTR str ) +{ + char* convstr; + int len = SysStringLen( str ); + convstr = new char[len+1] ; + int bytes = WideCharToMultiByte(CP_ACP, 0, str, len, convstr, len, NULL,NULL); + convstr[bytes] = '\0'; + if (!bytes) ATLTRACE( "ConvBSR error %d", GetLastError()); + return convstr; +} +BSTR ConvCSTR( const char *str ) +{ + BSTR convstr; + int len = (int)strlen( str )+1; + convstr = SysAllocStringLen( NULL, len); + int bytes = MultiByteToWideChar(CP_ACP, 0, str, len, convstr, len); + if (!bytes) ATLTRACE( "ConvCSTR error %d", GetLastError()); + return convstr; +} + +// CBus +CBus::CBus() +: bus(NULL) +{ + ATLTRACE("CBus created\n"); +} +CBus::~CBus() +{ + delete bus; + bus = NULL; + ATLTRACE("CBus destroyed\n"); +} + +STDMETHODIMP CBus::Start(BSTR domain) +{ + char *strdomain = NULL; + if ( !bus ) return E_FAIL; + if ( SysStringLen( domain ) ) + strdomain= ConvBSTR(domain); + if ( bus ) bus->start(strdomain); + delete strdomain; + return S_OK; +} + +STDMETHODIMP CBus::Stop(void) +{ + if ( !bus ) return E_FAIL; + bus->stop(); + return S_OK; +} + +STDMETHODIMP CBus::Create(BSTR appName, BSTR readyMsg) +{ + char *strname= ConvBSTR(appName); + char *strready= ConvBSTR(readyMsg); + bus = new Ivy(strname,strready,this); + delete strname; + delete strready; + return S_OK; +} + +STDMETHODIMP CBus::Delete(void) +{ + if ( !bus ) return E_FAIL; + bus->stop(); + delete bus; + bus = NULL; + return S_OK; +} + +STDMETHODIMP CBus::Send(BSTR message, SHORT* count) +{ + if ( !bus ) return E_FAIL; + char *strmessage= ConvBSTR(message); + *count = bus->SendMsg( strmessage ); + delete strmessage; + return S_OK; +} + +STDMETHODIMP CBus::Bind(BSTR regexp, IExpression** binding) +{ + if ( !bus ) return E_FAIL; + char* regexpstr = ConvBSTR(regexp); + *binding = NULL; + // Note that at this point the ref count for the object is 0. + HRESULT hRes = CExpression::CreateInstance(binding); + if ( hRes != S_OK ) return hRes; + CExpression* bind = (CExpression*)*binding; + this->AddRef(); + bind->bus = this; + bind->id = bus->BindMsg( regexpstr, bind ); + delete regexpstr; + return hRes; +} + +void CBus::OnApplicationConnected(IvyApplication * app) +{ + BSTR appname = ConvCSTR( app->GetName() ); + ApplicationConnected(appname); +} + +void CBus::OnApplicationDisconnected(IvyApplication * app) +{ + BSTR appname = ConvCSTR( app->GetName() ); + ApplicationDisconnected(appname); +} -- cgit v1.1