// ShapeDemoView.cpp : CShapeDemoView 类的实现
//
#include "stdafx.h"
#include "ShapeDemo.h"
#include "ShapeDemoDoc.h"
#include "ShapeDemoView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#include <ace/Init_ACE.h>
#include <dds/DCPS/transport/framework/TransportRegistry.h>
#include <dds/DCPS/transport/framework/TransportConfig.h>
#include <dds/DCPS/transport/framework/TransportInst.h>
#include <dds/DCPS/transport/multicast/MulticastInst.h>
#include <dds/DCPS/transport/multicast/MulticastInst_rch.h>
using namespace OpenDDS::DCPS;
DDS::DomainId_t g_domainId = 255;
const char * g_topicname = "Sharp";
int g_shap_size = 15;
#define SendFreqTimerId WM_USER+1
#define DrawFreqTimerId WM_USER+2
#define WndUpFreqTimerId WM_USER+3
// CShapeDemoView
IMPLEMENT_DYNCREATE(CShapeDemoView, CFormView)
BEGIN_MESSAGE_MAP(CShapeDemoView, CFormView)
ON_WM_TIMER()
ON_WM_SIZE()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BTN_FREQ, &CShapeDemoView::OnBnClickedBtnFreq)
ON_BN_CLICKED(IDC_BTN_PROT, &CShapeDemoView::OnBnClickedBtnProt)
ON_BN_CLICKED(IDC_BTN_PUB, &CShapeDemoView::OnBnClickedBtnPub)
ON_BN_CLICKED(IDC_BTN_SUB, &CShapeDemoView::OnBnClickedBtnSub)
END_MESSAGE_MAP()
// CShapeDemoView
CShapeDemoView::CShapeDemoView()
: CFormView(CShapeDemoView::IDD)
, m_EdtLost(_T("0%"))
, m_EdtNods(0)
, m_EdtProt(_T(""))
{
m_pdpf = NULL;
m_pdp = NULL;
m_pservant = NULL;
m_topic = NULL;
m_pub = NULL;
m_sub = NULL;
m_pwrite = NULL;
m_pub_shape = NULL;
m_sub_shape = NULL;
m_timer = NULL;
m_xspeed = 6;
m_yspeed = 6;
m_pdelay = NULL;
m_TransportType = TRANSPORTTYPE_MULTICAST;
}
CShapeDemoView::~CShapeDemoView()
{
ShutDown();
}
void CShapeDemoView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_LOST, m_EdtLost);
DDX_Text(pDX, IDC_EDIT_NODS, m_EdtNods);
DDX_Text(pDX, IDC_EDIT_PROT, m_EdtProt);
DDX_Control(pDX, IDC_LIST_CAP, m_ListCtrlCap);
DDX_Control(pDX, IDC_CMB_FREQ, m_ComBoxFreq);
DDX_Control(pDX, IDC_CMB_TOPIC, m_ComBoxTopic);
DDX_Control(pDX, IDC_CMB_PROT, m_ComBoxProt);
}
BOOL CShapeDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
// CREATESTRUCT cs 来修改窗口类或样式
return CFormView::PreCreateWindow(cs);
}
void CShapeDemoView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
m_ListCtrlCap.InsertColumn(0, L"时间", LVCFMT_CENTER, 10);
m_ListCtrlCap.InsertColumn(1, L"时间", LVCFMT_CENTER, 85);
m_ListCtrlCap.InsertColumn(2, L"平均时延", LVCFMT_CENTER, 80);
m_ListCtrlCap.InsertColumn(3, L"吞吐量", LVCFMT_CENTER, 80);
m_ListCtrlCap.DeleteColumn(0);
CTime time = CTime::GetCurrentTime();
CString str = time.Format("%H:%M:%S");
int nRow = m_ListCtrlCap.InsertItem(0, str);
m_ListCtrlCap.SetItemText(nRow, 1, L"0US");
m_ListCtrlCap.SetItemText(nRow, 2, L"0Mbps");
m_ComBoxTopic.InsertString(0, L"矩形");
m_ComBoxTopic.InsertString(1, L"圆形");
m_ComBoxTopic.InsertString(2, L"三角");
m_ComBoxTopic.SetCurSel(0);
m_ComBoxFreq.InsertString(0, L"50");
m_ComBoxFreq.InsertString(1, L"250");
m_ComBoxFreq.InsertString(2, L"500");
m_ComBoxFreq.InsertString(3, L"700");
m_ComBoxFreq.InsertString(4, L"1000");
m_ComBoxFreq.SetCurSel(0);
m_ComBoxProt.InsertString(0, L"TCP");
m_ComBoxProt.InsertString(1, L"UDP");
m_ComBoxProt.InsertString(2, L"Multicast");
m_ComBoxProt.InsertString(3, L"自适应");
m_ComBoxProt.SetCurSel(2);
CStatic* pStaticCan = (CStatic*)GetDlgItem(IDC_STATIC_CAN);
pStaticCan->GetClientRect(m_InvaRect);
m_CanRect.left = m_InvaRect.left + m_xspeed;
m_CanRect.right = m_InvaRect.right - m_xspeed;
m_CanRect.top = m_InvaRect.top + m_yspeed;
m_CanRect.bottom = m_InvaRect.bottom - m_yspeed;
}
void CShapeDemoView::OnRButtonUp(UINT nFlags, CPoint point)
{
ClientToScreen(&point);
OnContextMenu(this, point);
}
void CShapeDemoView::OnContextMenu(CWnd* pWnd, CPoint point)
{
}
// CShapeDemoView
#ifdef _DEBUG
void CShapeDemoView::AssertValid() const
{
CFormView::AssertValid();
}
void CShapeDemoView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CShapeDemoDoc* CShapeDemoView::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CShapeDemoDoc)));
return (CShapeDemoDoc*)m_pDocument;
}
#endif //_DEBUG
bool CShapeDemoView::init()
{
if ((!CORBA::is_nil(m_pdpf)) || (!CORBA::is_nil(m_pdp)))
{
return false;
}
ACE::init();
if (CORBA::is_nil(m_pdpf))
{
int argcValue = 3;
char*argvValue[3] = {NULL};
argvValue[0] = "ShapeDemo.exe";
argvValue[1] = "-DCPSConfigFile";
argvValue[2] = "dds_rtps_dis_conf.ini";
m_pdpf = TheParticipantFactoryWithArgs(argcValue, argvValue);
if (CORBA::is_nil(m_pdpf))
{
return false;
}
if (CORBA::is_nil(m_pdp))
{
m_pdp = m_pdpf->create_participant(g_domainId,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(m_pdp))
{
return false;
}
}
if (CORBA::is_nil(m_pservant))
{
m_pservant = new ShapeTypeSupportImpl();
if (DDS::RETCODE_OK != m_pservant->register_type(m_pdp, "Sample"))
{
return false;
}
}
if (CORBA::is_nil(m_topic))
{
CORBA::String_var type_name = m_pservant->get_type_name();
m_topic = m_pdp->create_topic(g_topicname,
type_name.in(),
TOPIC_QOS_DEFAULT,
DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(m_topic.in ()))
{
return false;
}
}
}
SetTimer(DrawFreqTimerId, 98, NULL);
SetTimer(WndUpFreqTimerId, 1000, NULL);
return true;
}
bool CShapeDemoView::CreatePublisher()
{
if ((CORBA::is_nil(m_pdp))||(CORBA::is_nil(m_pservant))||(CORBA::is_nil(m_topic)))
{
return false;
}
m_pub = m_pdp->create_publisher(PUBLISHER_QOS_DEFAULT,
DDS::PublisherListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (m_pub.in()))
{
return false;
}
DDS::DataWriter_var dw = m_pub->create_datawriter(m_topic.in(),
DATAWRITER_QOS_DEFAULT,
DDS::DataWriterListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dw.in ())) {
return false;
}
m_pwrite = ShapeDataWriter::_narrow(dw.in());
if (CORBA::is_nil(m_pwrite))
{
return false;
}
return true;
}
bool CShapeDemoView::CreateSubscriber()
{
if ((CORBA::is_nil(m_pdp))||(CORBA::is_nil(m_pservant))||(CORBA::is_nil(m_topic)))
{
return false;
}
m_sub = m_pdp->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (m_sub.in()))
{
return false;
}
DDS::DataReaderListener_var plistener (new DataReaderListenerImpl);
if (CORBA::is_nil(plistener))
{
return false;
}
DDS::DataReader_var dr = m_sub->create_datareader(m_topic.in(),
DATAREADER_QOS_DEFAULT,
plistener.in(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dr.in()))
{
return false;
}
DataReaderListenerImpl* plistener_servant = dynamic_cast<DataReaderListenerImpl*>(plistener.in());
m_sub_shape = &(plistener_servant->shape_);
m_pdelay = &(plistener_servant->delay_);
return true;
}
bool CShapeDemoView::DeletePublisher()
{
if (CORBA::is_nil (m_pub.in()))
return false;
m_pub->delete_contained_entities();
m_pwrite = NULL;
if (CORBA::is_nil(m_pdp))
return false;
m_pdp->delete_publisher(m_pub.in());
return true;
}
bool CShapeDemoView::DeleteSubscriber()
{
if (CORBA::is_nil (m_sub.in()))
return false;
m_sub->delete_contained_entities();
if (CORBA::is_nil(m_pdp))
return false;
m_pdp->delete_subscriber(