📄 xmibform.cpp
字号:
/* Copyright (c) 1999 Hewlett-Packard Company ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS. Permission to use, copy, modify, distribute and/or sell this software and/or its documentation is hereby granted without fee. User agrees to display the above copyright notice and this license notice in all copies of the software and any documentation of the software. User agrees to assume all liability for the use of the software; Hewlett-Packard makes no representations about the suitability of this software for any purpose. It is provided "AS-IS" without warranty of any kind,either express or implied. User hereby grants a royalty-free license to any and all derivatives based upon this software code base.*/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <Xm/Xm.h>#include <Xm/MwmUtil.h>#include <X11/Shell.h>#include <Xm/MenuShell.h>#include <Xm/PushB.h>#include <Xm/Text.h>#include <Xm/ScrolledW.h>#include <Xm/MessageB.h>#include <Xm/TextF.h>#include <Xm/Label.h>#include <Xm/Form.h>#include <snmp_pp.h>#include "xmibform.h"extern Widget UxTopLevel;extern Snmp *the_Session;extern Widget FormHandle;static Widget dialogWgt = NULL;void ErrorDialog(char *errorString){ Widget tmpWgt; Arg args[5]; int i=0; XmString message; XmString title; message = XmStringCreateSimple(errorString); title = XmStringCreateSimple("Error"); /*---------------------------------------------------------------*/ /* Create a standard Motif message box, but hide the Cancel and */ /* Help buttons, because the user just gets to look at the error */ /* no other action is available... */ /*---------------------------------------------------------------*/ if (dialogWgt == NULL){ XtSetArg(args[i], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); i++; XtSetArg(args[i], XmNdialogTitle, title); i++; dialogWgt = XmCreateErrorDialog(FormHandle, "errorDialog", args, i); tmpWgt = XmMessageBoxGetChild(dialogWgt, XmDIALOG_CANCEL_BUTTON); XtUnmanageChild(tmpWgt); tmpWgt = XmMessageBoxGetChild(dialogWgt, XmDIALOG_HELP_BUTTON); XtUnmanageChild(tmpWgt); } XtVaSetValues(dialogWgt, XmNmessageString, message, NULL); /*-----------------------------------------*/ /* Toss the strings... Can we do this yet? */ /*-----------------------------------------*/ XmStringFree(message); XmStringFree(title); /*------------------------*/ /* Now display the window */ /*------------------------*/ XtManageChild(dialogWgt);}void GetNextCB( int reason, Snmp *, Pdu &pdu, SnmpTarget &, void *cd){ Vb nextVb; char buf[200]; CQueryForm *displayForm = (CQueryForm *) cd; int pdu_error; displayForm->enableGetNext(); if (reason != SNMP_CLASS_ASYNC_RESPONSE){ sprintf(buf, "Error returned by GetNext:\n %s", the_Session->error_msg(reason)); ErrorDialog(buf); displayForm->displayText(buf); displayForm->displayText("\n\n"); return; } pdu_error = pdu.get_error_status(); if (pdu_error){ sprintf(buf, "Response contains error:\n %s", the_Session->error_msg(pdu_error)); ErrorDialog(buf); displayForm->displayText(buf); displayForm->displayText("\n\n"); return; } pdu.get_vb(nextVb, 0); sprintf(buf, " %s: %s\n\n", nextVb.get_printable_oid(), nextVb.get_printable_value()); displayForm->displayText(buf); displayForm->updateOid(nextVb.get_printable_oid());}void IssueGetNext(char *hostname, char *oid, CQueryForm *displayForm){ IpAddress dest(hostname); int status; if (!dest.valid()){ char buf[100]; sprintf(buf, "Couldn't resolve hostname for: %s", hostname); ErrorDialog(buf); displayForm->displayText(buf); displayForm->displayText("\n\n"); displayForm->enableGetNext(); return; } CTarget target(dest); Vb vb(oid); Pdu pdu; pdu += vb; status = the_Session->get_next(pdu, target, GetNextCB, (void *) displayForm); if (status){ char buf[100]; sprintf(buf, "Error issuing GetNext:\n %s", the_Session->error_msg(status)); ErrorDialog(buf); displayForm->displayText(buf); displayForm->displayText("\n\n"); displayForm->enableGetNext(); return; }}/******************************************************************************* The following are callback functions.*******************************************************************************/void CQueryForm :: activateCB_pbQuery( Widget /*wgt*/, XtPointer, XtPointer){ char *hostname; char *oidname; char buf[100]; hostname = XmTextFieldGetString(tfHostname); oidname = XmTextFieldGetString(tfOid); sprintf(buf, "Issuing GetNext(%s) to %s...\n", oidname, hostname); displayText(buf); disableGetNext(); IssueGetNext(hostname, oidname, this);}void CQueryForm :: Wrap_activateCB_pbQuery( Widget wgt, XtPointer cd, XtPointer cb){ CQueryForm *UxContext; UxContext = (CQueryForm *) cd; UxContext->activateCB_pbQuery(wgt, cd, cb);}void CQueryForm :: activateCB_pbQuit( Widget, XtPointer, XtPointer){ exit(0);}void CQueryForm :: Wrap_activateCB_pbQuit( Widget wgt, XtPointer cd, XtPointer cb){ CQueryForm *UxContext; UxContext = (CQueryForm *) cd; UxContext->activateCB_pbQuit(wgt, cd, cb);}/******************************************************************************* The 'buildWidgets' function creates all the widgets for the main screen.*******************************************************************************/Widget CQueryForm::buildWidgets(){ Widget theShell; // Creation of form1 theShell = XtVaCreatePopupShell( "form1_shell", applicationShellWidgetClass, UxTopLevel, XmNx, 140, XmNy, 370, XmNwidth, 600, XmNheight, 380, XmNshellUnitType, XmPIXELS, XmNtitle, "SNMP Query", NULL ); form1 = XtVaCreateManagedWidget( "form1", xmFormWidgetClass, theShell, XmNwidth, 440, XmNheight, 380, XmNresizePolicy, XmRESIZE_NONE, XmNunitType, XmPIXELS, NULL ); // Creation of lHost lHost = XtVaCreateManagedWidget( "lHost", xmLabelWidgetClass, form1, XmNx, 10, XmNy, 10, XmNwidth, 110, XmNheight, 40, RES_CONVERT( XmNlabelString, "Hostname" ), NULL ); // Creation of tfHostname tfHostname = XtVaCreateManagedWidget( "tfHostname", xmTextFieldWidgetClass, form1, XmNwidth, 290, XmNx, 130, XmNy, 10, XmNheight, 40, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, lHost, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 10, NULL ); char hostnamebuf[100]; gethostname(hostnamebuf, 100); XmTextFieldSetString(tfHostname, hostnamebuf); // Creation of lOid lOid = XtVaCreateManagedWidget( "lOid", xmLabelWidgetClass, form1, XmNx, 10, XmNy, 70, XmNwidth, 110, XmNheight, 40, RES_CONVERT( XmNlabelString, "Object Id:" ), NULL ); // Creation of tfOid tfOid = XtVaCreateManagedWidget( "tfOid", xmTextFieldWidgetClass, form1, XmNwidth, 430, XmNx, 120, XmNy, 70, XmNheight, 40, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, lOid, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 10, NULL ); XmTextFieldSetString(tfOid, "1"); // Creation of scrolledWindowText scrolledWindowText = XtVaCreateManagedWidget( "scrolledWindowText", xmScrolledWindowWidgetClass, form1, XmNscrollingPolicy, XmAPPLICATION_DEFINED, XmNvisualPolicy, XmVARIABLE, XmNscrollBarDisplayPolicy, XmSTATIC, XmNx, 30, XmNy, 160, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 60, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 10, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 20, XmNtopAttachment, XmATTACH_WIDGET, XmNtopOffset, 20, XmNtopWidget, lOid, NULL ); // Creation of scrolledText scrolledText = XtVaCreateManagedWidget( "scrolledText", xmTextWidgetClass, scrolledWindowText, XmNwidth, 500, XmNheight, 160, XmNeditMode, XmMULTI_LINE_EDIT , XmNeditable, FALSE, NULL ); // Creation of pbQuery pbQuery = XtVaCreateManagedWidget( "pbQuery", xmPushButtonWidgetClass, form1, XmNx, 20, XmNy, 330, XmNwidth, 150, XmNheight, 40, RES_CONVERT( XmNlabelString, "Get Next" ), XmNsensitive, TRUE, XmNbottomAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNtopAttachment, XmATTACH_NONE, XmNtopOffset, 0, XmNbottomOffset, 10, NULL ); XtAddCallback( pbQuery, XmNactivateCallback, (XtCallbackProc) &CQueryForm::Wrap_activateCB_pbQuery, (XtPointer) this ); // Creation of pbQuit pbQuit = XtVaCreateManagedWidget( "pbQuit", xmPushButtonWidgetClass, form1, XmNx, 390, XmNy, 330, XmNwidth, 150, XmNheight, 40, RES_CONVERT( XmNlabelString, "Quit" ), XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 10, XmNleftAttachment, XmATTACH_NONE, XmNleftOffset, 0, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 10, XmNtopAttachment, XmATTACH_NONE, XmNtopOffset, 0, NULL ); XtAddCallback( pbQuit, XmNactivateCallback, (XtCallbackProc) &CQueryForm::Wrap_activateCB_pbQuit, (XtPointer) this ); return ( theShell );}/******************************************************************************* The following is the constructor function.*******************************************************************************/CQueryForm::CQueryForm( Widget UxParent ){ this->UxParent = UxParent;}/******************************************************************************* The following is the procedural creation function. This is used instead of the constructor. No real good reason for this...*******************************************************************************/Widget create_form1( Widget UxParent ){ CQueryForm *theInterface = new CQueryForm( UxParent ); return (theInterface->buildWidgets());}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -