void Client::updateState(xcb_ewmh_connection_t* ewmhConn) { xcb_connection_t* conn = ewmhConn->connection; xcb_get_geometry_cookie_t geomCookie; if (!mOwned) geomCookie = xcb_get_geometry_unchecked(conn, mWindow); const xcb_get_property_cookie_t normalHintsCookie = xcb_icccm_get_wm_normal_hints(conn, mWindow); const xcb_get_property_cookie_t leaderCookie = xcb_get_property(conn, 0, mWindow, Atoms::WM_CLIENT_LEADER, XCB_ATOM_WINDOW, 0, 1); const xcb_get_property_cookie_t transientCookie = xcb_icccm_get_wm_transient_for(conn, mWindow); const xcb_get_property_cookie_t hintsCookie = xcb_icccm_get_wm_hints(conn, mWindow); const xcb_get_property_cookie_t classCookie = xcb_icccm_get_wm_class(conn, mWindow); const xcb_get_property_cookie_t nameCookie = xcb_icccm_get_wm_name(conn, mWindow); const xcb_get_property_cookie_t protocolsCookie = xcb_icccm_get_wm_protocols(conn, mWindow, Atoms::WM_PROTOCOLS); const xcb_get_property_cookie_t strutCookie = xcb_ewmh_get_wm_strut(ewmhConn, mWindow); const xcb_get_property_cookie_t partialStrutCookie = xcb_ewmh_get_wm_strut_partial(ewmhConn, mWindow); const xcb_get_property_cookie_t stateCookie = xcb_ewmh_get_wm_state(ewmhConn, mWindow); const xcb_get_property_cookie_t typeCookie = xcb_ewmh_get_wm_window_type(ewmhConn, mWindow); const xcb_get_property_cookie_t pidCookie = xcb_ewmh_get_wm_pid(ewmhConn, mWindow); if (!mOwned) updateSize(conn, geomCookie); updateNormalHints(conn, normalHintsCookie); updateLeader(conn, leaderCookie); updateTransient(conn, transientCookie); updateHints(conn, hintsCookie); updateClass(conn, classCookie); updateName(conn, nameCookie); updateProtocols(conn, protocolsCookie); updateStrut(ewmhConn, strutCookie); updatePartialStrut(ewmhConn, partialStrutCookie); updateEwmhState(ewmhConn, stateCookie); updateWindowTypes(ewmhConn, typeCookie); updatePid(ewmhConn, pidCookie); }
void Client::propertyNotify(xcb_atom_t atom) { #warning Need to notify js that properties have changed warning() << "Got propertyNotify" << Atoms::name(atom) << mWindow; auto ewmhConnection = WindowManager::instance()->ewmhConnection(); auto conn = ewmhConnection->connection; if (atom == XCB_ATOM_WM_NORMAL_HINTS) { const xcb_get_property_cookie_t normalHintsCookie = xcb_icccm_get_wm_normal_hints(conn, mWindow); updateNormalHints(conn, normalHintsCookie); } else if (atom == XCB_ATOM_WM_TRANSIENT_FOR) { const xcb_get_property_cookie_t transientCookie = xcb_icccm_get_wm_transient_for(conn, mWindow); updateTransient(conn, transientCookie); } else if (atom == Atoms::WM_CLIENT_LEADER) { const xcb_get_property_cookie_t leaderCookie = xcb_get_property(conn, 0, mWindow, Atoms::WM_CLIENT_LEADER, XCB_ATOM_WINDOW, 0, 1); updateLeader(conn, leaderCookie); } else if (atom == XCB_ATOM_WM_HINTS) { const xcb_get_property_cookie_t hintsCookie = xcb_icccm_get_wm_hints(conn, mWindow); updateHints(conn, hintsCookie); } else if (atom == XCB_ATOM_WM_CLASS) { const xcb_get_property_cookie_t classCookie = xcb_icccm_get_wm_class(conn, mWindow); updateClass(conn, classCookie); } else if (atom == XCB_ATOM_WM_NAME) { const xcb_get_property_cookie_t nameCookie = xcb_icccm_get_wm_name(conn, mWindow); updateName(conn, nameCookie); } else if (atom == Atoms::WM_PROTOCOLS) { const xcb_get_property_cookie_t protocolsCookie = xcb_icccm_get_wm_protocols(conn, mWindow, Atoms::WM_PROTOCOLS); updateProtocols(conn, protocolsCookie); } else if (atom == ewmhConnection->_NET_WM_STRUT) { const xcb_get_property_cookie_t strutCookie = xcb_ewmh_get_wm_strut(ewmhConnection, mWindow); updateStrut(ewmhConnection, strutCookie); } else if (atom == ewmhConnection->_NET_WM_STRUT_PARTIAL) { const xcb_get_property_cookie_t partialStrutCookie = xcb_ewmh_get_wm_strut_partial(ewmhConnection, mWindow); updatePartialStrut(ewmhConnection, partialStrutCookie); } else if (atom == ewmhConnection->_NET_WM_STATE) { const xcb_get_property_cookie_t stateCookie = xcb_ewmh_get_wm_state(ewmhConnection, mWindow); updateEwmhState(ewmhConnection, stateCookie); } else if (atom == ewmhConnection->_NET_WM_WINDOW_TYPE) { const xcb_get_property_cookie_t typeCookie = xcb_ewmh_get_wm_window_type(ewmhConnection, mWindow); updateWindowTypes(ewmhConnection, typeCookie); } else if (atom == ewmhConnection->_NET_WM_PID) { const xcb_get_property_cookie_t pidCookie = xcb_ewmh_get_wm_pid(ewmhConnection, mWindow); updatePid(ewmhConnection, pidCookie); } else { warning() << "Unhandled propertyNotify atom" << Atoms::name(atom); } }
/** * CAIGroup::remove * @date Modified April 30, 2006 */ void CAIGroup::remove(CEnemy* poEnemy) { std::list<CEnemy*>::iterator oEnemyIter = m_loEnemies.begin(); while (oEnemyIter != m_loEnemies.end()) { if ((*oEnemyIter) == poEnemy) { oEnemyIter = m_loEnemies.erase(oEnemyIter); break; } oEnemyIter++; } // check for removing the leader if (m_poLeader == poEnemy) { updateLeader(); } }
int conductElection(chat_node* curNode, udp_Server* curServer, udp_Server* ackServer){ cout << "Conducting Elections...\n"; int ret = 0 ; int val; //Check if your node has the highest port number. list<UserInfo>::iterator itr,itr2; bool isHighest = true; int numMsgReceived = 0; list<USERINFO> userList = curNode->getUserList(); #ifdef DEBUG cout << curNode->listofUsers.size(); cout << curNode->listofSockets.size(); #endif for(itr = curNode->listofUsers.begin(); itr != curNode->listofUsers.end(); ++itr){ struct UserInfo user = *itr; if((strcmp(user.username,curNode->lead.sName)==0) & (strcmp(user.ipaddress,curNode->lead.sIpAddress)==0) & ((atoi(user.portnum) == curNode->lead.sPort)) ){ curNode->listofUsers.erase(itr); //userList.erase(itr); break; } } userList = curNode->getUserList(); for(itr = userList.begin(); itr != userList.end(); ++itr){ struct UserInfo user = *itr; if((atoi(user.portnum) != curNode->portNum) | (strcmp((user.ipaddress),curNode->ipAddress)!= 0)){ if(strcmp(curNode->rxBytes,user.rxBytes) < 0){ isHighest = false; numMsgReceived = sendElectionMessage(curNode, curServer, ackServer, user, numMsgReceived); }else{ if(strcmp(curNode->rxBytes,user.rxBytes) == 0){ if(curNode->portNum < atoi(user.portnum)){ isHighest = false; numMsgReceived = sendElectionMessage(curNode, curServer, ackServer, user, numMsgReceived); } } } } } //delete &userList; cout << "isHighest:"<<isHighest<<endl; cout <<" numMsg Recevied:"<<numMsgReceived <<endl; //TODO Declare Yourself as the leader //Checking if the size of listofUsers = 2 if((curNode->listofUsers.size() == 1) || (isHighest == true) || (numMsgReceived == 0)){ cout << "I am the leader\n"; curNode->bIsLeader = true; curNode->mStatusmap.clear(); curNode->lastSeqNum = 0; curNode->mClientmap.erase(string(curNode->lead.sIpAddress)+":"+to_string(curNode->lead.sPort)); curNode->listofSockets.clear(); list<USERINFO> userList = curNode->getUserList(); for(itr = userList.begin(); itr != userList.end(); ++itr){ USERINFO user; user = *itr; addSocket(user.ipaddress,atoi(user.portnum)); if(!((strcmp(user.ipaddress,curNode->ipAddress)==0) & ((atoi(user.portnum) == curNode->portNum))) ){ sendLeaderMessage(curNode,curServer,ackServer,user); } } updateLeader(curNode); curNode->statusServer = NORMAL_OPERATION; MESSAGE leaderMsg; string msg = "New Leader elected :" + string(curNode->sUserName); strcpy(leaderMsg.sContent,msg.c_str()); leaderMsg.sType = MESSAGE_TYPE_CHAT; curNode->consoleQueue.push(leaderMsg); } return ret; }