LRESULT CALLBACK StaticProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { POINT pt; static POINT ptLast; switch(msg) { case WM_LBUTTONDBLCLK: case WM_LBUTTONDOWN: ptLast.x = (short)LOWORD(lParam); ptLast.y = (short)HIWORD(lParam); // Ask the callback function if we want to proceed if(FireWndFindNotify(hwnd, WFN_BEGIN, 0) == -1) { return 0; } fDragging = TRUE; SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmapDrag2); hwndCurrent = hwnd; ShowSel(hwndCurrent); SetCapture(hwnd); hOldCursor = SetCursor(hCursor); // Install keyboard hook to trap ESCAPE key // We could just set the focus to this window to receive // normal keyboard messages - however, we don't want to // steal focus from current window when we use the drag tool, // so a hook is a stealthier way to monitor key presses draghookhwnd = hwnd; draghook = SetWindowsHookEx(WH_KEYBOARD, draghookproc, GetModuleHandle(0), 0); // Current window has changed FireWndFindNotify(hwnd, WFN_SELCHANGED, hwndCurrent); return 0; case WM_MOUSEMOVE: pt.x = (short)LOWORD(lParam); pt.y = (short)HIWORD(lParam); if(fDragging == TRUE && ptLast.x != pt.x && ptLast.y != pt.y) { //MoveFindTool(hwnd, wParam, lParam); HWND hWndPoint; ptLast = pt; ClientToScreen(hwnd, (POINT *)&pt); hWndPoint = WindowFromPointEx(pt, fShowHidden); if(hWndPoint == 0) return 0; if(hWndPoint != hwndCurrent) { HideSel(hwndCurrent); //InvertWindow(hwndCurrent, fShowHidden); FireWndFindNotify(hwnd, WFN_SELCHANGED, hWndPoint); //InvertWindow(hWndPoint, fShowHidden); ShowSel(hWndPoint); hwndCurrent = hWndPoint; } } return 0; case WM_LBUTTONUP: // Mouse has been release, so end the find-tool if(fDragging == TRUE) { fDragging = FALSE; EndFindToolDrag(hwnd, wParam, lParam); FireWndFindNotify(hwnd, WFN_END, hwndCurrent); } return 0; // Sent from the keyboard hook case WM_CANCELMODE: // User has pressed ESCAPE, so cancel the find-tool if(fDragging == TRUE) { fDragging = FALSE; EndFindToolDrag(hwnd, wParam, lParam); FireWndFindNotify(hwnd, WFN_CANCELLED, 0); } return 0; case WM_NCDESTROY: // When the last finder tool has been destroyed, free // up all the resources if(InterlockedDecrement(&lRefCount) == 0) { FreeFinderResources(); } break; } return CallWindowProc(oldstaticproc, hwnd, msg, wParam, lParam); }
// Keyboard hook for the Finder Tool. // This hook just monitors the ESCAPE key static LRESULT CALLBACK draghookproc(int code, WPARAM wParam, LPARAM lParam) { ULONG state = (ULONG)lParam; static int count; if(code < 0) return CallNextHookEx(draghook, code, wParam, lParam); switch(wParam) { case VK_ESCAPE: if(!(state & 0x80000000)) { //don't let the current window procedure process a VK_ESCAPE, //because we want it to cancel the mouse capture PostMessage(draghookhwnd, WM_CANCELMODE, 0, 0); return -1; } break; case VK_SHIFT: if(state & 0x80000000) { //InvertWindow(hwndCurrent, fShowHidden); HideSel(hwndCurrent); FireWndFindNotify(draghookhwnd, WFN_SHIFT_UP, 0); //InvertWindow(hwndCurrent, fShowHidden); ShowSel(hwndCurrent); } else { if(!(state & 0x40000000)) { //InvertWindow(hwndCurrent, fShowHidden); HideSel(hwndCurrent); FireWndFindNotify(draghookhwnd, WFN_SHIFT_DOWN, 0); //InvertWindow(hwndCurrent, fShowHidden); ShowSel(hwndCurrent); } } return -1; case VK_CONTROL: if(state & 0x80000000) { //InvertWindow(hwndCurrent, fShowHidden); HideSel(hwndCurrent); FireWndFindNotify(draghookhwnd, WFN_CTRL_UP, 0); //InvertWindow(hwndCurrent, fShowHidden); ShowSel(hwndCurrent); } else { if(!(state & 0x40000000)) { //InvertWindow(hwndCurrent, fShowHidden); HideSel(hwndCurrent); FireWndFindNotify(draghookhwnd, WFN_CTRL_DOWN, 0); //InvertWindow(hwndCurrent, fShowHidden); ShowSel(hwndCurrent); } } return -1; } // Test to see if a key is pressed for first time if(!(state & 0xC0000000)) { // Find ASCII character UINT ch = MapVirtualKey((UINT)wParam, 2); if(ch == _T('c') || ch == _T('C')) { //InvertWindow(hwndCurrent, fShowHidden); HideSel(hwndCurrent); CaptureWindow(GetParent(draghookhwnd), hwndCurrent); //InvertWindow(hwndCurrent, fShowHidden); ShowSel(hwndCurrent); return -1; } } return CallNextHookEx(draghook, code, wParam, lParam); }
int main(int argc, char **argv) { char c; SaErrorT rv; SaHpiVersionT hpiVer; SaHpiSessionIdT sessionid; SaHpiRptInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiSelEntryIdT entryid; SaHpiSelEntryIdT nextentryid; SaHpiSelEntryIdT preventryid; SaHpiSelInfoT info; SaHpiSelEntryT sel; SaHpiRdrT rdr; printf("%s: version %s\n",argv[0],progver); while ( (c = getopt( argc, argv,"cx?")) != EOF ) switch(c) { case 'c': fclear = 1; break; case 'x': fdebug = 1; break; default: printf("Usage %s [-cx]\n",argv[0]); printf("where -c clears the event log\n"); printf(" -x displays eXtra debug messages\n"); exit(1); } rv = saHpiInitialize(&hpiVer); if (rv != SA_OK) { printf("saHpiInitialize: %s\n",decode_error(rv)); exit(-1); } rv = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID,&sessionid,NULL); if (rv != SA_OK) { if (rv == SA_ERR_HPI_ERROR) printf("saHpiSessionOpen: error %d, SpiLibd not running\n",rv); else printf("saHpiSessionOpen: %s\n",decode_error(rv)); exit(-1); } rv = saHpiResourcesDiscover(sessionid); if (fdebug) printf("saHpiResourcesDiscover %s\n",decode_error(rv)); rv = saHpiRptInfoGet(sessionid,&rptinfo); if (fdebug) printf("saHpiRptInfoGet %s\n",decode_error(rv)); printf("RptInfo: UpdateCount = %d, UpdateTime = %lx\n", rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp); #ifdef BUGGY /* ARC: Bug here in OpenHPI required re-doing discovery as a workaround. */ #endif /* walk the RPT list */ rptentryid = SAHPI_OLDEST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry); if (fdebug) printf("saHpiRptEntryGet %s\n",decode_error(rv)); if (rv == SA_OK) { resourceid = rptentry.ResourceId; if (fdebug) printf("RPT %x capabilities = %x\n", resourceid, rptentry.ResourceCapabilities); if ((rptentry.ResourceCapabilities & SAHPI_CAPABILITY_SEL) == 0) continue; /* no SEL here, try next RPT */ if (fclear) { rv = saHpiEventLogClear(sessionid,resourceid); if (rv == SA_OK) printf("EventLog successfully cleared\n"); else printf("EventLog clear, error = %d\n",rv); break; } rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; printf("rptentry[%d] tag: %s\n", resourceid,rptentry.ResourceTag.Data); rv = saHpiEventLogInfoGet(sessionid,resourceid,&info); if (fdebug) printf("saHpiEventLogInfoGet %s\n",decode_error(rv)); if (rv == SA_OK) { /* This data isn't reliable yet with Spi beta2 implementation */ /* Use the entryid instead to calculate log size below. */ printf("EventLog entries=%d, size=%d, enabled=%d\n", info.Entries,info.Size,info.Enabled); } entryid = SAHPI_OLDEST_ENTRY; while ((rv == SA_OK) && (entryid != SAHPI_NO_MORE_ENTRIES)) { rv = saHpiEventLogEntryGet(sessionid,resourceid,entryid, &preventryid,&nextentryid,&sel,&rdr,NULL); if (fdebug) printf("saHpiEventLogEntryGet %s\n", decode_error(rv)); if (rv == SA_OK) { ShowSel(&sel, &rdr, &rptentry); preventryid = entryid; entryid = nextentryid; } } if (preventryid >= 0xff80) { int free; /* * This test could be more generic if the log info fields above * were accurate. IPMI SEL logs have a fixed size of 0x10000 * bytes. New log records are thrown away when it gets full. * (OLDEST = 0, NO_MORE = fffffffe , so these are ok.) */ free = (0x10000 - 20) - preventryid; printf("WARNING: Log free space is very low (%d bytes)\n" " Clear log with hpisel -c\n",free); } rptentryid = nextrptentryid; } } rv = saHpiSessionClose(sessionid); rv = saHpiFinalize(); exit(0); return(0); }
int main(int argc, char **argv) { int c; SaErrorT rv; SaHpiVersionT hpiVer; SaHpiSessionIdT sessionid; SaHpiRptInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiSelEntryIdT entryid; SaHpiSelEntryIdT nextentryid; SaHpiSelEntryIdT preventryid; SaHpiSelInfoT info; SaHpiSelEntryT sel; SaHpiRdrT rdr; int free = 50; printf("%s: version %s\n",argv[0],progver); while ( (c = getopt( argc, argv,"cx?")) != EOF ) switch(c) { case 'c': fclear = 1; break; case 'x': fdebug = 1; break; default: printf("Usage %s [-cx]\n",argv[0]); printf("where -c clears the event log\n"); printf(" -x displays eXtra debug messages\n"); exit(1); } rv = saHpiInitialize(&hpiVer); if (rv != SA_OK) { printf("saHpiInitialize: %s\n",decode_error(rv)); exit(-1); } rv = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID,&sessionid,NULL); if (rv != SA_OK) { if (rv == SA_ERR_HPI_ERROR) printf("saHpiSessionOpen: error %d, SpiLibd not running\n",rv); else printf("saHpiSessionOpen: %s\n",decode_error(rv)); exit(-1); } rv = saHpiResourcesDiscover(sessionid); if (fdebug) printf("saHpiResourcesDiscover %s\n",decode_error(rv)); rv = saHpiRptInfoGet(sessionid,&rptinfo); if (fdebug) printf("saHpiRptInfoGet %s\n",decode_error(rv)); printf("RptInfo: UpdateCount = %d, UpdateTime = %lx\n", rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp); /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry); if (fdebug) printf("saHpiRptEntryGet %s\n",decode_error(rv)); if (rv == SA_OK) { resourceid = rptentry.ResourceId; if (fdebug) printf("RPT %d capabilities = %x\n", resourceid, rptentry.ResourceCapabilities); if (!(rptentry.ResourceCapabilities & SAHPI_CAPABILITY_SEL)) { if (fdebug) printf("RPT doesn't have SEL\n"); rptentryid = nextrptentryid; continue; /* no SEL here, try next RPT */ } rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; printf("rptentry[%d] tag: %s\n", resourceid,rptentry.ResourceTag.Data); /* initialize structure */ info.Entries = 0; info.Size = 0; info.Enabled = 0; rv = saHpiEventLogInfoGet(sessionid,resourceid,&info); if (fdebug) printf("saHpiEventLogInfoGet %s\n",decode_error(rv)); if (rv == SA_OK) { char date[30]; printf("EventLog entries=%d, size=%d, enabled=%d\n", info.Entries,info.Size,info.Enabled); free = info.Size - info.Entries; saftime2str(info.UpdateTimestamp,date,30); printf("UpdateTime = %s, ", date); saftime2str(info.CurrentTime,date,30); printf("CurrentTime = %s\n", date); printf("Overflow = %d\n", info.OverflowFlag); printf("DeleteEntrySupported = %d\n", info.DeleteEntrySupported); } if (fclear) { rv = saHpiEventLogClear(sessionid,resourceid); if (rv == SA_OK) printf("EventLog successfully cleared\n"); else printf("EventLog clear, error = %d, %s\n",rv, decode_error(rv)); break; } if (info.Entries != 0){ entryid = SAHPI_OLDEST_ENTRY; while ((rv == SA_OK) && (entryid != SAHPI_NO_MORE_ENTRIES)) { rv = saHpiEventLogEntryGet(sessionid,resourceid, entryid,&preventryid,&nextentryid, &sel,&rdr,NULL); if (fdebug) printf("saHpiEventLogEntryGet %s\n", decode_error(rv)); if (rv == SA_OK) { ShowSel(&sel, &rdr, &rptentry); preventryid = entryid; entryid = nextentryid; } } } else printf("SEL is empty\n"); if (free < 6) { printf("WARNING: Log free space is very low (%d records)\n",free); printf("\tClear log with hpisel -c\n"); } rptentryid = nextrptentryid; } } printf("done.\n"); rv = saHpiSessionClose(sessionid); rv = saHpiFinalize(); // exit(0); return(0); }
static int sa_show_evtlog(SaHpiResourceIdT resourceid) { SaErrorT rv = SA_OK; SaHpiSelInfoT info; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiSelEntryIdT entryid; SaHpiSelEntryIdT nextentryid; SaHpiSelEntryIdT preventryid; SaHpiSelEntryT sel; SaHpiRdrT rdr; char date[30]; rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry); if (!(rptentry.ResourceCapabilities & SAHPI_CAPABILITY_SEL)) { rptentryid = nextrptentryid; continue; /* no SEL here, try next RPT */ } if (rptentry.ResourceId == resourceid) { break; } rptentryid = nextrptentryid; } if ((rv != SA_OK) || (rptentryid == SAHPI_LAST_ENTRY)) { printf("The designated resource hasn't SEL.\n"); return SA_OK; } rv = saHpiEventLogInfoGet(sessionid,resourceid,&info); if (rv != SA_OK) { printf("saHpiEventLogInfoGet error %d\n",rv); return -1; } printf("EventLog entries=%d, size=%d, enabled=%d\n", info.Entries,info.Size,info.Enabled); saftime2str(info.UpdateTimestamp,date,30); printf("UpdateTime = %s, ", date); saftime2str(info.CurrentTime,date,30); printf("CurrentTime = %s\n", date); printf("Overflow = %d\n", info.OverflowFlag); printf("DeleteEntrySupported = %d\n", info.DeleteEntrySupported); if (info.Entries != 0){ entryid = SAHPI_OLDEST_ENTRY; while (entryid != SAHPI_NO_MORE_ENTRIES) { rv = saHpiEventLogEntryGet(sessionid,resourceid, entryid,&preventryid,&nextentryid, &sel,&rdr,NULL); if (rv != SA_OK) { printf("saHpiEventLogEntryGet error %d\n",rv); return -1; } ShowSel(&sel, &rdr, &rptentry); preventryid = entryid; entryid = nextentryid; } } else printf("SEL is empty\n"); return SA_OK; }