void nxInputManager::DataSender::SendData(const unsigned short&uButtonId,const bool&IsAxis,const short&sValue,const nxDeviceId&uDevId,const nxExtendedId&uExtended) { nxInputId uInputId = MakeInputId(dType,uButtonId,IsAxis,uExtended); if (!objManager.srInputLabel.LookupLeft(uInputId)) { nxScopedRecursiveLock objLock(objManager.csDataSenderSendData); // Be sure it wasn't added while waiting for the lock if (!objManager.srInputLabel.LookupLeft(uInputId)) { std::stringstream ss; switch (dType) { case NX_MOUSE: ss << "MOUSE_"; break; case NX_XINPUT: ss << "XI_"; break; case NX_DINPUT: ss << "DI_"; if (uExtended) ss << "POV_"; break; default: break; } if (IsAxis) ss << "AXIS_"; ss << uButtonId; objManager.AddInputLabel(uInputId,ss.str()); } } objManager.PostEvent(NX_INPUT_RECEIVED,MakeMessage(uInputId,(uDevId?uDevId:uDeviceId)),sValue); //objHandler.SendData(objHandler.AllocData()->Set(dType,(uDevId?uDevId:uDeviceId),uInputId,sValue)); }
int32_t CInsideSocket::OnConnected() { m_pEpoll->RegistEvent(this, EPOLLIN); //发送注册消息 if(SendRegisteNotify(m_nPeerType,m_nPeerID) < 0) { CloseSocket(SYS_EVENT_CONN_REGISTFAILED); return S_OK; } //成功发送通知后置为可用状态 SetSocketStatus(enmSocketStatus_Available); //发送缓存中剩余数据 int32_t nRet = SendRestData(); if(nRet < 0) { CloseSocket(SYS_EVENT_CONN_ERROR); return E_SOCKETERROR; } //提取接收缓存中的消息 MakeMessage(); return S_OK; }
CLeaveRoomMessage::CLeaveRoomMessage(std::string username,std::string room_name) : CNetworkMessage() { DUsername = username; DRoomName = room_name; DMessage = new char[MAX_MESSAGE_SIZE]; DPacketFactory = new CNetworkPacketFactory(); DMessageLength = 0; MakeMessage(); DAction = (int16_t) LEAVE_ROOM; }
bool Update(const AbstractAirspace &_airspace, AirspaceWarning::State _state, const AirspaceInterceptSolution &solution) { if (&_airspace != &airspace) return false; state = _state; SetMessage(MakeMessage(airspace, state, solution)); return true; }
CCreateRoomMessage::CCreateRoomMessage(int capacity,std::string username,std::string room_name) : CNetworkMessage() { DUsername = username; DRoomName = room_name; DCapacity = capacity; DMessage = new char[MAX_MESSAGE_SIZE]; DPacketFactory = new CNetworkPacketFactory(); DMessageLength = 0; MakeMessage(); DAction = (int16_t) CREATE_ROOM; }
AirspaceWarningWidget(AirspaceWarningMonitor &_monitor, ProtectedAirspaceWarningManager &_manager, const AbstractAirspace &_airspace, AirspaceWarning::State _state, const AirspaceInterceptSolution &solution) :QuestionWidget(MakeMessage(_airspace, _state, solution), *this), monitor(_monitor), manager(_manager), airspace(_airspace), state(_state) { AddButton(_("ACK"), ACK); AddButton(_("ACK Day"), ACK_DAY); AddButton(_("More"), MORE); }
LONG CCardIssuer::ExecCommand(BYTE bCommandCode, BYTE bParameterCode, PBYTE pbBodyData, BYTE cbBodyLength, PBYTE pbRecvBuff, PDWORD pcbRecvLength) { LONG lResult = 0; EnterCriticalSection(&m_csLock); MakeMessage(bCommandCode, bParameterCode, pbBodyData, cbBodyLength); lResult = TransmissionControl(bCommandCode, bParameterCode, pbRecvBuff, pcbRecvLength); LeaveCriticalSection(&m_csLock); return lResult; }
int32_t CInsideSocket::OnRead(int32_t nErrorCode) { uint8_t arrBuf[enmMaxMessageSize]; int32_t nCloseCode = 0; int32_t nRecvBytes = 0; int32_t nRet = Recv(arrBuf, sizeof(arrBuf), nRecvBytes); if(nRet != S_OK) { nCloseCode = nRet; } m_stRecvBuffer.Write(arrBuf, nRecvBytes); //提取消息包 MakeMessage(); if(nCloseCode != 0) { CloseSocket(nCloseCode); return E_SOCKETERROR; } return S_OK; }
void SetGUIDMapping(const nxDeviceId&uDeviceId,const std::string&strGUID) { srDeviceGUID.Insert(uDeviceId,strGUID); PostEvent(NX_INPUT_DEVICE,MakeMessage(0,uDeviceId),0); }
MatTaskAddWidget(MatTaskMonitor &_monitor, const Waypoint &_waypoint) :QuestionWidget(MakeMessage(_waypoint), *this), monitor(_monitor), waypoint(_waypoint) { AddButton(_("Add"), ADD); AddButton(_("Dismiss"), DISMISS); }
// /// Constructs a TXGdi object with a default IDS_GDIFAILURE message. // TXGdi::TXGdi(uint resId, HANDLE handle) : TXOwl(MakeMessage(resId, uint(handle)), resId) { }
// /// Converts the resource ID to a string and returns the string message. /// \note For backward compatibility // tstring TXGdi::Msg(uint resId, HANDLE handle) { return MakeMessage(resId, uint(handle)); }
LRESULT CALLBACK nxInputManager::RawInputProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_INPUT: { nxInputManager&objManager = nxInputManager::instance(); unsigned char*ptData = NULL; RAWINPUT*priData=NULL; try { // In case we somehow magically have a null handle, we shouldn't do anything special. if (!lParam) break; UINT uSize=sizeof(RAWINPUTHEADER); HRAWINPUT hRawInput = reinterpret_cast<HRAWINPUT>(lParam); if (GetRawInputData(hRawInput,RID_INPUT,NULL,&uSize,sizeof(RAWINPUTHEADER)) != 0) nxThrow("Couldn't retrieve RAWINPUT data size for WM_INPUT message."); ptData = new unsigned char[uSize]; priData = reinterpret_cast<RAWINPUT*>(ptData); if (GetRawInputData(hRawInput,RID_INPUT,priData,&uSize,sizeof(RAWINPUTHEADER)) == (UINT)-1) nxThrow("Couldn't retrieve RAWINPUT data for WM_INPUT message."); // Retrieve the device ID for the keyboard. Will be nonzero if it's a physical keyboard. // If it's simulated input, it will be zero. Same for random HID devices (and multimedia keys). nxDeviceId uDeviceId = objManager.GetInputHandleId(priData->header.hDevice); switch (priData->header.dwType) { // Keyboard input handling case RIM_TYPEKEYBOARD: { // Get a reference to the keyboard object RAWKEYBOARD&riKB = priData->data.keyboard; // We don't want to do anything in the case of an overrun code, or if it's not a keydown or keyup message if (riKB.VKey != KEYBOARD_OVERRUN_MAKE_CODE && (riKB.Message == WM_KEYDOWN || riKB.Message == WM_KEYUP)) { // If there's no make code specified, we'll be looking at the vkey bool isVKey = (riKB.MakeCode?false:true); // The pause key, at least on my keyboard, sends an 0xFF, and then get's interpreted as LCTRL and then PAUSE // or something similar. So, I just handle the pause key as a special case, and ignore the 0xFF. // There's an additional error where the numlock key is identified as the pause key (imagine that...) // So, in these cases I definitely wants to categorize the key by its VKey. switch (riKB.VKey) { case VK_PAUSE: case VK_NUMLOCK: isVKey = true; } // Create an input id for this information nxInputId uInputId = MakeInputId(NX_KEYBOARD,(isVKey?(unsigned short)riKB.VKey:(unsigned short)riKB.MakeCode),false,(isVKey?0x1u:0x0u) | (riKB.Flags&RI_KEY_E0?0x2u:0x0u) | (riKB.Flags&RI_KEY_E1?0x4u:0x0u)); // If we haven't gotten the key name at some time prior //nxInputInfo*pInputInfo=objManager.GetInputInfo(uInputId); bool bIsText = (objManager.srInputLabel.LookupLeft(uInputId)?true:false); if (!bIsText) { std::string strKeyText = ""; // If it's one of our special cases, set the text if (isVKey) { switch (riKB.VKey) { case VK_PAUSE: strKeyText = "PAUSE"; break; case VK_NUMLOCK: strKeyText = "NUM_LOCK"; break; } } // if it wasn't one of our special cases if (strKeyText.empty()) { // If the key isn't defined by it's VKey, we try to get the key name from the key's scan code and extended bit if (!isVKey) { // Size the string to a size that will definitely be large enough strKeyText.resize(255); // Resize the string to fit the results of getting the key's name text. Returns 0 on error, so no problems. strKeyText.resize(GetKeyNameText(riKB.MakeCode<<16 | (riKB.Flags&RI_KEY_E0?0x1<<24:0),const_cast<char*>(strKeyText.c_str()),255)); } // If we haven't gotten a name for the key yet, then we need to construct one based on the flags and the scan code or vkey // This ensures that we at least support every key in some way. if (strKeyText.empty()) { std::stringstream ss; USHORT uVal = 0; // Using the extended bits, create a value from 0-3 to reflect their values char chExtended = "0123"[(riKB.Flags&RI_KEY_E0?0x1:0x0) | (riKB.Flags&RI_KEY_E1?0x2:0x0)]; // If the key is defined by the scan code, make a name using it. if (!isVKey) { // Prefix ss << "KSC_"; uVal = riKB.MakeCode; } // Otherwise, we'll use the vkey if the vkey exists else if (riKB.VKey) { // Prefix ss << "KVK_"; uVal = riKB.VKey; } // If either a scan code or a vkey were available, then we're ready to create the name. // This should always happen, but if it doesnt.. I guess I won't be supporting that key, now will I? if (uVal) { // Name will be <prefix><extended bit value><scancode or vkey in hex> ss << chExtended << std::hex << std::uppercase << std::setfill('0') << std::setw(sizeof(USHORT)*2) << uVal; strKeyText = ss.str(); } } } // If we got a textual identifier for the key if (!strKeyText.empty()) { // Make the key identifier uppercase for (std::string::iterator it=strKeyText.begin();it!=strKeyText.end();++it) { if (*it == ' ') *it = '_'; else *it = std::toupper(*it); } // Add the input information if (strKeyText==";") strKeyText = "SEMICOLON"; else if (strKeyText==":") strKeyText = "COLON"; else if (strKeyText==",") strKeyText = "COMMA"; else if (strKeyText=="'") strKeyText = "QUOTE"; else if (strKeyText == "/") strKeyText = "SLASH"; else if (strKeyText == "\\") strKeyText = "BACKSLASH"; else if (strKeyText == ".") strKeyText = "PERIOD"; else if (strKeyText == "=") strKeyText = "EQUALS"; else if (strKeyText == "-") strKeyText = "MINUS"; else if (strKeyText == "`") strKeyText = "ACUTE"; else if (strKeyText == "[") strKeyText = "LBRACK"; else if (strKeyText == "]") strKeyText = "RBRACK"; objManager.AddInputLabel(uInputId,strKeyText); bIsText = true; } } if (bIsText) objManager.PostEvent(NX_INPUT_RECEIVED,MakeMessage(uInputId,uDeviceId),(priData->data.keyboard.Flags&RI_KEY_BREAK?0:INPUT_MAX)); } break; } // Mouse input handling (multiple dispatch points) case RIM_TYPEMOUSE: { // Get a reference to the mouse object RAWMOUSE&riMouse = priData->data.mouse; DataSender objSender(NX_MOUSE,uDeviceId); // Check if the mouse has moved relatively, we are not supporting absolute mice (like touch screens) if (riMouse.usFlags & MOUSE_MOVE_ABSOLUTE) { // TODO: Convert it to relative positioning based on the old coordinate //printf("Moved mouse absolute: (%ld,%ld)\n",riMouse.lLastX,riMouse.lLastY); } else { // Must be relative movement. if (riMouse.lLastX) objSender.SendData(0,true,riMouse.lLastX); if (riMouse.lLastY) objSender.SendData(1,true,riMouse.lLastY); } // Wheel will be axis 2 if (riMouse.usButtonFlags & RI_MOUSE_WHEEL) objSender.SendData(2,true,(SHORT)riMouse.usButtonData); if (riMouse.usButtonFlags & RI_MOUSE_BUTTON_1_DOWN) objSender.SendData(0,false,INPUT_MAX); if (riMouse.usButtonFlags & RI_MOUSE_BUTTON_1_UP) objSender.SendData(0,false,0); if (riMouse.usButtonFlags & RI_MOUSE_BUTTON_2_DOWN) objSender.SendData(1,false,INPUT_MAX); if (riMouse.usButtonFlags & RI_MOUSE_BUTTON_2_UP) objSender.SendData(1,false,0); if (riMouse.usButtonFlags & RI_MOUSE_BUTTON_3_DOWN) objSender.SendData(2,false,INPUT_MAX); if (riMouse.usButtonFlags & RI_MOUSE_BUTTON_3_UP) objSender.SendData(2,false,0); if (riMouse.usButtonFlags & RI_MOUSE_BUTTON_4_DOWN) objSender.SendData(3,false,INPUT_MAX); if (riMouse.usButtonFlags & RI_MOUSE_BUTTON_4_UP) objSender.SendData(3,false,0); if (riMouse.usButtonFlags & RI_MOUSE_BUTTON_5_DOWN) objSender.SendData(4,false,INPUT_MAX); if (riMouse.usButtonFlags & RI_MOUSE_BUTTON_5_UP) objSender.SendData(4,false,0); break; } } } catch (std::exception&e) { nxLog << e.what() << std::endl; } delete[] ptData; // We don't need to call DefWindowProc if it's a WM_INPUT message. return 0; } } // If we somehow got a message other than WM_INPUT, we'll pass it on. return DefWindowProc(hwnd, msg, wParam, lParam); }
// /// Create the exception. // TXModuleVersionInfo::TXModuleVersionInfo(const tstring& name) : TXOwl(MakeMessage(IDS_INVALIDMODULE, name)) { }
MatTaskAddWidget(MatTaskMonitor &_monitor, WaypointPtr &&_waypoint) :QuestionWidget(MakeMessage(*_waypoint), *this), monitor(_monitor), waypoint(std::move(_waypoint)) { AddButton(_("Add"), ADD); AddButton(_("Dismiss"), DISMISS); }
bool SMTPClient::SendEmail() { if (m_From.size()==0) return false; if (m_Recipients.size()==0) return false; if (m_Server.size()==0) return false; const std::string rmessage=MakeMessage(); CURLcode ret; struct curl_slist *slist1; smtp_upload_status smtp_ctx; smtp_ctx.bytes_read=0; slist1 = NULL; std::vector<std::string>::const_iterator itt; for (itt=m_Recipients.begin(); itt!=m_Recipients.end(); ++itt) { slist1 = curl_slist_append(slist1, (*itt).c_str()); } std::stringstream sstr; if (m_Port != 465) sstr << "smtp://"; else sstr << "smtps://"; //SSL connection sstr << m_Server << ":" << m_Port; std::string szURL=sstr.str();//"smtp://"+MailServer; try { CURL *curl; curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)177); curl_easy_setopt(curl, CURLOPT_URL, szURL.c_str()); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); if (m_Username!="") { //std::string szUserPassword=MailUsername+":"+MailPassword; //curl_easy_setopt(curl, CURLOPT_USERPWD, szUserPassword.c_str()); curl_easy_setopt(curl, CURLOPT_USERNAME, m_Username.c_str()); curl_easy_setopt(curl, CURLOPT_PASSWORD, m_Password.c_str()); } curl_easy_setopt(curl, CURLOPT_USERAGENT, "domoticz/7.26.0"); curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L); curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_TRY);//CURLUSESSL_ALL); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); curl_easy_setopt(curl, CURLOPT_SSLVERSION, 0L); curl_easy_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0L); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); //curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L); curl_easy_setopt(curl, CURLOPT_MAIL_FROM, m_From.c_str()); curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, slist1); smtp_ctx.pDataBytes=new char[rmessage.size()]; if (smtp_ctx.pDataBytes==NULL) { _log.Log(LOG_ERROR,"SMTP Mailer: Out of Memory!"); curl_easy_cleanup(curl); curl_slist_free_all(slist1); return false; } smtp_ctx.sDataLength=rmessage.size(); memcpy(smtp_ctx.pDataBytes,rmessage.c_str(),smtp_ctx.sDataLength); curl_easy_setopt(curl, CURLOPT_READFUNCTION, smtp_payload_reader); curl_easy_setopt(curl, CURLOPT_READDATA, &smtp_ctx); ret = curl_easy_perform(curl); curl_easy_cleanup(curl); curl_slist_free_all(slist1); delete [] smtp_ctx.pDataBytes; if (ret!=CURLE_OK) { _log.Log(LOG_ERROR,"SMTP Mailer: Error sending Email to: %s !",m_Recipients[0].c_str()); return false; } } catch (...) { _log.Log(LOG_ERROR,"SMTP Mailer: Error sending Email to: %s !",m_Recipients[0].c_str()); return false; } return true; }
tstring TXOwl::MakeMessage(uint resId, const tstring& infoStr, TModule* module) { return MakeMessage(resId, infoStr.c_str(), module); }