summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfcolin2007-02-01 13:13:10 +0000
committerfcolin2007-02-01 13:13:10 +0000
commitca9ed29613974218347a1229458be9b19472eef9 (patch)
treef5daf322e0dd893e9b08bbef79f39630004fbf45
parent449663bd3662b5841a5e96c059630a31f26675b6 (diff)
downloadivy-cplusplus-ca9ed29613974218347a1229458be9b19472eef9.zip
ivy-cplusplus-ca9ed29613974218347a1229458be9b19472eef9.tar.gz
ivy-cplusplus-ca9ed29613974218347a1229458be9b19472eef9.tar.bz2
ivy-cplusplus-ca9ed29613974218347a1229458be9b19472eef9.tar.xz
Utilisateur : Fcolin Date : 3/10/02 Heure : 10:55 Créé Commentaire: (vss 1)
-rw-r--r--comIvy/Bus.cpp115
1 files changed, 115 insertions, 0 deletions
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);
+}