void CThreadQueue::processCommandBase(IQueueCommand* pCmd) { { synchronized(m_mxStackCommands); m_pCurCmd = pCmd; } processCommand(pCmd); { synchronized(m_mxStackCommands); m_pCurCmd = null; } }
// // getOutputStream() // OutputStream* Socket::getOutputStream() throw(IOException) { if (! isConnected()) { throw IOException("Socket not connected"); } OutputStream* stream = NULL; try { Synchronized synchronized(_sync); { stream = _impl->getOutputStream(); // If this socket has an associated channel then the resulting // output stream delegates all of its operations to the channel. // If the channel is in non-blocking mode then the output stream's // write operations will throw an IllegalBlockingModeException stream->_channel = _channel; } } catch(TIDThr::Exception& e) { throw IOException(e.what()); } return stream; }
// // read() // ssize_t SocketChannel::read(unsigned char* dst, size_t dst_len) throw (NotYetConnectedException, IOException) { // Comprueba si esta conectado if (! isConnected()) { throw NotYetConnectedException("Channel not connected"); } // Comprueba si el extremo de lectura esta cerrado if (_socket->isInputShutdown()) { return -1; } // Obtiene el stream de entrada del socket try { Synchronized synchronized(_sync); { if (_istream == NULL) { _istream = _socket->getInputStream(); } } } catch(TIDThr::Exception& e) { throw IOException(e.what()); } return _istream->read(dst, dst_len); }
// // connect() // void DatagramSocket::connect(const SocketAddress& addr,const char* interface) throw(SocketException, IllegalArgumentException) { // Comprueba si addr es referencia a un objeto InetSocketAddress const InetSocketAddress* addrptr = dynamic_cast<const InetSocketAddress*>(&addr); if (addrptr == NULL) { throw IllegalArgumentException("Invalid SocketAddress"); } try { Synchronized synchronized(_sync); { //_remoteaddr = addrptr->getAddress(); if (_remoteaddr) delete _remoteaddr; _remoteaddr = addrptr->getAddress().clone(); _remoteport = addrptr->getPort(); //_impl->connect(_remoteaddr, _remoteport); _impl->connect(*_remoteaddr, _remoteport,interface); _status |= TID_SOCKET_STATUS_CONNECTED; } } catch(TIDThr::Exception& e) { throw SocketException(e.what()); } }
void Parser::ExpressionStatement() { _message.print(DBUG, "PARSER: In ExpressionStatement()\n"); // [ Expression, [ “=”, Expression ] ], “;” static tokenType firstSet[] = {SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, SYM_SEMICOLON, TOK_IDENT, (tokenType) - 1}; static tokenType followSet[] = {TOK_EOF, KW_ELSE, SYM_CURLY_CLOSE, KW_VOID, KW_INT, KW_FLOAT, SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_CURLY_OPEN, KW_IF, KW_WHILE, KW_RETURN, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, (tokenType) - 1}; string type, type1; if ( synchronized(firstSet, followSet, "Expected Expression Statement") ) { type = Expression(); if( _lookAhead.getTokenType() == SYM_ASSIGN ) { match(SYM_ASSIGN); type1 = Expression(); // check that type1 and type2 are assignment compatible if(!((type == "f" && type1 == "i") || (type == "i" && type1 == "i") || (type == "f" && type1 == "f"))) { _message.print(ERROR, "SEMANTIC-ANALYZER: Semantic issue on line: %i col: %i. Incompatible assignment", _lookAhead.getRow() , _lookAhead.getCol()); } } match(SYM_SEMICOLON); } _message.print(DBUG, "PARSER: End of ExpressionStatement()\n"); }
void Parser::Statement(string functionName) { _message.print(DBUG, "PARSER: In Statement()\n"); // ExpressionStatement // | CompoundStatement // | SelectionStatement // | RepetitionStatement // | ReturnStatement static tokenType statementFirstSet[] = {SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_CURLY_OPEN, KW_IF, KW_WHILE, KW_RETURN, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, SYM_SEMICOLON, (tokenType) - 1}; static tokenType followSet[] = {TOK_EOF, KW_ELSE, SYM_CURLY_CLOSE, KW_VOID, KW_INT, KW_FLOAT, SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_CURLY_OPEN, KW_IF, KW_WHILE, KW_RETURN, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, (tokenType) - 1}; if ( synchronized(statementFirstSet, followSet, "Expected Statement") ) { if ( _lookAhead.getTokenType() == SYM_CURLY_OPEN ) { _symbolTable->openScope(); CompoundStatement(functionName); // _symbolTable->dump(); _symbolTable->closeScope(); } else if ( _lookAhead.getTokenType() == KW_IF ) { SelectionStatement(functionName); } else if ( _lookAhead.getTokenType() == KW_WHILE ) { RepetitionStatement(functionName); } else if ( _lookAhead.getTokenType() == KW_RETURN ) { ReturnStatement(functionName); } else { ExpressionStatement(); } } _message.print(DBUG, "PARSER: End of Statement()\n"); }
string Parser::TypeSpecifier() { _message.print(DBUG, "PARSER: In TypeSpecifier()\n"); // “void” // | “int” // | “float” static tokenType firstSet[] = {KW_FLOAT, KW_INT, KW_VOID, (tokenType) -1}; static tokenType followSet[] = {TOK_IDENT, (tokenType) -1}; string type; if ( synchronized(firstSet, followSet, "Expected TypeSpecifier") ) { if ( _lookAhead.getTokenType() == KW_FLOAT ) { match(KW_FLOAT); type = "f"; } else if ( _lookAhead.getTokenType() == KW_INT ) { match(KW_INT); type = "i"; } else if ( _lookAhead.getTokenType() == KW_VOID ) { match(KW_VOID); type = "v"; } } _message.print(DBUG, "PARSER: End of TypeSpecifier()\n"); return type; }
void Parser::ReturnStatement(string functionName) { _message.print(DBUG, "PARSER: In ReturnStatement()\n"); // “return”, [ Expression ], “;” static tokenType firstSet[] = {KW_RETURN, (tokenType) - 1}; static tokenType expressionFirstSet[] = {SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, (tokenType) - 1}; static tokenType followSet[] = {TOK_EOF, KW_ELSE, SYM_CURLY_CLOSE, KW_VOID, KW_INT, KW_FLOAT, SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_CURLY_OPEN, KW_IF, KW_WHILE, KW_RETURN, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, (tokenType) - 1}; string type = "v"; // return statements defaults to void if ( synchronized(firstSet, followSet, "Expected Return Statement") ) { match(KW_RETURN); if ( memberOf(_lookAhead.getTokenType(),expressionFirstSet) ) { type = Expression(); } string def = _symbolTable->lookup(functionName); if (!def.empty()) def = def.substr(0,1) == "v" ? "void" : (def.substr(0,1) == "i" ? "int" : "float"); if(def.empty() || def.substr(0,1) != type) { _message.print(ERROR, "SEMANTIC-ANALYZER: Semantic issue on line: %i col: %i. Function '%s' shoule return '%s' value", _lookAhead.getRow() , _lookAhead.getCol(),functionName.c_str(),def.c_str()); } match(SYM_SEMICOLON); } _message.print(DBUG, "PARSER: End of ReturnStatement()\n"); }
void Parser::CompoundStatement(string functionName) { _message.print(DBUG, "PARSER: In CompoundStatement()\n"); //“{”, { Declaration | Statement }, “}” static tokenType compoundStatementFirstSet[] = {SYM_CURLY_OPEN, (tokenType)-1}; static tokenType declarationFirstSet[] = {KW_VOID, KW_INT, KW_FLOAT, (tokenType) - 1}; static tokenType statementFirstSet[] = {SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_CURLY_OPEN, KW_IF, KW_WHILE, KW_RETURN, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, (tokenType) - 1}; static tokenType followSet[] = {TOK_EOF, KW_ELSE, SYM_CURLY_CLOSE, KW_VOID, KW_INT, KW_FLOAT, SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_CURLY_OPEN, KW_IF, KW_WHILE, KW_RETURN, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, (tokenType) - 1}; if ( synchronized(compoundStatementFirstSet, followSet, "Expected Compound Statement") ) { match(SYM_CURLY_OPEN); while ( memberOf(_lookAhead.getTokenType(), declarationFirstSet) || memberOf(_lookAhead.getTokenType(), statementFirstSet) ) { if ( memberOf(_lookAhead.getTokenType(), declarationFirstSet) ) { Declaration(); } else if ( memberOf(_lookAhead.getTokenType(), statementFirstSet) ) { Statement(functionName); } } match(SYM_CURLY_CLOSE); } _message.print(DBUG, "PARSER: End of CompoundStatement()\n"); }
// // write() // ssize_t SocketChannel::write(const unsigned char* src, size_t src_len) throw (NotYetConnectedException, ClosedChannelException, IOException) { // Comprueba si esta conectado if (! isConnected()) { throw NotYetConnectedException("Channel not connected"); } // Comprueba si el extremo de escritura esta cerrado if (_socket->isOutputShutdown()) { throw ClosedChannelException("Channel is closed"); } // Obtiene el stream de entrada del socket try { Synchronized synchronized(_sync); { if (_ostream == NULL) { _ostream = _socket->getOutputStream(); } } } catch(TIDThr::Exception& e) { throw IOException(e.what()); } return _ostream->write(src, src_len); }
string Parser::AndExpression() { _message.print(DBUG, "PARSER: In AndExpression()\n"); // RelationExpression, // { “&&”, RelationExpression } static tokenType firstSet[] = {SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, (tokenType) - 1}; static tokenType followSet[] = {SYM_OR, SYM_ASSIGN, SYM_SEMICOLON, SYM_OPEN, SYM_SQ_OPEN, SYM_COMMA, SYM_CLOSE, (tokenType) - 1}; string type, type1; if ( synchronized(firstSet, followSet, "Expected AND Expression") ) { type = RelationExpression(); while ( _lookAhead.getTokenType() == SYM_AND ) { type = "i"; match(SYM_AND); type1 = RelationExpression(); if (!(type == "i" && type1 == "i")) _message.print(ERROR, "SEMANTIC-ANALYZER: Semantic issue on line: %i col: %i. Conditional statement must return either 0 or 1", _lookAhead.getRow() , _lookAhead.getCol()); } } _message.print(DBUG, "PARSER: End of AndExpression()\n"); return type; }
void CAsyncHttp::cancelRequest(const char* szCallback) { if (!szCallback || !*szCallback ) { LOG(INFO) + "Cancel callback should not be empty. Use * for cancel all"; return; } synchronized(getCommandLock()); CHttpCommand* pCmd = (CHttpCommand*)getCurCommand(); if ( pCmd != null && ( *szCallback == '*' || pCmd->m_strCallback.compare(szCallback) == 0) ) pCmd->cancel(); if ( *szCallback == '*' ) getCommands().clear(); else { for (int i = getCommands().size()-1; i >= 0; i--) { CHttpCommand* pCmd1 = (CHttpCommand*)getCommands().get(i); if ( pCmd1 != null && pCmd1->m_strCallback.compare(szCallback) == 0 ) getCommands().remove(i); } } }
void PacketPool::returnPacket(Packet* p) { JTCSynchronized synchronized(*this); p->next = firstPacket; firstPacket = p; }
void Parser::SelectionStatement(string functionName) { _message.print(DBUG, "PARSER: In SelectionStatement()\n"); // “if”, “(”, Expression, “)”, Statement, [ “else”, Statement ] static tokenType firstSet[] = {KW_IF, (tokenType) - 1}; static tokenType followSet[] = {TOK_EOF, KW_ELSE, SYM_CURLY_CLOSE, KW_VOID, KW_INT, KW_FLOAT, SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_CURLY_OPEN, KW_IF, KW_WHILE, KW_RETURN, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, (tokenType) - 1}; if ( synchronized(firstSet, followSet, "Expected Selection Statement") ) { match(KW_IF); match(SYM_OPEN); if (Expression() != "i") { _message.print(ERROR, "SEMANTIC-ANALYZER: Semantic issue on line: %i col: %i. Invalid expression", _lookAhead.getRow() , _lookAhead.getCol()); } match(SYM_CLOSE); Statement(functionName); if (_lookAhead.getTokenType() == KW_ELSE) { match(KW_ELSE); Statement(functionName); } } _message.print(DBUG, "PARSER: End of SelectionStatement()\n"); }
string Parser::Factor() { _message.print(DBUG, "PARSER: In Factor()\n"); //[ “+” | “-“ ], Value static tokenType firstSet[] = {SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, (tokenType) - 1}; static tokenType followSet[] = {SYM_MUL, SYM_DIV, SYM_MOD, SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_LESS_EQ, SYM_LESS, SYM_GREATER_EQ, SYM_GREATER, SYM_EQUAL, SYM_NOT_EQ, SYM_AND, SYM_OR, SYM_ASSIGN, SYM_SEMICOLON, SYM_OPEN, SYM_SQ_OPEN, SYM_COMMA, SYM_CLOSE, (tokenType) - 1}; string type; if ( synchronized(firstSet, followSet, "Expected Factor") ) { bool isNumeric = false; if ( _lookAhead.getTokenType() == SYM_PLUS ) { match(SYM_PLUS); isNumeric = true; } else if ( _lookAhead.getTokenType() == SYM_MINUS ) { match(SYM_MINUS); isNumeric = true; } type = Value(); if (isNumeric && (type != "i" || type != "f")) { _message.print(ERROR, "SEMANTIC-ANALYZER: Semantic issue on line: %i col: %i. Invalid operation", _lookAhead.getRow() , _lookAhead.getCol()); } } _message.print(DBUG, "PARSER: End of Factor()\n"); return type; }
// // bind() // void Socket::bind(const SocketAddress* bindpoint, const char* interface) throw(IOException, IllegalArgumentException) { // InetSocketAddress a la que nos asociamos (cualquier IP, cualquier puerto) InetSocketAddress addr(PlainSocketImpl::ANY_PORT, _ipv6); InetSocketAddress* addrptr = &addr; // Comprueba si bindpoint es referencia a un objeto InetSocketAddress; en // caso afirmativo, se asocia a dicha direccion if (bindpoint) { addrptr = (InetSocketAddress*) dynamic_cast<const InetSocketAddress*>(bindpoint); if (addrptr == NULL) { throw IllegalArgumentException("Invalid SocketAddress"); } } try { Synchronized synchronized(_sync); { // Asocia el socket a la direccion InetSocketAddress _impl->bind(addrptr->getAddress(), addrptr->getPort(),interface); _status |= TID_SOCKET_STATUS_BOUND; } } catch(TIDThr::Exception& e) { throw IOException(e.what()); } }
// // connect() // void Socket::connect(const SocketAddress& endpoint, time_t timeout,const char* interface) throw(IllegalBlockingModeException, IllegalArgumentException, IOException) { // Comprueba si endpoint es referencia a un objeto InetSocketAddress const InetSocketAddress* addrptr = dynamic_cast<const InetSocketAddress*>(&endpoint); if (addrptr == NULL) { throw IllegalArgumentException("Invalid SocketAddress"); } try { Synchronized synchronized(_sync); { // Comprueba el modo de bloqueo del canal asociado, si existe if (_channel && _channel->isBlocking()==false) { throw IllegalBlockingModeException( "SocketChannel in non-blocking mode"); } // Invoca a la operacion connect de SocketImpl _impl->connect(endpoint, timeout,interface); setConnected(); } } catch(TIDThr::Exception& e) { throw IOException(e.what()); } }
// // getLocalAddress() // InetAddress* Socket::getLocalAddress() throw() { InetAddress* inet = NULL; InetSocketAddress* sock = NULL; try { Synchronized synchronized(_sync); { size_t size; int optID = SocketOptions::_SO_BINDADDR; sock = (InetSocketAddress*) _impl->getOption(optID, size); const InetAddress& addr = sock->getAddress(); unsigned char* data = (unsigned char*) addr.getAddress(size); inet = InetAddress::getByAddress(data, size); } } catch(...) { } delete sock; return inet; }
void Client::moveSurfaceTo(wl_surface* surface, int32_t x, int32_t y) const { synchronized( [this, &surface, &x, &y]() { wfits_manip_move_surface(wfits_manip_, surface, x, y); } ); }
void Client::movePointerTo(int32_t x, int32_t y) const { synchronized( [this, &x, &y]() { wfits_input_move_pointer(wfits_input_, x, y); } ); }
void Client::sendKey(uint32_t key, uint32_t state) const { synchronized( [this, &key, &state]() { wfits_input_key_send(wfits_input_, key, state); } ); }
void LogLoader::checkFirstRun() { if(firstRun) { firstRun = false; emit synchronized(); } }
void CThreadQueue::addQueueCommandToFrontInt(IQueueCommand *pCmd) { LOG(INFO) + "addCommand to front: " + pCmd->toString(); synchronized(m_mxStackCommands); if (!isAlreadyExist(pCmd)) m_stackCommands.addToFront(pCmd); }
void CoreConnection::checkSyncState() { if (_netsToSync.isEmpty() && state() >= Synchronizing) { setState(Synchronized); setProgressText(tr("Synchronized to %1").arg(currentAccount().accountName())); setProgressMaximum(-1); emit synchronized(); } }
Packet* PacketPool::getPacket() { JTCSynchronized synchronized(*this); if (firstPacket != NULL) { Packet* p = firstPacket; firstPacket = p->next; return (p); } else { return (new Packet(packetSize)); } }
void CLog::Log(const char * msg, ...) { CSynchronized synchronized(&_LogSec); static char buffer[LOG_BUFFER_SIZE] = { 0, }; va_list args; va_start(args, msg); vsnprintf_s(buffer, LOG_BUFFER_SIZE, LOG_BUFFER_SIZE - 1, msg, args); va_end(args); std::cout << CurrentDateTime() << " [INFO] " << buffer << std::endl; }
string Parser::RelationExpression() { _message.print(DBUG, "PARSER: In RelationExpression()\n"); // SimpleExpression, // [ ( “<=” | “<” | “>=” | “>” | “==” | “!=” ), // SimpleExpression ] static tokenType firstSet[] = {SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, (tokenType) - 1}; static tokenType followSet[] = {SYM_AND, SYM_OR, SYM_ASSIGN, SYM_SEMICOLON, SYM_OPEN, SYM_SQ_OPEN, SYM_COMMA, SYM_CLOSE, (tokenType) - 1}; static tokenType set[] = {SYM_LESS_EQ, SYM_LESS, SYM_GREATER_EQ, SYM_GREATER, SYM_EQUAL, SYM_NOT_EQ, (tokenType) -1}; string type, type1; if ( synchronized(firstSet, followSet, "Expected Relational Expression") ) { type = SimpleExpression(); if ( memberOf(_lookAhead.getTokenType(), set) ) { //check to make sure both types of simpleexpression are numeric type = "i"; if ( _lookAhead.getTokenType() == SYM_LESS_EQ ) { match(SYM_LESS_EQ); } else if( _lookAhead.getTokenType() == SYM_LESS) { match(SYM_LESS); } else if( _lookAhead.getTokenType() == SYM_GREATER_EQ ) { match(SYM_GREATER_EQ); } else if( _lookAhead.getTokenType() == SYM_GREATER ) { match(SYM_GREATER); } else if( _lookAhead.getTokenType() == SYM_EQUAL ) { match(SYM_EQUAL); } else if( _lookAhead.getTokenType() == SYM_NOT_EQ ) { match(SYM_NOT_EQ); } type1 = SimpleExpression(); if(!((type == "f" && type1 == "i") || (type == "i" && type1 == "i") || (type == "f" && type1 == "f") || (type == "i" && type1 == "f"))) { _message.print(ERROR, "SEMANTIC-ANALYZER: Semantic issue on line: %i col: %i. Incompatible comparision", _lookAhead.getRow() , _lookAhead.getCol()); } } } _message.print(DBUG, "PARSER: End of RelationExpression()\n"); return type; }
void CLog::Error(const char * fileName, const char * funcName, int line, const char * msg, ...) { CSynchronized synchronized(&_LogSec); static char buffer[LOG_BUFFER_SIZE] = { 0, }; va_list args; va_start(args, msg); vsnprintf_s(buffer, LOG_BUFFER_SIZE, LOG_BUFFER_SIZE - 1, msg, args); va_end(args); std::cout << CurrentDateTime() << " [ERROR] " << "File: " << fileName << "\nFunction: " << funcName << "\nLine: " << line \ << "\nError: " << buffer << std::endl; }
void CThreadQueue::processCommands()//throws Exception { while(!isStopping() && !isNoCommands()) { common::CAutoPtr<IQueueCommand> pCmd = null; { synchronized(m_mxStackCommands); pCmd = (IQueueCommand*)m_stackCommands.removeFirst(); } processCommand(pCmd); } }
unsigned long CRhoTimer::getNextTimeout() { synchronized(m_mxAccess); if ( (m_arItems.size() == 0) && (m_arNativeItems.size() == 0) ) return 0; CTimeInterval curTime = CTimeInterval::getCurrentTime(); unsigned long nMinInterval = ((unsigned long)-1); for( int i = 0; i < (int)m_arItems.size(); i++ ) { unsigned long nInterval = 0; if ( m_arItems.elementAt(i).m_oFireTime.toULong() > curTime.toULong() ) { nInterval = m_arItems.elementAt(i).m_oFireTime.toULong() - curTime.toULong(); } else { nInterval=nMinInterval+m_arItems.elementAt(i).m_oFireTime.toULong() - curTime.toULong(); } if ( nInterval < nMinInterval ) nMinInterval = nInterval; } for( int i = 0; i < (int)m_arNativeItems.size(); i++ ) { unsigned long nInterval = 0; if ( m_arNativeItems.elementAt(i).m_oFireTime.toULong() > curTime.toULong() ) { nInterval = m_arNativeItems.elementAt(i).m_oFireTime.toULong() - curTime.toULong(); } else { nInterval=nMinInterval+m_arNativeItems.elementAt(i).m_oFireTime.toULong() - curTime.toULong(); } if ( nInterval < nMinInterval ) nMinInterval = nInterval; } if ( nMinInterval < 100 ) nMinInterval = 100; RAWTRACE1("CRhoTimer::getNextTimeout: %d",nMinInterval); return nMinInterval; }