summaryrefslogtreecommitdiff
path: root/IvyProbe/IvyProbeDlg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'IvyProbe/IvyProbeDlg.cpp')
-rw-r--r--IvyProbe/IvyProbeDlg.cpp394
1 files changed, 394 insertions, 0 deletions
diff --git a/IvyProbe/IvyProbeDlg.cpp b/IvyProbe/IvyProbeDlg.cpp
new file mode 100644
index 0000000..ef7bff8
--- /dev/null
+++ b/IvyProbe/IvyProbeDlg.cpp
@@ -0,0 +1,394 @@
+// TestDlg.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "IvyProbe.h"
+#include "IvyProbeDlg.h"
+#include "TestParseCmdLine.h"
+
+#include "IvyApplication.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+static char BASED_CODE szFilterMsg[] = "Ivy Messages Files (*.ivm)|*.ivm|Ivy Files (*.ivm;*.ivb;*.txt)|*.ivm;*.ivb;*.txt|All Files (*.*)|*.*||";
+static char BASED_CODE szFilterBind[] = "Ivy Bindings Files (*.ivb)|*.ivb|Ivy Files (*.ivm;*.ivb;*.txt)|*.ivm;*.ivb;*.txt|All Files (*.*)|*.*||";
+
+CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
+{
+ //{{AFX_DATA_INIT(CAboutDlg)
+ //}}AFX_DATA_INIT
+}
+
+void CAboutDlg::DoDataExchange(CDataExchange* pDX)
+{
+ CDialog::DoDataExchange(pDX);
+ //{{AFX_DATA_MAP(CAboutDlg)
+ //}}AFX_DATA_MAP
+}
+
+BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
+ //{{AFX_MSG_MAP(CAboutDlg)
+ // No message handlers
+ //}}AFX_MSG_MAP
+END_MESSAGE_MAP()
+
+/////////////////////////////////////////////////////////////////////////////
+// CTestDlg dialog
+
+CIvyProbeDlg::CIvyProbeDlg(CWnd* pParent /*=NULL*/)
+ : MyDialog(CIvyProbeDlg::IDD, pParent)
+{
+ //{{AFX_DATA_INIT(CTestDlg)
+ m_busnumber = "";
+ //}}AFX_DATA_INIT
+ // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
+ m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
+
+ bus = NULL;
+}
+
+void CIvyProbeDlg::DoDataExchange(CDataExchange* pDX)
+{
+ MyDialog::DoDataExchange(pDX);
+ //{{AFX_DATA_MAP(CTestDlg)
+ DDX_Control(pDX, IDC_REGEXP, m_expr);
+ DDX_Control(pDX, IDC_MSG, m_msg);
+ DDX_Text(pDX, IDC_BUSNUMBER, m_busnumber);
+ //}}AFX_DATA_MAP
+}
+
+BEGIN_MESSAGE_MAP(CIvyProbeDlg, MyDialog)
+ //{{AFX_MSG_MAP(CTestDlg)
+ ON_WM_QUERYDRAGICON()
+ ON_BN_CLICKED(IDC_START, OnStart)
+ ON_WM_CLOSE()
+ ON_BN_CLICKED(IDC_SEND, OnSend)
+ ON_BN_CLICKED(IDC_BIND, OnBind)
+ ON_WM_SYSCOMMAND()
+ ON_COMMAND(FILE_LOAD, OnLoad)
+ ON_COMMAND(FILE_SAVE, OnSave)
+ //}}AFX_MSG_MAP
+ ON_COMMAND(ID_FILE_SAVEBINDINGS, &CIvyProbeDlg::OnFileSavebindings)
+ ON_COMMAND(ID_FILE_LOADBINDINGS, &CIvyProbeDlg::OnFileLoadbindings)
+END_MESSAGE_MAP()
+
+
+
+const char * CONVSTR( const CString& str )
+{
+#ifdef UNDER_CE
+
+ static char buffer[4096];
+ int len = str.GetLength();
+ buffer[len] = '\0';
+ if ( len )
+ {
+ int err = WideCharToMultiByte( CP_ACP, 0, str, len, buffer, 4096, NULL, NULL );
+ if ( err == 0 )
+ TRACE(TEXT("Error converting chars %d\n"),GetLastError());
+ }
+ return buffer;
+#else
+ return (LPCSTR) str;
+#endif
+
+}
+
+
+/////////////////////////////////////////////////////////////////////////////
+// CTestDlg message handlers
+
+BOOL CIvyProbeDlg::OnInitDialog()
+{
+ MyDialog::OnInitDialog();
+
+// // Add "About..." menu item to system menu.
+//
+// // IDM_ABOUTBOX must be in the system command range.
+// ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
+// ASSERT(IDM_ABOUTBOX < 0xF000);
+//
+// CMenu* pSysMenu = GetSystemMenu(FALSE);
+// if (pSysMenu != NULL)
+// {
+// CString strAboutMenu;
+// strAboutMenu.LoadString(IDS_ABOUTBOX);
+// if (!strAboutMenu.IsEmpty())
+// {
+// pSysMenu->AppendMenu(MF_SEPARATOR);
+// pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
+// }
+// }
+
+ // Set the icon for this dialog. The framework does this automatically
+ // when the application's main window is not a dialog
+ SetIcon(m_hIcon, TRUE); // Set big icon
+ SetIcon(m_hIcon, FALSE); // Set small icon
+
+#ifdef USE_ETS
+ // define the Layout
+ CreateRoot( VERTICAL, nDefaultBorder, 5 )
+ << ( pane( HORIZONTAL, ABSOLUTE_VERT )
+ << item ( IDC_BUSNUMBER, GREEDY )
+ << item ( IDC_START, NORESIZE )
+ )
+ << item ( IDC_TEXT, GREEDY )
+ << ( pane( HORIZONTAL, ABSOLUTE_VERT )
+ << item( IDC_STATIC_MSG, NORESIZE )
+ << item( IDC_MSG, GREEDY )
+ << item( IDC_SEND, NORESIZE )
+ )
+ << ( pane( HORIZONTAL, ABSOLUTE_VERT )
+ << item( IDC_STATIC_BIND, NORESIZE )
+ << item( IDC_REGEXP, GREEDY )
+ << item( IDC_BIND, NORESIZE )
+ );
+ UpdateLayout ();
+#endif
+ // extra initialization here
+ m_text.SubclassDlgItem (IDC_TEXT, this);
+
+
+ // parse command Line Info
+ TestParseCmdLine cmd;
+ AfxGetApp()->ParseCommandLine( cmd );
+
+ // Set Argument from Command Line
+ m_busnumber = cmd.m_busNumber;
+
+ bus = new Ivy( "IvyProbe Windows","IvyProbe Windows Ready",this,FALSE);
+ bus->SetBindCallback( this );
+
+// bus->BindMsg("(.*)", BUS_CALLBACK_OF(CTestDlg, IvyCallback ));
+
+ //bus->BindMsg("^S( A=([0-9]+))?( B=([0-9]+))?",cb);
+ m_busnumber = bus->GetDomain( CONVSTR(m_busnumber) );
+ UpdateData(FALSE);
+
+ // force bus start in case of start
+ if ( cmd.m_start )
+ OnStart();
+
+ return TRUE; // return TRUE unless you set the focus to a control
+}
+
+
+//void CTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
+//{
+// if ((nID & 0xFFF0) == IDM_ABOUTBOX)
+// {
+// CAboutDlg dlgAbout;
+// dlgAbout.DoModal();
+// }
+// else
+// {
+// MyDialog::OnSysCommand(nID, lParam);
+// }
+//}
+
+
+
+// The system calls this to obtain the cursor to display while the user drags
+// the minimized window.
+HCURSOR CIvyProbeDlg::OnQueryDragIcon()
+{
+ return (HCURSOR) m_hIcon;
+}
+
+void CIvyProbeDlg::OnStart()
+{
+ UpdateData(TRUE);
+ bus->stop();
+ m_busnumber = bus->GetDomain( CONVSTR(m_busnumber) );
+ bus->start(CONVSTR(m_busnumber));
+ UpdateData(FALSE);
+}
+
+void CIvyProbeDlg::OnMessage(IvyApplication *app, int argc, const char **argv)
+{
+ int i;
+ CString text;
+ TRACE(TEXT(" Called function args:"));
+ WriteMessage( "Ivy callback %d args",argc );
+ for ( i = 0; i < argc; i++ )
+ {
+ WriteMessage(" arg%d='%s'",i, argv[i] );
+ TRACE(TEXT(" '%s'"),argv[i]);
+ }
+ TRACE(TEXT("\n"));
+
+}
+
+
+
+void CIvyProbeDlg::OnDirectMessage(IvyApplication *app, int id, const char *arg)
+{
+TRACE(TEXT("Direct Msg Receive %d, %s\n"),id,arg );
+}
+
+void CIvyProbeDlg::OnApplicationConnected(IvyApplication *app)
+{
+ WriteMessage( "Application: %s ready",(LPCSTR)(app->GetName()) );
+}
+void CIvyProbeDlg::OnApplicationDisconnected(IvyApplication *app)
+{
+ WriteMessage( "Application: %s bye",(LPCSTR)(app->GetName()) );
+}
+
+void CIvyProbeDlg::OnAddBind (IvyApplication *app, int id, const char * regexp)
+{
+ WriteMessage( "Application: %s Add Binding %s",(LPCSTR)(app->GetName()), regexp );
+}
+void CIvyProbeDlg::OnRemoveBind (IvyApplication *app, int id, const char * regexp)
+{
+ WriteMessage( "Application: %s Remove Binding %s",(LPCSTR)(app->GetName()), regexp );
+}
+void CIvyProbeDlg::OnFilterBind (IvyApplication *app, int id, const char * regexp)
+{
+ WriteMessage( "Application: %s Filtered Binding %s",(LPCSTR)(app->GetName()), regexp );
+}
+
+void CIvyProbeDlg::WriteMessage(const char *format, ...)
+{
+ char str[4096];
+ // format and write the data we were given
+ va_list args;
+ va_start(args, format);
+ _vsnprintf_s(str, sizeof(str), sizeof(str)-1, format, args);
+
+ m_text.AppendString( str );
+}
+
+
+void CIvyProbeDlg::OnClose()
+{
+ // TODO: Add your message handler code here and/or call default
+ TRACE ( TEXT("IvyProbe Quitting\n"));
+ if (bus)
+ {
+ bus->stop();
+ delete bus;
+ }
+
+ MyDialog::OnClose();
+}
+
+
+void CIvyProbeDlg::OnSend()
+{
+ CString buffer;
+ m_msg.SetEditSel( 0, -1 );
+ m_msg.GetWindowText( buffer );
+ if ( buffer.IsEmpty() ) return;
+ int count = bus->SendMsg( CONVSTR(buffer) );
+ if ( m_msg.FindStringExact(-1, buffer) == CB_ERR )
+ {
+ //m_msg.AddString( buffer );
+ m_msg.InsertString( 0, buffer );
+ }
+ WriteMessage( "Sending %d message %s",count,CONVSTR(buffer) );
+ m_msg.Clear();
+}
+
+void CIvyProbeDlg::OnBind()
+{
+ CString buffer;
+ m_expr.SetEditSel( 0, -1 );
+ m_expr.GetWindowText( buffer );
+ if ( buffer.IsEmpty() ) return;
+ int count = bus->BindMsg( CONVSTR(buffer) , this );
+ if ( m_expr.FindStringExact(-1, buffer) == CB_ERR )
+ {
+ m_expr.AddString( buffer );
+ }
+ WriteMessage( "Binding to %s", CONVSTR(buffer) );
+ m_expr.Clear();
+}
+
+
+void CIvyProbeDlg::OnLoad()
+{
+#ifndef UNDER_CE
+ // TODO ReadString doesn't existe
+ CString message;
+
+ CFileDialog dialog( TRUE, TEXT("ivm"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilterMsg);
+ if ( dialog.DoModal() == IDOK )
+ {
+ CStdioFile file( dialog.GetPathName(), CFile::modeRead | CFile::typeText );
+ m_msg.ResetContent();
+ while ( file.ReadString( message ))
+ {
+ m_msg.AddString( message );
+ }
+ file.Close();
+ }
+#endif
+}
+
+void CIvyProbeDlg::OnSave()
+{
+#ifndef UNDER_CE
+ // TODO WriteString doesn't existe
+ CString message;
+
+ CFileDialog dialog( FALSE, TEXT("ivm") , NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilterMsg);
+ if ( dialog.DoModal() == IDOK )
+ {
+ CStdioFile file( dialog.GetPathName(), CFile::modeCreate | CFile::modeWrite | CFile::typeText );
+ for (int i=0;i < m_msg.GetCount();i++)
+ {
+ m_msg.GetLBText( i, message );
+ file.WriteString(message + TEXT("\n"));
+ }
+ file.Close();
+
+ }
+#endif
+}
+
+void CIvyProbeDlg::OnFileLoadbindings()
+{
+#ifndef UNDER_CE
+ // TODO ReadString doesn't existe
+ CString message;
+
+ CFileDialog dialog( TRUE, TEXT("ivb"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilterBind);
+ if ( dialog.DoModal() == IDOK )
+ {
+ CStdioFile file( dialog.GetPathName(), CFile::modeRead | CFile::typeText );
+ m_expr.ResetContent();
+ while ( file.ReadString( message ))
+ {
+ m_expr.AddString( message );
+ bus->BindMsg( CONVSTR(message) , this );
+ }
+ file.Close();
+ }
+#endif
+}
+
+void CIvyProbeDlg::OnFileSavebindings()
+{
+#ifndef UNDER_CE
+ // TODO WriteString doesn't existe
+ CString message;
+
+ CFileDialog dialog( FALSE, TEXT("ivb") , NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilterBind);
+ if ( dialog.DoModal() == IDOK )
+ {
+ CStdioFile file( dialog.GetPathName(), CFile::modeCreate | CFile::modeWrite | CFile::typeText );
+ for (int i=0;i < m_expr.GetCount();i++)
+ {
+ m_expr.GetLBText( i, message );
+ file.WriteString(message + TEXT("\n"));
+ }
+ file.Close();
+
+ }
+#endif
+}