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 (limited to '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 From 4e4c7697a33094f360e29ba203f116242b63896e Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:13:11 +0000 Subject: Utilisateur : Fcolin Date : 18/04/03 Heure : 15:43 Archivé dans $/Bus/comIvy Commentaire: ajout GetDomain (vss 2) --- comIvy/Bus.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'comIvy/Bus.cpp') diff --git a/comIvy/Bus.cpp b/comIvy/Bus.cpp index cad7a36..393406a 100644 --- a/comIvy/Bus.cpp +++ b/comIvy/Bus.cpp @@ -113,3 +113,10 @@ void CBus::OnApplicationDisconnected(IvyApplication * app) BSTR appname = ConvCSTR( app->GetName() ); ApplicationDisconnected(appname); } + +STDMETHODIMP CBus::GetDomain(BSTR* domain) +{ + *domain = ConvCSTR( bus->GetDomain(NULL) ); + + return S_OK; +} -- cgit v1.1 From ab15cfce0b453acf070c6c3715036017971dd524 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:13:13 +0000 Subject: Utilisateur : Fcolin Date : 7/06/04 Heure : 10:56 Archivé dans $/Bus/comIvy Commentaire: (vss 3) --- comIvy/Bus.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'comIvy/Bus.cpp') diff --git a/comIvy/Bus.cpp b/comIvy/Bus.cpp index 393406a..66f2f2c 100644 --- a/comIvy/Bus.cpp +++ b/comIvy/Bus.cpp @@ -95,9 +95,7 @@ STDMETHODIMP CBus::Bind(BSTR regexp, IExpression** binding) 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 ); + bind->Bind( regexpstr, this ); delete regexpstr; return hRes; } -- cgit v1.1 From 87713194748f6eb399f2ba2d6cb72db9ddb5e1a5 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:13:15 +0000 Subject: Utilisateur : Fcolin Date : 4/01/05 Heure : 14:48 Archivé dans $/Bus/comIvy Commentaire: (vss 4) --- comIvy/Bus.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'comIvy/Bus.cpp') diff --git a/comIvy/Bus.cpp b/comIvy/Bus.cpp index 66f2f2c..355661f 100644 --- a/comIvy/Bus.cpp +++ b/comIvy/Bus.cpp @@ -35,7 +35,11 @@ CBus::CBus() } CBus::~CBus() { - delete bus; + if ( bus ) + { + bus->stop(); + delete bus; + } bus = NULL; ATLTRACE("CBus destroyed\n"); } @@ -46,7 +50,7 @@ STDMETHODIMP CBus::Start(BSTR domain) if ( !bus ) return E_FAIL; if ( SysStringLen( domain ) ) strdomain= ConvBSTR(domain); - if ( bus ) bus->start(strdomain); + bus->start(strdomain); delete strdomain; return S_OK; } -- cgit v1.1