home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #1
/
monster.zip
/
monster
/
OS2
/
LNVREM.ZIP
/
LNREMSRC.EXE
/
LNREMLCH.C
< prev
next >
Wrap
Text File
|
1993-11-09
|
19KB
|
597 lines
/*
* This file was generated by the SOM Compiler.
* FileName: lnremlch.c.
* Generated using:
* SOM Precompiler spc: 1.22
* SOM Emitter emitc: 1.24
*/
/*
* lnremlch.csc
* Copyright (c) International Business Machines Corporation
* 1993
*/
#define LNRemoteLaunch_Class_Source
#include <lnremlch.ih>
CHAR MyID[50];
/*
* Launch remote command for one or more nodes
*/
SOM_Scope int SOMLINK RemoteExecPgm(LNRemoteLaunch *somSelf,
STRING_ARRAY_OBJ *pHier,
SOMAny *pModel,
PVOID pAppParm,
SOMAny *pSelected)
{
char fname[] = "RemoteExecPgm -";
ULONG ulRC; // Return code
STRING_ARRAY_OBJ *Contents; // Management coll contants
int i; // Loop control
PCHAR pCmdBuf; // Command buffer
PCHAR pCmdTail; // Command tail buffer
STARTDATA *pStartData; // StartData pointer
PGCMDSTRUC pCmdStruc; // Command struc pointer
UCHAR PrgTitle[]="Remote Launch";
UCHAR PrgName[256];
UCHAR PrgNameCmdExe[]="C:\\OS2\\CMD.EXE";
UCHAR ObjBuf[100];
PSZ pOutFile;
APIRET DosRc;
LNRemoteLaunchData *somThis = LNRemoteLaunchGetData(somSelf);
LNRemoteLaunchMethodDebug("LNRemoteLaunch","RemoteExecPgm");
printf("%s Top of method\n", fname);
// ---------------------------------------------
// Allocate program inputs and start data structures
// and fill in the blanks
// ---------------------------------------------
pCmdBuf = (PCHAR) malloc(PINPUT_SIZE);
if (pCmdBuf == (PCHAR) NULL) {
printf("%s malloc failed for command buffer\n", fname);
return(0);
} /* endif */
pCmdTail = (PCHAR) malloc(PINPUT_SIZE);
if (pCmdTail == (PCHAR) NULL) {
printf("%s malloc failed for command tail buffer\n", fname);
free(pCmdBuf);
return(0);
} /* endif */
pStartData = (STARTDATA *) malloc(sizeof(STARTDATA));
if (pStartData == (STARTDATA *) NULL) {
printf("%s malloc failed for startdata structure\n", fname);
free(pCmdBuf);
free(pCmdTail);
return(0);
} /* endif */
// ---------------------------------------------
// Get the command string
// ---------------------------------------------
if ((GetCmdString(&pCmdStruc)) != LN_RC_SUCCESSFUL) {
// No command string - put up error screen
printf("%s Calling error message routine\n",fname);
_ErrorMessage(somSelf,
(ULONG) LN_RC_ERR_NO_CMD,
fname,
TRUE);
printf("%s Return from error message routine\n",fname);
free(pStartData);
free(pCmdTail);
free(pCmdBuf);
return(0);
} /* endif */
// ---------------------------------------------
// Get fully-qualified module name
// ---------------------------------------------
DosRc = DosSearchPath(SEARCH_ENVIRONMENT,
"PATH",
"svruncmd.exe",
PrgName,
sizeof(PrgName));
if (DosRc != 0) {
printf("%s DosSearchPath return code was %d\n",fname,DosRc);
} else {
printf("%s Module name is %s\n",fname,PrgName);
} /* endif */
// ---------------------------------------------
// Setup DosStartSession control block
// ---------------------------------------------
pStartData->Length = sizeof(STARTDATA);
pStartData->Related = SSF_RELATED_INDEPENDENT;
pStartData->FgBg = SSF_FGBG_FORE;
pStartData->TraceOpt = SSF_TRACEOPT_NONE;
pStartData->PgmTitle = PrgTitle;
pStartData->PgmName = PrgName;
pStartData->PgmInputs = pCmdBuf;
pStartData->SessionType = SSF_TYPE_DEFAULT;
pStartData->TermQ = 0;
pStartData->Environment = 0;
pStartData->InheritOpt = SSF_INHERTOPT_PARENT;
pStartData->IconFile = 0;
pStartData->PgmHandle = 0;
pStartData->PgmControl = SSF_CONTROL_VISIBLE | SSF_CONTROL_MAXIMIZE;
pStartData->InitXPos = 30;
pStartData->InitYPos = 40;
pStartData->InitXSize = 200;
pStartData->InitYSize = 140;
pStartData->Reserved = 0;
pStartData->ObjectBuffer = ObjBuf;
pStartData->ObjectBuffLen = 100;
// ---------------------------------------------
// Setup SVRUNCMD parameters
// ---------------------------------------------
if (pCmdStruc->Sticky) {
pStartData->PgmName = PrgNameCmdExe; // Use cmd.exe as prog name
sprintf(pCmdBuf,"/K %s /c=\"%s \" ",PrgName,pCmdStruc->Cmd);
} else {
sprintf(pCmdBuf,"/c=\"%s \" ",pCmdStruc->Cmd);
} /* endif */
printf("%s CmdBuf => %s\n",fname,pCmdBuf);
if (pCmdStruc->TimeOut != (PSZ) NULL) {
sprintf(pCmdTail," /t=%s ",pCmdStruc->TimeOut);
} else {
sprintf(pCmdTail," /t=15 ");
} /* endif */
if (pCmdStruc->OutFile != (PSZ) NULL) {
strcat(pCmdTail,"> ");
strcat(pCmdTail,pCmdStruc->OutFile);
} /* endif */
printf("%s CmdTail => %s\n",fname,pCmdTail);
// ---------------------------------------------
// See if we were called from a management collection
// or a system
// ---------------------------------------------
printf("%s Input class is %s\n", fname,pHier->Array[0]);
if ((!strcmp(pHier->Array[0],CL_MD_MDL)) ||
(!strcmp(pHier->Array[0],CL_ALL_SYSTEMS_MDL))) {
Contents = _ConvertContentsToStringArray(pModel,pSelected);
printf("%s Selected list count is %d\n", fname,Contents->Count);
for (i=0; i < Contents->Count; i+=2) { // Loop through sel systems
ulRC = _RemoteCall(somSelf,
Contents->Array[i+1],
pCmdBuf,
pCmdTail,
pStartData,
FALSE);
} /* endfor */
} else { // Must be a system
printf("%s Long name is %s\n", fname,pHier->Array[1]);
ulRC = _RemoteCall(somSelf,
pHier->Array[1],
pCmdBuf,
pCmdTail,
pStartData,
TRUE);
} /* endif */
// ---------------------------------------------
// Clean up allocated buffers
// ---------------------------------------------
free(pStartData);
free(pCmdTail);
free(pCmdBuf);
free(pCmdStruc->Cmd);
if (pCmdStruc->TimeOut != (PSZ) NULL) {
free(pCmdStruc->TimeOut);
} /* endif */
if (pCmdStruc->InFile != (PSZ) NULL) {
free(pCmdStruc->InFile);
} /* endif */
if (pCmdStruc->OutFile != (PSZ) NULL) {
free(pCmdStruc->OutFile);
} /* endif */
free(pCmdStruc);
printf("%s Bottom of method\n", fname);
return (int) 0;
}
/*
* Issue remote call for one node
*/
SOM_Scope int SOMLINK RemoteCall(LNRemoteLaunch *somSelf,
PSZ LongName,
PSZ CmdBuf,
PSZ CmdTail,
STARTDATA *pStartData,
BOOL32 VerboseSwitch)
{
char fname[] = "RemoteCall -";
ULONG ulRC; // Return code
PSZ SystemName; // Displayable system name
BOOL32 NameBufferFlag = FALSE;
ULONG SessID;
PID PID;
APIRET DosRc;
NIDSIDSTRUC NetIDSysID; // Net ID & sys ID structure
LNRemoteLaunchData *somThis = LNRemoteLaunchGetData(somSelf);
LNRemoteLaunchMethodDebug("LNRemoteLaunch","RemoteCall");
printf("%s Top of method\n", fname);
// ---------------------------------------------
// Initialize variables
// ---------------------------------------------
SystemName = (PSZ) NULL;
NetIDSysID.NetID = (PSZ) NULL;
NetIDSysID.SysID = (PSZ) NULL;
printf("%s Long name is %s\n", fname,LongName);
// ---------------------------------------------
// Get the icon title text
// ---------------------------------------------
printf("%s Calling GetShortName for long name %s\n",fname,LongName);
if ((GetShortName((PSZ) LongName, SYSTEM, &SystemName)) != OK) {
//
// No short name? Just use long name
//
printf("%s Using long name\n", fname);
SystemName =
(PSZ) _AllocBuffer(somSelf,strlen(LongName));
strcpy(SystemName,LongName);
NameBufferFlag = TRUE; // Remember I allocated buffer
} /* endif */
printf("%s Using name %s\n", fname,SystemName);
// ---------------------------------------------
// Get net ID and system ID
// ---------------------------------------------
if ((GetNetIDSysID(LongName,&NetIDSysID)) != LN_RC_SUCCESSFUL) {
// No system agent - put up error screen
printf("%s Calling error message routine\n",fname);
_ErrorMessage(somSelf,
(ULONG) LN_RC_ERR_NO_AGENT,
SystemName,
VerboseSwitch);
printf("%s Return from error message routine\n",fname);
} else { // We have a net ID and sys ID
// ---------------------------------------------
// Setup SVRUNCMD parameters
// ---------------------------------------------
strcat(CmdBuf,"/s=");
strcat(CmdBuf,NetIDSysID.SysID);
strcat(CmdBuf," /n=");
strcat(CmdBuf,NetIDSysID.NetID);
strcat(CmdBuf,CmdTail);
printf("%s SVRUNCMD string => %s\n",fname,CmdBuf);
// ---------------------------------------------
// Call DosStartSession
// ---------------------------------------------
printf("%s Calling DosStartSession\n",fname);
DosRc=DosStartSession(pStartData, &SessID, &PID);
// DosRc = 0;
printf("%s Return code from DosStartSession - %d\n",fname,DosRc);
if (DosRc != 0) {
printf("%s Calling error message routine\n",fname);
_ErrorMessage(somSelf,
(ULONG) LN_RC_ERR_RCLI,
SystemName,
VerboseSwitch);
printf("%s Return from error message routine\n",fname);
} /* endif */
} /* endif */
// ---------------------------------------------
// Cleanup buffers
// ---------------------------------------------
//
// Free icon title save buffer
//
if (SystemName != (PSZ) NULL) {
printf("%s Freeing system name buffer\n",fname);
if (NameBufferFlag) { // I allocated the buffer
_FreeBuffer(somSelf,SystemName);
} else { // View allocated the buffer
SOMFree(SystemName);
} /* endif */
} /* endif */
//
// Free net ID and sys ID buffers
//
if (NetIDSysID.NetID != (PSZ) NULL) {
free(NetIDSysID.NetID);
} /* endif */
if (NetIDSysID.SysID != (PSZ) NULL) {
free(NetIDSysID.SysID);
} /* endif */
printf("%s Bottom of method\n", fname);
return (int) 0;
}
/*
* Issue error panels
*/
SOM_Scope VOID SOMLINK ErrorMessage(LNRemoteLaunch *somSelf,
ULONG ErrorCode,
PSZ LongName,
BOOL32 VerboseSwitch)
{
ULONG rc;
char fname[] = "ErrorMessage -";
HAB hab; // PM anchor block handle
HMQ hmq; // PM message queue handle
LNRemoteLaunchData *somThis = LNRemoteLaunchGetData(somSelf);
LNRemoteLaunchMethodDebug("LNRemoteLaunch","ErrorMessage");
printf("%s Top of method\n", fname);
if (VerboseSwitch) {
//
// Allocate PM stuff
//
printf("%s Allocating anchor block\n", fname);
hab = WinInitialize(0);
printf("%s Allocating message queue\n", fname);
hmq = WinCreateMsgQueue(hab,0);
switch (ErrorCode) {
case LN_RC_ERR_NO_AGENT :
printf("%s Calling NoAgentProc\n", fname);
rc = WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, (PFNWP)NoAgentProc,
_ModHandle, IDLG_NO_SAGENT, (PVOID) LongName);
printf("%s Return from NoAgentProc\n", fname);
break;
case LN_RC_ERR_NO_CMD :
rc = WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, (PFNWP)NoCmdProc,
_ModHandle, IDLG_NO_CMD, (PVOID) LongName);
break;
case LN_RC_ERR_RCLI :
rc = WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, (PFNWP)RCLIErrProc,
_ModHandle, IDLG_RCLI_ERR, (PVOID) LongName);
break;
default :
break;
} /* endswitch */
//
// Clean up PM stuff
//
printf("%s Deallocating message queue\n", fname);
WinDestroyMsgQueue(hmq);
printf("%s Deallocating anchor block\n", fname);
WinTerminate(hab);
} /* endif */
printf("%s Bottom of method\n", fname);
}
/*
* Instance setup
*/
SOM_Scope void SOMLINK somInit(LNRemoteLaunch *somSelf)
{
ULONG rc;
char fname[] = "somInit -";
char LoadError[100];
LNRemoteLaunchData *somThis = LNRemoteLaunchGetData(somSelf);
LNRemoteLaunchMethodDebug("LNRemoteLaunch","somInit");
sprintf(MyID,"lnremlch - %d -",somSelf);
printf("%s %s Top of method\n",MyID,fname);
parent_somInit(somSelf);
//
// Get the module handle and save it for use in the PM procs.
//
rc = DosLoadModule(LoadError,
sizeof(LoadError),
"LNREMLCH",
&_ModHandle);
if (rc != 0) {
printf("%s DosQueryModuleHandle rc = %d\n",fname,rc);
} else {
printf("%s ModuleHandle = %d\n",fname,_ModHandle);
} /* endif */
printf("%s %s Bottom of method\n",MyID,fname);
}
/*
* Instance cleanup
*/
SOM_Scope void SOMLINK somUninit(LNRemoteLaunch *somSelf)
{
ULONG rc;
char fname[] = "somUninit -";
LNRemoteLaunchData *somThis = LNRemoteLaunchGetData(somSelf);
LNRemoteLaunchMethodDebug("LNRemoteLaunch","somUninit");
printf("%s %s Top of method\n",MyID,fname);
rc = DosFreeModule(_ModHandle);
printf("%s %s Bottom of method\n",MyID,fname);
parent_somUninit(somSelf);
}
// ----------------------------------------------------------------------
// NoCmdProc
//
// This PM procedure displays the panel for the command not found case
// ----------------------------------------------------------------------
MRESULT EXPENTRY NoCmdProc(HWND hWndDlg,
USHORT message,
MPARAM mp1,
MPARAM mp2)
{
PSZ SysName;
MRESULT fpRC = (MRESULT) FALSE;
CHAR description[256];
USHORT usRc; /* Function return code */
char fname[] = "NoCmdProc -";
switch(message)
{
case WM_INITDLG:
SysName = (PSZ) mp2;
WinSetDlgItemText(hWndDlg, NOCMD_TX_NNAME, SysName);
printf("%s Received %s\n", fname, SysName);
fpRC = (MRESULT) TRUE;
break;
case WM_COMMAND:
switch(SHORT1FROMMP(mp1))
{
case NOCMD_PB_OK: //Ok
WinDismissDlg(hWndDlg, FALSE);
break;
}
break; // End of WM_COMMAND
case WM_CLOSE:
WinDismissDlg(hWndDlg, FALSE);
break; // End of WM_CLOSE
default:
fpRC = WinDefDlgProc(hWndDlg, message, mp1, mp2);
break;
}
return fpRC;
}
// ----------------------------------------------------------------------
// NoAgentProc
//
// This PM procedure displays the panel for the system agent not found case
// ----------------------------------------------------------------------
MRESULT EXPENTRY NoAgentProc(HWND hWndDlg,
USHORT message,
MPARAM mp1,
MPARAM mp2)
{
PSZ SysName;
MRESULT fpRC = (MRESULT) FALSE;
CHAR description[256];
USHORT usRc; /* Function return code */
char fname[] = "NoAgentProc -";
// printf("%s Top of function\n", fname);
switch(message)
{
case WM_INITDLG:
printf("%s Case WM_INITDLG\n", fname);
SysName = (PSZ) mp2;
WinSetDlgItemText(hWndDlg, NSAGT_TX_NNAME, SysName);
printf("%s Received %s\n", fname, SysName);
fpRC = (MRESULT) TRUE;
break;
case WM_COMMAND:
printf("%s Case WM_COMMAND\n", fname);
switch(SHORT1FROMMP(mp1))
{
case NSAGT_PB_OK: //Ok
WinDismissDlg(hWndDlg, FALSE);
break;
}
break; // End of WM_COMMAND
case WM_CLOSE:
printf("%s Case WM_CLOSE\n", fname);
WinDismissDlg(hWndDlg, FALSE);
break; // End of WM_CLOSE
default:
// printf("%s Default case\n", fname);
fpRC = WinDefDlgProc(hWndDlg, message, mp1, mp2);
break;
}
// printf("%s Bottom of function\n", fname);
return fpRC;
}
// ----------------------------------------------------------------------
// RCLIErrProc
//
// This PM procedure displays the panel for a DosStartSession or RCLI error
// ----------------------------------------------------------------------
MRESULT EXPENTRY RCLIErrProc(HWND hWndDlg,
USHORT message,
MPARAM mp1,
MPARAM mp2)
{
PSZ SysName;
MRESULT fpRC = (MRESULT) FALSE;
CHAR description[256];
USHORT usRc; /* Function return code */
char fname[] = "RCLIErrProc -";
switch(message)
{
case WM_INITDLG:
SysName = (PSZ) mp2;
WinSetDlgItemText(hWndDlg, RCERR_TX_NNAME, SysName);
printf("%s Received %s\n", fname, SysName);
fpRC = (MRESULT) TRUE;
break;
case WM_COMMAND:
switch(SHORT1FROMMP(mp1))
{
case RCERR_PB_OK: //Ok
WinDismissDlg(hWndDlg, FALSE);
break;
}
break; // End of WM_COMMAND
case WM_CLOSE:
WinDismissDlg(hWndDlg, FALSE);
break; // End of WM_CLOSE
default:
fpRC = WinDefDlgProc(hWndDlg, message, mp1, mp2);
break;
}
return fpRC;
}
#pragma linkage (SOMInitModule, system)
void SOMInitModule(integer4 MajorVersion, integer4 MinorVersion)
{
LNRemoteLaunchNewClass(0,0);
}