⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getbulk.cpp

📁 HP公司的SNMP++的Win32版本源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	  nextoid = "next ";
	  nextoid += vb.get_printable_oid();
	  lb->InsertString( lb->GetCount(),nextoid);
   }

   // update the output display
   UpdateData( FALSE);

};

// display a timeout message
void GetBulk::display_timeout( SnmpTarget &target)
{
   m_output = "";
   UpdateData( FALSE);
   m_output = "Request Timed Out";
   UpdateData( FALSE);
};


// load up the Ctree control with the MIB table
void GetBulk::load_mib_view( CTreeCtrl *tree)
{
	 CString name;
	 Oid current_oid, parent_oid, next_oid,prev_parent_oid,*oid_ptr;
	 HTREEITEM new_node, parent_node, previous_parent;
	 parent_node = previous_parent = TVI_ROOT;
	 for (int x=0;x<MAXMIBVALS; x++)
	 {
	    name = MIBVals[x][0];								  
		current_oid = MIBVals[x][2];						  
		next_oid = ((x+1)==MAXMIBVALS)?"":MIBVals[x+1][2];	  

		if ( current_oid.len() <= parent_oid.len())
		{
			parent_node = previous_parent;
			parent_oid = prev_parent_oid;
		}

		// add the node
		new_node = tree->InsertItem( name,parent_node);
		oid_ptr = new Oid( current_oid);
		if ( strcmp(MIBVals[x][1],SCALAR)==0)
		   (*oid_ptr)+="0";
		tree->SetItemData( new_node, (DWORD) oid_ptr);

		if ( name == "sysDescr")
		   tree->SelectItem( new_node);

		if (( current_oid.len() > parent_oid.len()) && ( current_oid.len() < next_oid.len()))
		{
		   previous_parent = parent_node;  
		   parent_node = new_node;         
		   prev_parent_oid = parent_oid;
		   parent_oid = current_oid;        
		}
	 };
};

// recursive delete of CtreeCtrl Items
void GetBulk::delete_nodes( CTreeCtrl *tree, HTREEITEM node)
{
    HTREEITEM next_node;
	Oid * oid_ptr;

    next_node = tree->GetChildItem( node);
	if ( next_node != NULL)
		delete_nodes( tree, next_node);
	
	next_node = tree->GetNextSiblingItem( node);
	if ( next_node != NULL)
		delete_nodes( tree, next_node);
	
	oid_ptr = (Oid *) tree->GetItemData( node);
	if ( oid_ptr != NULL)
	   delete oid_ptr;
}


void GetBulk::OnAdd() 
{
	// TODO: Add your control notification handler code here
	CTreeCtrl *tree;
	HTREEITEM node;
	Oid *oid_ptr;

	tree = (CTreeCtrl *) GetDlgItem( IDC_MIBTREE);
	node = tree->GetSelectedItem();
	oid_ptr = (Oid *) tree->GetItemData( node);

	Oid addoid( oid_ptr->get_printable());
	CListBox *lb;
	lb = ( CListBox*) GetDlgItem( IDC_PDU);
	CString scalar;
	scalar = tree->GetItemText( node);
	scalar += " ";
	scalar += addoid.get_printable();
	lb->InsertString( lb->GetCount(),scalar);

}

void GetBulk::OnAddoid() 
{
	// TODO: Add your control notification handler code here
	UpdateData( TRUE);
	Oid oid( m_oid);
	if ( oid.valid())
	{
		CListBox *lb;
	    lb = ( CListBox*) GetDlgItem( IDC_PDU);
	    CString item;
	    item = "Custom ";
	    item += oid.get_printable();
        lb->InsertString( lb->GetCount(),item);
	}
	else
		AfxMessageBox("Invalid Custom MIB Object Identifier");

}

void GetBulk::OnDblclkMibtree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	OnAdd();
	*pResult = 0;
}

void GetBulk::OnRemove() 
{
	// TODO: Add your control notification handler code here
	CListBox *lb;
	int selection;
	lb = ( CListBox*) GetDlgItem( IDC_PDU);

	if((selection = lb->GetCurSel()) != LB_ERR)
		lb->DeleteString( selection);
}

void GetBulk::OnStop() 
{
	// TODO: Add your control notification handler code here
	CButton * mib_walk = (CButton*) GetDlgItem( IDC_AUTOWALK);
	mib_walk->SetCheck(0);
}

void GetBulk::OnGetbulk() 
{
	// TODO: Add your control notification handler code here
	
	//------------------------------------------------------
	// Here is the real SNMP++ code !
	// 
	// Algorithm:
	// - build a Pdu using the Oids from the Pdu list box
	// - create a CTarget
	// - response will come to specified callback
	CListBox *lb;
	int count;
	char buffer[80],*ptr;
	Pdu pdu;          // SNMP++ Pdu object

	// update data to get non repeaters and max repititions
	UpdateData( TRUE);


	// get the ListBox id
	lb = ( CListBox*) GetDlgItem( IDC_PDU);

	// make sure we have something to get
	if ( (count=lb->GetCount()) <1)
	{
		AfxMessageBox("There are No PDU Variables to GetBulk");
		return;
	}

	// build up a SNMP++ Pdu with all the Vbs requested
	for ( int z =0;z<count;z++)
	{
	   // get the text from the listbox
	   lb->GetText(z,buffer);

	   // get rid of the text part
	   ptr = buffer;
	   while (*ptr != ' ') ptr++;
	   ptr++;

	   // make a SNMP++ Oid with the dotted notation
	   Oid oid( ptr);      

	   // make a SNMP++ Vb with the oid
	   Vb vb( oid);

	   // add the vb to the Pdu
	   pdu += vb;
	}


	// make a SnmpTarget using the Target_Factory
	CComboBox *cb = ( CComboBox *) GetDlgItem( IDC_TARGETS);
	char key[80];
    if ( cb->GetCurSel() == CB_ERR)
    {
       AfxMessageBox("No Target Selected!");
       return;
    }
	cb->GetLBText( cb->GetCurSel(), key); 

	// get a target from the target factory
	SnmpTarget *target = target_factory( key);
	if ( target == NULL)
	{
		AfxMessageBox("Unable To find Target");
		return;
	}

	// Invoke a SNMP++ Get for the Pdu requested
	// from the target created
	int status = snmp->get_bulk( pdu,
                            *target,
							m_non_repeaters,
							m_max_repititions,
                            (snmp_callback) &my_getbulkcallback,
                            (void *) this);
                                        
    if ( status != SNMP_CLASS_SUCCESS)
		AfxMessageBox( snmp->error_msg( status));


	// free up the target when complete
	delete target;


	m_output = "SNMP++ GetBulk In Progress...";
	UpdateData( FALSE);

	// disable all controls while get is pending
	enable_controls( FALSE);

}

BOOL GetBulk::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CenterWindow();

	// load up the MIB tree control
	CTreeCtrl *tree;
	tree = (CTreeCtrl *) GetDlgItem( IDC_MIBTREE);
	load_mib_view( tree);

	// clear the pdu table
	CListBox *lb;
	lb= ( CListBox*) GetDlgItem( IDC_PDU);
	lb->ResetContent();	

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void GetBulk::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// need to free up CtreeCtrl's Oids
	CTreeCtrl *tree;
	tree = (CTreeCtrl *) GetDlgItem( IDC_MIBTREE);
	delete_nodes( tree, tree->GetRootItem());

}

void GetBulk::OnSelchangeTargets() 
{
	// TODO: Add your control notification handler code here
	Db target_db;
	TargetDb_Rec db_rec;
	char key[80];
	char *ptr,*address;
	int status;
 
    CComboBox * target_cb = ( CComboBox *) GetDlgItem( IDC_TARGETS);
	target_cb->GetLBText( target_cb->GetCurSel() , key);

	// trim off alias, if present
	address = key;
	ptr = key;
	while (*ptr != 0)
	{
		if ( *ptr == '@')
		   address = ptr+2;
	   ptr++;
	}


    // get the db file name from the ini file
    CString filename = theApp.GetProfileString( BROWSER_VALUE,DB_NAME,DEF_DB_NAME);
	target_db.set_attributtes( filename, sizeof( TargetDb_Rec));
    strcpy( db_rec.key,address);
    status = target_db.read( &db_rec);
    if ( status != DB_OK)
    {
       MessageBox( "Unable to Read Target Record",ERR_MSG,MB_ICONSTOP);
       return;
    }
    load_target_attribs( db_rec);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -