AccountTradeInfo::AccountTradeInfo(Account *pAccount,Instrument *pInstrument,PositionCost *pPositionCost) :m_pAccount(pAccount),m_pInstrument(pInstrument),m_pPositionCost(pPositionCost), m_bOrderLoaded(false),m_bPositionLoaded(false),m_bTransactionLoaded(false) { LoadPositions(); LoadTradeDayOrders(); LoadTradeDayTransactions(); }
bool QueryState::NextDocument(){ if(!position_loaded && docid>=0){ LoadPositions();// Bypass } position_loaded = false; positions.clear(); docid = -1; if(pos>=buffer) return false; int *did = (int*)pos; docid = *did; pos += sizeof(int); return true; }
VOID vJoy_EvtIoDeviceControlForRawPdo( IN WDFQUEUE Queue, IN WDFREQUEST Request, IN size_t OutputBufferLength, IN size_t InputBufferLength, IN ULONG IoControlCode ) /*++ Routine Description: This routine is the dispatch routine for device control requests. Arguments: Queue - Handle to the framework queue object that is associated with the I/O request. Request - Handle to a framework request object. OutputBufferLength - length of the request's output buffer, if an output buffer is available. InputBufferLength - length of the request's input buffer, if an input buffer is available. IoControlCode - the driver-defined or system-defined I/O control code (IOCTL) that is associated with the request. Return Value: VOID --*/ { NTSTATUS status = STATUS_SUCCESS; WDFDEVICE parent; WDF_REQUEST_FORWARD_OPTIONS forwardOptions; PDEVICE_EXTENSION pDevContext = NULL; WDFMEMORY inMemory, outMemory; PVOID buffer; size_t bufSize; WDFDEVICE hRawDevice = WdfIoQueueGetDevice(Queue); PRPDO_DEVICE_DATA pdoData = PdoGetData(hRawDevice); WDF_REQUEST_SEND_OPTIONS RequestOptions; WDFIOTARGET TargetOnParent; JOYSTICK_POSITION_V2 * iReport; WDFFILEOBJECT FileObj; USHORT id=0; PFILEOBJECT_EXTENSION pExtension=NULL; WDFREQUEST requestForceFeedback; PHID_XFER_PACKET transferPacket = NULL; PVOID ForceFeedbackBuffer = NULL; PVOID GenBuffer = NULL; size_t bytesReturned = 0; WDF_REQUEST_PARAMETERS Params; BOOLEAN FfbStat = FALSE; ULONG bytesToCopy = 0; BYTE Byte_tmp; UNREFERENCED_PARAMETER(OutputBufferLength); UNREFERENCED_PARAMETER(InputBufferLength); TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "Entered vJoy_EvtIoDeviceControlForRawPdo\n"); // // Process the ioctl and complete it when you are done. // Since the queue is configured for serial dispatch, you will // not receive another ioctl request until you complete this one. // switch (IoControlCode) { case 1234: // TODO: Remove for production //RequestOptions.Flags = WDF_REQUEST_SEND_OPTION_TIMEOUT; //RequestOptions.Size = sizeof(WDF_REQUEST_SEND_OPTIONS); //WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(&RequestOptions, WDF_REL_TIMEOUT_IN_SEC(1)); //status = WdfIoTargetSendInternalIoctlSynchronously(pdoData->IoTargetToParent, Request, IoControlCode , NULL, NULL, &RequestOptions, NULL); break; // Testing case GET_DEV_STAT: // Get information for a device by device ID TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: Case GET_DEV_STAT\n"); // Get the buffer from the request // Get the data from the request WDF_REQUEST_PARAMETERS_INIT(&Params); WdfRequestGetParameters(Request, &Params); bytesToCopy = Params.Parameters.DeviceIoControl.OutputBufferLength; if (bytesToCopy<5) { TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo[GET_DEV_STAT]: failed - bytesToCopy=%d\n", bytesToCopy); WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // Get the buffer status = WdfRequestRetrieveOutputBuffer(Request, bytesToCopy, &GenBuffer, &bytesReturned); if (bytesReturned<5) { TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo[GET_DEV_STAT]: failed - bytesReturned=%d\n", bytesReturned); WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // Get the id number from input buffer status = WdfRequestRetrieveInputBuffer(Request, sizeof(BYTE), &buffer, &bufSize); if (!NT_SUCCESS(status) || (bufSize!=1)) { TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo[GET_DEV_STAT]: failed to retrieve input buffer\n"); WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // Get target ID id = *(BYTE *)buffer; TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo[GET_DEV_STAT]: id=%d\n", id); // Put data into output buffer // Byte 1: // Bit 0: Implemented? // Bit 1: FFB Device Enabled? // Bit 2: File Object associated with this device? pDevContext = GetDeviceContext(pdoData->hParentDevice); Byte_tmp = 0; // Implemented mask if (pDevContext->DeviceImplemented[id - 1]) Byte_tmp |= 1; else Byte_tmp &= 0xFE; TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo[GET_DEV_STAT]: Dev Implemented=%x\n", pDevContext->DeviceImplemented[id - 1]); // FFB mask TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo[GET_DEV_STAT]: Dev Enabled=%x\n", pDevContext->FfbEnable[id - 1]); if (pDevContext->FfbEnable[id - 1]) Byte_tmp |= 2; else Byte_tmp &= 0xFD; // File Object if (pDevContext->DeviceFileObject[id - 1]) Byte_tmp |= 4; else Byte_tmp &= 0xFB; ((BYTE *)GenBuffer)[0] = Byte_tmp; TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo[GET_DEV_STAT]: Buffer[0]=%x\n", ((BYTE *)GenBuffer)[0]); // Byte2-5: Process ID // Get the context FileObj = pDevContext->DeviceFileObject[id - 1]; if (FileObj) *(DWORD *)(&((BYTE *)GenBuffer)[1]) = GetFileObjectContext(FileObj)->CallingProcessId; else *(DWORD *)(&((BYTE *)GenBuffer)[1]) = 0; TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo[GET_DEV_STAT]: ProcessID=%x\n", *(DWORD *)(&((BYTE *)GenBuffer)[1])); // Complete the transaction WdfRequestCompleteWithInformation(Request, status, bytesReturned); return; case GET_DRV_INFO: // Get information for this driver TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: [GET_DRV_INFO]\n"); // Get the buffer from the request // Get the data from the request WDF_REQUEST_PARAMETERS_INIT(&Params); WdfRequestGetParameters(Request, &Params); // Number of bytes to copy must be at least one byte bytesToCopy = Params.Parameters.DeviceIoControl.OutputBufferLength; if (bytesToCopy <1 ) { TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: [GET_DRV_INFO] - bytesToCopy <1\n"); WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // Output buffer must be at least one byte status = WdfRequestRetrieveOutputBuffer(Request, bytesToCopy, &GenBuffer, &bytesReturned); if (bytesReturned<1) { TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: [GET_DRV_INFO] - bytesReturned <1\n"); WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; pDevContext = GetDeviceContext(pdoData->hParentDevice); // Return the data in the output buffer // BYTE 0 ////////////////////////////// // Bit 0 : Supports FFB? // Bit 1 : Reserved // Bit 2 : Mode: Multi-device // Bit 3 : Mode: FFB // BYTE 1 ////////////////////////////// // Bits 0-7 : Maximum number of possible devices (16 ==> 255) not regarding to mode // BYTE 2 ////////////////////////////// // Bits 0-7 : Number of existing devices // BYTE 3 ////////////////////////////// // Bits 0-7 : Number of devices that can still be implemented (This is the number of possible devices for the current mode minus the number of already existing devices). ////////////////////////////////// // Byte 0 Byte_tmp = 0; Byte_tmp |= 0x01; // FFB Supported Byte_tmp |= 0x00; // Default Mode (TODO: Change to real mode when Implemented) Multi-Device=0x04; FFB=0x80 ((BYTE *)GenBuffer)[0] = Byte_tmp; // Byte 1 if (bytesToCopy >= 2 && bytesReturned >= 2) { ((BYTE *)GenBuffer)[1] = MAX_N_DEVICES; TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: [GET_DRV_INFO] - Data byte[1]=%02x\n", ((BYTE *)GenBuffer)[1]); } // Byte 2 if (bytesToCopy >= 3 && bytesReturned >= 3) { ((BYTE *)GenBuffer)[2] = (BYTE)(pDevContext->nDevices); TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: [GET_DRV_INFO] - Data byte[2]=%02x\n", ((BYTE *)GenBuffer)[2]); } // Byte 3 - TODO: Change according to mode if (bytesToCopy >= 4 && bytesReturned >= 4) { ((BYTE *)GenBuffer)[3] = MAX_N_DEVICES - (BYTE)(pDevContext->nDevices); TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: [GET_DRV_INFO] - Data byte[3]=%02x\n", ((BYTE *)GenBuffer)[3]); } ////////////////////////////////// // Complete the transaction WdfRequestCompleteWithInformation(Request, status, bytesReturned); return; case GET_DEV_INFO: // Get information for this device (and for the driver) // Get the buffer from the request // Get the data from the request WDF_REQUEST_PARAMETERS_INIT(&Params); WdfRequestGetParameters(Request, &Params); bytesToCopy = Params.Parameters.DeviceIoControl.OutputBufferLength; if (bytesToCopy<6) { WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; status = WdfRequestRetrieveOutputBuffer(Request, bytesToCopy, &GenBuffer, &bytesReturned); if (bytesReturned<6) { WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // Get the context, id and the status id = GetIdFromRawPdoRequest(Request, pExtension); // Illegal ID if (id == 0xFFFF) { WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // Copy the state to the buffer pDevContext = GetDeviceContext(pdoData->hParentDevice); ((BYTE *)GenBuffer)[0] = (BYTE)id; ((BYTE *)GenBuffer)[1] = (BYTE)(pDevContext->nDevices); ((BYTE *)GenBuffer)[2] = pDevContext->DeviceImplemented ? 1:0; ((BYTE *)GenBuffer)[3] = MAX_N_DEVICES; ((BYTE *)GenBuffer)[4] = 1; // Driver does support FFB ((BYTE *)GenBuffer)[5] = pDevContext->FfbEnable[id - 1]; // Device support FFB // Complete the transaction WdfRequestCompleteWithInformation(Request, status, bytesReturned); return; case 0x910: // Backward compatibility value of LOAD_POSITIONS case LOAD_POSITIONS: // KdBreakPoint(); Break When loading position status = WdfRequestRetrieveInputBuffer( Request, sizeof(JOYSTICK_POSITION), &buffer, &bufSize); if(!NT_SUCCESS(status)) break; // Get interface that this IRP came from, // then get the implicated id of the top-level collection id = GetIdFromRawPdoRequest(Request, pExtension); // Illegal ID if (id==0xFFFF) { WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // Get the incoming report and compare the id in the report // to the implicated id of the top-level collection // They should match iReport = buffer; if (iReport->bDevice != id) { WdfRequestComplete(Request, STATUS_CANCELLED); return; }; pDevContext = GetDeviceContext(pdoData->hParentDevice); LoadPositions(iReport, pDevContext, bufSize); status = vJoyCompleteReadReport(pdoData->hParentDevice, (BYTE)id); break; case GET_FFB_STAT: /* Get the status of the FFB mechanism */ // Get the buffer from the request // Get the data from the request WDF_REQUEST_PARAMETERS_INIT(&Params); WdfRequestGetParameters(Request, &Params); bytesToCopy = Params.Parameters.DeviceIoControl.OutputBufferLength; status = WdfRequestRetrieveOutputBuffer(Request, bytesToCopy, &GenBuffer, &bytesReturned); if (!bytesReturned) { WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // Get the context, id and the status id = GetIdFromRawPdoRequest(Request, pExtension); // Illegal ID if (id == 0xFFFF) { WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // Copy the state to the buffer pDevContext = GetDeviceContext(pdoData->hParentDevice); ((BYTE *)GenBuffer)[0] = pDevContext->FfbEnable[id-1]; // Complete the transaction WdfRequestCompleteWithInformation(Request, status, bytesReturned); return; case SET_FFB_STAT: /*Set the status of the FFB mechanism - Obsolete*/ // Get the data from the request WDF_REQUEST_PARAMETERS_INIT(&Params); WdfRequestGetParameters(Request, &Params); // Get interface that this IRP came from, // then get the implicated id of the top-level collection // Get the context, id and the status id = GetIdFromRawPdoRequest(Request, pExtension); // Illegal ID if (id == 0xFFFF) { WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // Get the data, process the data and complete the transaction //pDevContext = GetDeviceContext(pdoData->hParentDevice); - Obsolete //FfbActiveSet(*(BOOLEAN *)Params.Parameters.DeviceIoControl.Type3InputBuffer, id, pDevContext); - Obsolete WdfRequestComplete(Request, status); return; case GET_FFB_DATA: // Get interface that this IRP came from, // then get the implicated id of the top-level collection id = GetIdFromRawPdoRequest(Request, pExtension); // If FFB is not active then just reject this request pDevContext = GetDeviceContext(pdoData->hParentDevice); if (id == 0xFFFF || !pDevContext->FfbEnable[id - 1]) { WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // If FFB is active then forward this request to the ReadQ and return status = WdfRequestForwardToIoQueue(Request, pDevContext->FfbReadQ[id - 1]); if(!NT_SUCCESS(status)){ TraceEvents(TRACE_LEVEL_ERROR, DBG_IOCTL, "WdfRequestForwardToIoQueue (FfbWriteQ[%d]) failed with status: 0x%x\n", id - 1, status); WdfRequestComplete(Request, status); } return; case GET_DRV_DEV_EN: // Get the number of devices that are currently enabled TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: Case GET_DRV_DEV_EN\n"); // Get the buffer from the request // Get the data from the request WDF_REQUEST_PARAMETERS_INIT(&Params); WdfRequestGetParameters(Request, &Params); bytesToCopy = Params.Parameters.DeviceIoControl.OutputBufferLength; TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: bytesToCopy=%d\n", bytesToCopy); if (bytesToCopy<1) { WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; status = WdfRequestRetrieveOutputBuffer(Request, bytesToCopy, &GenBuffer, &bytesReturned); TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: bytesReturned=%d\n", bytesReturned); if (bytesReturned<1) { WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; if (!pdoData) break; pDevContext = GetDeviceContext(pdoData->hParentDevice); if (!pDevContext) break; // The number of the max supported devices ((BYTE *)GenBuffer)[0] = (BYTE)(pDevContext->nDevices); // Complete the transaction WdfRequestCompleteWithInformation(Request, status, bytesReturned); TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: GenBuffer[0]=%d\n", ((BYTE *)GenBuffer)[0]); return; case GET_DRV_DEV_MAX: // Get the max possible number of devices that this driver supports TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: Case GET_DRV_DEV_MAX\n"); // Get the buffer from the request // Get the data from the request WDF_REQUEST_PARAMETERS_INIT(&Params); WdfRequestGetParameters(Request, &Params); bytesToCopy = Params.Parameters.DeviceIoControl.OutputBufferLength; TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: bytesToCopy=%d\n", bytesToCopy); if (bytesToCopy<1) { WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; status = WdfRequestRetrieveOutputBuffer(Request, bytesToCopy, &GenBuffer, &bytesReturned); TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: bytesReturned=%d\n", bytesReturned); if (bytesReturned<1) { WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // The number of the max supported devices ((BYTE *)GenBuffer)[0] = MAX_N_DEVICES; // Complete the transaction WdfRequestCompleteWithInformation(Request, status, bytesReturned); TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: GenBuffer[0]=%d\n", ((BYTE *)GenBuffer)[0]); return; case IS_DRV_FFB_CAP: // Test is this version of vJoy driver supports FFB TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: Case IS_DRV_FFB_CAP\n"); // Get the data from the request (Bytes to copy) WDF_REQUEST_PARAMETERS_INIT(&Params); WdfRequestGetParameters(Request, &Params); bytesToCopy = Params.Parameters.DeviceIoControl.OutputBufferLength; TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: bytesToCopy=%d\n", bytesToCopy); if (bytesToCopy<1) { TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: bytesToCopy=%d (Failed)\n", bytesToCopy); WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // Get the buffer from the request status = WdfRequestRetrieveOutputBuffer(Request, bytesToCopy, &GenBuffer, &bytesReturned); TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: bytesReturned=%d\n", bytesReturned); if (bytesReturned<1) { TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: bytesReturned=%d (Failed)\n", bytesReturned); WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // Yes, this driver supports FFB ((BYTE *)GenBuffer)[0] = 1; // Complete the transaction WdfRequestCompleteWithInformation(Request, status, bytesReturned); TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: GenBuffer[0]=%d\n", ((BYTE *)GenBuffer)[0]); return; case RESET_DEV: /* Resets device(s) to predefined values */ TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: Case RESET_DEV\n"); // then get the implicated id of the top-level collection id = GetIdFromRawPdoRequest(Request, pExtension); TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "vJoy_EvtIoDeviceControlForRawPdo: ID=%d\n", id); // Sanity check if (id == 0xFFFF) { WdfRequestComplete(Request, STATUS_NO_SUCH_DEVICE); return; }; // Get the context of vJoy device pDevContext = GetDeviceContext(pdoData->hParentDevice); // Reset device(s) status = ResetDevice(id, pDevContext); WdfRequestCompleteWithInformation(Request, status, 0); return; default: break; } WdfRequestComplete(Request, status); return; }