/// <summary>Opens a feature connection with the settings specified by the /// ConnectionString attribute of the provider-specific feature connection /// object.</summary> /// <returns>Returns nothing</returns> FdoConnectionState SuperMapConnection::Open () { TRACE(_T("调用 SuperMapConnection::Open ...\n")); if (GetConnectionState() == FdoConnectionState_Open) throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_103_CONNECTION_ALREADY_OPEN))); // Disconnect if currently 'partially' connected (but not if already 'fully' connected): if (GetConnectionState() == FdoConnectionState_Pending) Close(); /* DEL ***************************************** FdoPtr<ConnectionProperty> datastoreProperty = dictionary->FindProperty(CONNECTIONPROPERTY_DATASTORE); // Create an enum list with a single "Default Datastore" entry: wchar_t **enumArray = new wchar_t*[1]; enumArray[0] = new wchar_t[wcslen(L"测试")+1]; wcscpy(enumArray[0], L"测试"); datastoreProperty->UpdateEnumerableProperties(1, (const wchar_t**)enumArray); if (FdoConnectionState_Pending == GetConnectionState ()) datastoreProperty->SetIsPropertyRequired (true); ************************************************/ m_strConnectionSession = SuperMapConnectionPool::GetInstance()->GetConnectionInfo(this); if (m_strConnectionSession != "") m_ConnectionState = FdoConnectionState_Open; else m_ConnectionState = FdoConnectionState_Closed; return (GetConnectionState ()); }
//************************************************************************ // Returns the number of available colors //************************************************************************ int CLCDConnectionLogitech::GetColorCount() { if (!GetConnectionState() == CONNECTED) return 0; return m_pConnectedDevice->GetColorCount(); }
//************************************************************************ // Get the pointer to the pixel buffer //************************************************************************ PBYTE CLCDConnectionLogitech::GetPixelBuffer() { if (!GetConnectionState() == CONNECTED) return NULL; return (PBYTE)m_pDrawingBuffer; }
void CLCDConnectionLogitech::SetMKeyLight(bool bM1, bool bM2, bool bM3, bool bMR) { if (GetConnectionState() != CONNECTED || m_pConnectedDevice->GetIndex() != LGLCD_DEVICE_BW) //m_lcdDeviceDesc.deviceFamilyId != LGLCD_DEVICE_FAMILY_KEYBOARD_G15) return; byte *data = new byte[m_HIDCapabilities.FeatureReportByteLength]; data[0] = 0x02; data[1] = 0x04; data[2] = 0x00; if (!bM1) data[2] |= G15_M1_LIGHT; if (!bM2) data[2] |= G15_M2_LIGHT; if (!bM3) data[2] |= G15_M3_LIGHT; if (!bMR) data[2] |= G15_MR_LIGHT; data[3] = 0x00; HidD_SetFeature(m_hHIDDeviceHandle, data, m_HIDCapabilities.FeatureReportByteLength); delete[] data; }
/*virtual*/ void OpScopeNetwork::Reset() { ResetSTP(); if (GetConnectionState() != STATE_CLOSED) ResetSocket(); }
//************************************************************************ // Returns the display size //************************************************************************ SIZE CLCDConnectionLogitech::GetDisplaySize() { SIZE size = { 0, 0 }; if (!GetConnectionState() == CONNECTED) return size; return m_pConnectedDevice->GetDisplaySize(); }
bool FTcpMessageTransportConnection::Send(FTcpSerializedMessagePtr Message) { if (GetConnectionState() == STATE_Connected) { return Outbox.Enqueue(Message); } return false; }
//************************************************************************ // Draws the specified bitmap on the LCD //************************************************************************ bool CLCDConnectionLogitech::Draw() { if (!GetConnectionState() == CONNECTED || !m_hDrawEvent) return false; memcpy(m_pPixels, m_pDrawingBuffer, m_iPixels); SetEvent(m_hDrawEvent); return true; }
/*virtual*/ void OpScopeNetwork::Disconnect() { BOOL was_connected = (GetConnectionState() == STATE_CONNECTED); Reset(); if (was_connected) NotifyConnectionClosed(this); }
//************************************************************************ // Returns the state of the specified Button //************************************************************************ bool CLCDConnectionLogitech::GetButtonState(int iButton) { if (!GetConnectionState() == CONNECTED) return false; DWORD dwButton = GetButtonId(iButton); if (m_dwButtonState & dwButton) return true; return false; }
SG15LightStatus CLCDConnectionLogitech::GetLightStatus() { SG15LightStatus status; status.bMKey[0] = false; status.bMKey[1] = false; status.bMKey[2] = false; status.bMRKey = false; status.eKBDBrightness = KBD_OFF; status.eLCDBrightness = LCD_OFF; if (GetConnectionState() != CONNECTED || m_pConnectedDevice->GetIndex() != LGLCD_DEVICE_BW) //m_lcdDeviceDesc.deviceFamilyId != LGLCD_DEVICE_FAMILY_KEYBOARD_G15) return status; byte *data = new byte[m_HIDCapabilities.FeatureReportByteLength]; data[0] = 0x02; data[1] = 0x02; data[2] = 0x00; data[3] = 0x00; HidD_GetFeature(m_hHIDDeviceHandle, data, m_HIDCapabilities.FeatureReportByteLength); // data[1] = Keys status.eKBDBrightness = (EKBDBrightness)data[1]; // data[2] = LCD switch (data[2]) { case 0x02: status.eLCDBrightness = LCD_ON; break; case 0x01: status.eLCDBrightness = LCD_MEDIUM; break; default: status.eLCDBrightness = LCD_OFF; break; } // MKeys status.bMKey[0] = !(data[3] & G15_M1_LIGHT); status.bMKey[1] = !(data[3] & G15_M2_LIGHT); status.bMKey[2] = !(data[3] & G15_M3_LIGHT); // MRKey status.bMRKey = !(data[3] & G15_MR_LIGHT); delete[] data; return status; }
//************************************************************************ // Hides the applet //************************************************************************ bool CLCDConnectionLogitech::HideApplet() { if (!GetConnectionState() == CONNECTED) return false; DWORD rc; rc = lgLcdUpdateBitmap(m_hDevice, &m_lcdBitmap.hdr, LGLCD_ASYNC_UPDATE(LGLCD_PRIORITY_IDLE_NO_SHOW)); if (rc != ERROR_SUCCESS) return false; return true; }
OpScopeNetwork::~OpScopeNetwork() { ConnectionState constate = GetConnectionState(); in_destruct = TRUE; g_main_message_handler->UnsetCallBack(this, MSG_SCOPE_PROCESS_MESSAGE); ResetSTP(); if (constate != STATE_CLOSED) ResetSocket(); if (constate == STATE_CONNECTED) NotifyConnectionClosed(this); }
OP_STATUS OpScopeNetwork::Connect(OpStringC &addr, int port) { if (GetConnectionState() != STATE_CLOSED) Disconnect(); ResetSTP(); RETURN_IF_ERROR(socket_address.Set(addr)); socket_port = port; RETURN_IF_ERROR(SocketWrapper::CreateTCPSocket(&socket, this, SocketWrapper::NO_WRAPPERS)); RETURN_IF_ERROR(OpSocketAddress::Create(&sockaddr)); RETURN_IF_ERROR(sockaddr->FromString(addr.CStr())); sockaddr->SetPort(port); return socket->Connect(sockaddr); }
/// <summary>Sets the connection string used to open a DataStore. SetConnectionString can only be set while the /// connection is closed.</summary> /// <param name="value">Input the connection string</param> /// <returns>Returns nothing</returns> void SuperMapConnection::SetConnectionString (FdoString* value) { TRACE(_T("调用 SuperMapConnection::SetConnectionString(%ls)。\n"), value); FdoConnectionState state = GetConnectionState(); if (state == FdoConnectionState_Closed || state == FdoConnectionState_Pending) { // Update the connection string: m_ConnectionString = value; // Update the connection property dictionary: FdoPtr<FdoIConnectionInfo> connInfo = GetConnectionInfo(); FdoPtr<FdoCommonConnPropDictionary> connDict = dynamic_cast<FdoCommonConnPropDictionary*>(connInfo->GetConnectionProperties()); connDict->UpdateFromConnectionString(m_ConnectionString); } else throw FdoException::Create (NlsMsgGet(SUPERMAP_CONNECTION_ALREADY_OPEN, "The connection is already open.")); }
bool APartyBeaconClient::RequestReservationUpdate(const FUniqueNetIdRepl& RequestingPartyLeader, const TArray<FPlayerReservation>& PlayersToAdd) { bool bWasStarted = false; EBeaconConnectionState ConnectionState = GetConnectionState(); if (ensure(ConnectionState == EBeaconConnectionState::Open)) { RequestType = EClientRequestType::ReservationUpdate; PendingReservation.PartyLeader = RequestingPartyLeader; PendingReservation.PartyMembers = PlayersToAdd; ServerUpdateReservationRequest(DestSessionId, PendingReservation); bPendingReservationSent = true; bWasStarted = true; } return bWasStarted; }
OP_STATUS OpScopeNetwork::Connect(OpSocket *new_socket) { OP_ASSERT(new_socket); if (GetConnectionState() != STATE_CLOSED) Disconnect(); ResetSTP(); socket = new_socket; RETURN_IF_ERROR(OpSocketAddress::Create(&sockaddr)); RETURN_IF_ERROR(socket->GetSocketAddress(sockaddr)); RETURN_IF_ERROR(sockaddr->ToString(&socket_address)); socket_port = 0; OnSocketConnected(socket); return OpStatus::OK; }
void CLCDConnectionLogitech::SetKBDBacklight(EKBDBrightness eBrightness) { if (GetConnectionState() != CONNECTED || m_pConnectedDevice->GetIndex() != LGLCD_DEVICE_BW) //m_lcdDeviceDesc.deviceFamilyId != LGLCD_DEVICE_FAMILY_KEYBOARD_G15) return; byte *data = new byte[m_HIDCapabilities.FeatureReportByteLength]; data[0] = 0x02; data[1] = 0x01; data[2] = eBrightness; data[3] = 0x00; HidD_SetFeature(m_hHIDDeviceHandle, data, m_HIDCapabilities.FeatureReportByteLength); delete[] data; }
void CLCDConnectionLogitech::runDrawingThread() { m_hStopEvent = CreateEvent(NULL, FALSE, FALSE, NULL); m_hDrawEvent = CreateEvent(NULL, FALSE, FALSE, NULL); DWORD dwRes = 0; while (1) { HANDLE hArray[2] = { m_hStopEvent, m_hDrawEvent }; dwRes = WaitForMultipleObjects(2, hArray, FALSE, INFINITE); if (dwRes == WAIT_OBJECT_0) { break; } else if (dwRes == WAIT_OBJECT_0 + 1) { DWORD rc; if (GetConnectionState() != CONNECTED) { continue; } // do a sync update if the applet is in the foreground, or every 500 ms // the delay is there because sync updates can take up to 33ms to fail if (m_dwForegroundCheck < GetTickCount()) { m_dwForegroundCheck = GetTickCount() + 500; rc = lgLcdUpdateBitmap(m_hDevice, &m_lcdBitmap.hdr, LGLCD_SYNC_COMPLETE_WITHIN_FRAME(m_iPriority)); if (rc == ERROR_ACCESS_DENIED) { rc = ERROR_SUCCESS; m_bIsForeground = false; } else if (rc == ERROR_SUCCESS) m_bIsForeground = true; } else rc = lgLcdUpdateBitmap(m_hDevice, &m_lcdBitmap.hdr, LGLCD_ASYNC_UPDATE(m_iPriority)); if (rc != ERROR_SUCCESS) { HandleErrorFromAPI(rc); } } } CloseHandle(m_hStopEvent); CloseHandle(m_hDrawEvent); }
bool APartyBeaconClient::RequestReservationUpdate(const FString& ConnectInfoStr, const FString& InSessionId, const FUniqueNetIdRepl& RequestingPartyLeader, const TArray<FPlayerReservation>& PlayersToAdd) { bool bWasStarted = false; EBeaconConnectionState ConnectionState = GetConnectionState(); if (ConnectionState != EBeaconConnectionState::Open) { // create a new pending reservation for these players in the same way as a new reservation request bWasStarted = RequestReservation(ConnectInfoStr, InSessionId, RequestingPartyLeader, PlayersToAdd); if (bWasStarted) { // Treat this reservation as an update to an existing reservation on the host RequestType = EClientRequestType::ReservationUpdate; } } else if (ConnectionState == EBeaconConnectionState::Open) { RequestReservationUpdate(RequestingPartyLeader, PlayersToAdd); } return bWasStarted; }
bool Session::IsLoggedIn() { bool isloggedIn = (NULL != m_pSession) && !m_hasLoggedOut && (GetConnectionState() == SP_CONNECTION_STATE_LOGGED_IN); return isloggedIn; }
/// <summary>Creates and returns the specified type of command object associated with /// the connection.</summary> /// <param name="commandType">Input the command type to be created</param> /// <returns>Returns the command</returns> FdoICommand* SuperMapConnection::CreateCommand (FdoInt32 commandType) { FdoPtr<FdoICommand> ret = NULL; if ((GetConnectionState() == FdoConnectionState_Closed) || (GetConnectionState() == FdoConnectionState_Pending)) throw FdoException::Create(NlsMsgGet(SUPERMAP_CONNECTION_INVALID, "Connection is invalid.")); switch (commandType) { case FdoCommandType_Select: TRACE(_T("调用 SuperMapConnection::CreateCommand:Select\n")); ret = new SuperMapSelectCommand (this); break; case FdoCommandType_SelectAggregates: TRACE(_T("调用 SuperMapConnection::CreateCommand:SelectAggregates\n")); //ret = new SuperMapSelectAggregatesCommand (this); break; case FdoCommandType_DescribeSchema: ret = new SuperMapDescribeSchemaCommand (this); TRACE(_T("调用 SuperMapConnection::CreateCommand:DescribeSchema\n")); break; case FdoCommandType_DescribeSchemaMapping: //ret = new SuperMapDescribeSchemaMappingCommand (this); TRACE(_T("调用 SuperMapConnection::CreateCommand:DescribeSchemaMapping\n")); break; case FdoCommandType_GetSpatialContexts: ret = new SuperMapGetSpatialContextsCommand (this); TRACE(_T("调用 SuperMapConnection::CreateCommand:GetSpatialContexts\n")); break; case FdoCommandType_CreateSpatialContext: ret = new SuperMapCreateSpatialContextCommand (this); TRACE(_T("调用 SuperMapConnection::CreateCommand:CreateSpatialContext\n")); break; case FdoCommandType_Insert: ret = new SuperMapInsertCommand (this); TRACE(_T("调用 SuperMapConnection::CreateCommand:Insert\n")); break; case FdoCommandType_Update: ret = new SuperMapUpdateCommand (this); TRACE(_T("调用 SuperMapConnection::CreateCommand:Update\n")); break; case FdoCommandType_Delete: ret = new SuperMapDeleteCommand (this); TRACE(_T("调用 SuperMapConnection::CreateCommand:Delete\n")); break; case FdoCommandType_ApplySchema: ret = new SuperMapApplySchemaCommand (this); TRACE(_T("调用 SuperMapConnection::CreateCommand:ApplySchema\n")); break; case FdoCommandType_DestroySchema: ret = new SuperMapDestroySchemaCommand (this); TRACE(_T("调用 SuperMapConnection::CreateCommand:DestroySchema\n")); break; case FdoCommandType_CreateDataStore: //ret = new SuperMapCreateDataStoreCommand (this); TRACE(_T("调用 SuperMapConnection::CreateCommand:CreateDataStore\n")); break; default: throw FdoException::Create (FdoException::NLSGetMessage (FDO_102_COMMAND_NOT_SUPPORTED, "The command '%1$ls' is not supported.", (FdoString*)(FdoCommonMiscUtil::FdoCommandTypeToString (commandType)))); } return (FDO_SAFE_ADDREF (ret.p)); }
bool CLCDConnectionLogitech::HIDInit() { if (GetConnectionState() != CONNECTED || m_pConnectedDevice->GetIndex() != LGLCD_DEVICE_BW) //LGLCD_DEVICE_FAMILY_KEYBOARD_G15) return false; // Logitech G15 int VendorID = 0x046d; int ProductID = 0xc222; //Use a series of API calls to find a HID with a specified Vendor IF and Product ID. HIDD_ATTRIBUTES Attributes; SP_DEVICE_INTERFACE_DATA devInfoData; bool LastDevice = FALSE; int MemberIndex = 0; LONG Result; DWORD Length = 0; PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = NULL; HANDLE hDevInfo = NULL; GUID HidGuid; ULONG Required = 0; bool MyDeviceDetected = false; /* API function: HidD_GetHidGuid Get the GUID for all system HIDs. Returns: the GUID in HidGuid. */ HidD_GetHidGuid(&HidGuid); /* API function: SetupDiGetClassDevs Returns: a handle to a device information set for all installed devices. Requires: the GUID returned by GetHidGuid. */ hDevInfo = SetupDiGetClassDevs (&HidGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); devInfoData.cbSize = sizeof(devInfoData); //Step through the available devices looking for the one we want. //Quit on detecting the desired device or checking all available devices without success. MemberIndex = 0; LastDevice = FALSE; do { /* API function: SetupDiEnumDeviceInterfaces On return, MyDeviceInterfaceData contains the handle to a SP_DEVICE_INTERFACE_DATA structure for a detected device. Requires: The DeviceInfoSet returned in SetupDiGetClassDevs. The HidGuid returned in GetHidGuid. An index to specify a device. */ Result = SetupDiEnumDeviceInterfaces (hDevInfo, 0, &HidGuid, MemberIndex, &devInfoData); if (Result != 0) { //A device has been detected, so get more information about it. /* API function: SetupDiGetDeviceInterfaceDetail Returns: an SP_DEVICE_INTERFACE_DETAIL_DATA structure containing information about a device. To retrieve the information, call this function twice. The first time returns the size of the structure in Length. The second time returns a pointer to the data in DeviceInfoSet. Requires: A DeviceInfoSet returned by SetupDiGetClassDevs The SP_DEVICE_INTERFACE_DATA structure returned by SetupDiEnumDeviceInterfaces. The final parameter is an optional pointer to an SP_DEV_INFO_DATA structure. This application doesn't retrieve or use the structure. If retrieving the structure, set MyDeviceInfoData.cbSize = length of MyDeviceInfoData. and pass the structure's address. */ //Get the Length value. //The call will return with a "buffer too small" error which can be ignored. Result = SetupDiGetDeviceInterfaceDetail (hDevInfo, &devInfoData, NULL, 0, &Length, NULL); //Allocate memory for the hDevInfo structure, using the returned Length. detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(Length); //Set cbSize in the detailData structure. detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); //Call the function again, this time passing it the returned buffer size. Result = SetupDiGetDeviceInterfaceDetail (hDevInfo, &devInfoData, detailData, Length, &Required, NULL); // Open a handle to the device. // To enable retrieving information about a system mouse or keyboard, // don't request Read or Write access for this handle. /* API function: CreateFile Returns: a handle that enables reading and writing to the device. Requires: The DevicePath in the detailData structure returned by SetupDiGetDeviceInterfaceDetail. */ m_hHIDDeviceHandle = CreateFile (detailData->DevicePath, FILE_GENERIC_READ | FILE_GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); /* API function: HidD_GetAttributes Requests information from the device. Requires: the handle returned by CreateFile. Returns: a HIDD_ATTRIBUTES structure containing the Vendor ID, Product ID, and Product Version Number. Use this information to decide if the detected device is the one we're looking for. */ //Set the Size to the number of bytes in the structure. Attributes.Size = sizeof(Attributes); Result = HidD_GetAttributes (m_hHIDDeviceHandle, &Attributes); //Is it the desired device? MyDeviceDetected = FALSE; if (Attributes.VendorID == VendorID) { if (Attributes.ProductID == ProductID) { //Both the Vendor ID and Product ID match. MyDeviceDetected = TRUE; } else CloseHandle(m_hHIDDeviceHandle); } else CloseHandle(m_hHIDDeviceHandle); //Free the memory used by the detailData structure (no longer needed). free(detailData); } else LastDevice = TRUE; MemberIndex = MemberIndex + 1; } //do while ((LastDevice == FALSE) && (MyDeviceDetected == FALSE)); if (MyDeviceDetected) { PHIDP_PREPARSED_DATA PreparsedData; HidD_GetPreparsedData (m_hHIDDeviceHandle, &PreparsedData); HidP_GetCaps (PreparsedData, &m_HIDCapabilities); HidD_FreePreparsedData(PreparsedData); } //Free the memory reserved for hDevInfo by SetupDiClassDevs. SetupDiDestroyDeviceInfoList(hDevInfo); return MyDeviceDetected; }