Hi,
I have an external application which connects to OpenOffice.org application
using sockets. The connection string can be given as
"uno:socket,host=localhost,port=2081 ". OpenOffice was started in accept mode
with the above string. I have an application level macro which needs to call a
function in the external application. I am hoping to use the bridge connection
using sockets to make this communication work.
The Macro is as follows
Sub Test2
oConnector = createUnoService( "com.sun.star.connection.Connector" )
oConnection = oConnector.connect("socket,host=localhost,port=2081")
cCR = Chr(13)
cLF = Chr (10)
oConnection.write( StringToByteArray( "Hello World" + cCR + cLF + cCR +
cLF) )
oConnection.flush()
oConnection.close()
End Sub
The external application registers a XStreamListener on the connection using
the XConnectionBroadcaster. The class is given below. I am expecting the
XStreamListener functions to get a call when something is written to the
Connection. I have seen the XStreamListener interface implementation in the
following post
http://www.oooforum.org/forum/viewtopic ...
uest#26353<http://www.oooforum.org/forum/viewtopic.phtml?p=26353&highlight=http+request#26353>
However I am not sure how this can be implemented for communicating with an
external C++ application connected to OpenOffice.org application. Any help on
this will be welcome.
// Class to listen to the OpenOffice.org connection. It registers on the
XConnection to recieve a callback
// when the user tries to write data to the socket from OpenOffice.org.
class ConnectionMonitor : public ::cppu::WeakImplHelper1<XStreamListener>
{
public:
// Constrution
ConnectionMonitor(Reference<XConnection> xConnection, bool bRegister =
true) :
rConnection(xConnection), m_bRegistered(false)
{
if (bRegister)
{
Register(true);
}
}
//destructor
~ConnectionMonitor ()
{
Register(false);
}
bool Register(bool bRegister)
{
Reference <XConnectionBroadcaster > xBC (rConnection, UNO_QUERY);
if ( !xBC.is() )
{
printf("XConnectionBroadcaster is not found");
return false;
}
if (bRegister != m_bRegistered)
try
{
if (bRegister)
{
xBC->addStreamListener(this);
}
else
{
xBC->removeStreamListener(this);
}
m_bRegistered = bRegister;
}
catch (Exception e)
{
printf("Error: Problem encountered while adding/removing
StreamListener on Connection to OOo %s\n",
OUStringToOString(e.Message,
RTL_TEXTENCODING_ASCII_US).getStr());
return false;
}
return m_bRegistered;
}
protected:
// Implementation data
bool m_bRegistered;
Reference<XConnection> rConnection;
public:
// XEventListener
virtual void SAL_CALL disposing(const EventObject& Source)
{
m_bRegistered = false;
}
// //XStreamListener
virtual void SAL_CALL started() throw (RuntimeException)
{
printf(" Streaming started \n");
}
// //XStreamListener
virtual void SAL_CALL closed() throw (RuntimeException)
{
printf(" Streaming closed \n");
}
////XStreamListener
virtual void SAL_CALL terminated() throw (RuntimeException)
{
printf(" Streaming terminated \n");
}
////XStreamListener
virtual void SAL_CALL error( const ::Any& aException ) throw
(::com::sun::star::uno::RuntimeException)
{
}
};
Thanks,
Mangesh
Mangesh Shukla