bool		SmallNineAndroid::OnChangeBanker(const void* pBuffer, WORD wDataSize)
	{
		if (wDataSize!=sizeof(CMD_S_ChangeBanker)) 
			return true;

		CMD_S_ChangeBanker* pChangeBanker = (CMD_S_ChangeBanker *)pBuffer;
		if (isSelf(m_wCurBanker))
		{
			SUser* pUser = GetUserInfo();

			CString szMessage;
			szMessage.Format("[%d][%d]下庄完成 做庄次数%d 成绩%I64d", pUser->dwUserID, 
				pUser->dwGameID, pUser->wCurUpBanker, pUser->nBankerCurWin);
			LogEvent(szMessage, TraceLevel_Debug);

			pUser->wCurUpBanker		= 0;
			pUser->nBankerCurWin	= 0;	

			BankerManager::GetSingleton().Remove(pUser->dwUserID);
		}

		m_wCurBanker	= pChangeBanker->wChairID;
		m_nBankerScore  = pChangeBanker->lBankerTreasure;

		return true;
	}
Esempio n. 2
0
/**
 * Calculates and sets the size of the widget for a synchronous message.
 */
void MessageWidget::calculateDimensionsSynchronous()
{
    int x = 0;

    int x1 = m_pOw[Uml::RoleType::A]->centerX();
    int x2 = m_pOw[Uml::RoleType::B]->centerX();

    int widgetWidth = 0;
    if(isSelf()) {
        widgetWidth = 50;
        x = x1 - 2;
    } else if(x1 < x2) {
        x = x1;
        widgetWidth = x2 - x1 + 8;
    } else {
        x = x2 - 8;
        widgetWidth = x1 - x2 + 8;
    }

    QSizeF minSize = minimumSize();
    int widgetHeight = 0;
    if (height() < minSize.height()) {
        widgetHeight = minSize.height();
    } else {
        widgetHeight = height();
    }

    setX(x);
    setSize(widgetWidth, widgetHeight);
}
Esempio n. 3
0
/**
 * Draws the calling arrow with filled in arrowhead, the
 * timeline box and the returning arrow with a dashed line and
 * stick arrowhead.
 */
void MessageWidget::paintSynchronous(QPainter *painter, const QStyleOptionGraphicsItem *option)
{
    int x1 = m_pOw[Uml::RoleType::A]->x();
    int x2 = m_pOw[Uml::RoleType::B]->x();
    int w = width() - 1;
    int h = height();
    int offsetX = 0;
    int offsetY = 0;

    bool messageOverlaps = m_pOw[Uml::RoleType::A]->messageOverlap(y(), this);
    const int boxWidth = 17;
    const int wr = w < boxWidth ? w : boxWidth;
    const int arrowWidth = 4;

    if(isSelf()) {
        painter->fillRect(offsetX, offsetY, wr, h,  QBrush(Qt::white));              //box
        painter->drawRect(offsetX, offsetY, wr, h);                                    //box
        offsetX += wr;
        w -= wr;
        offsetY += 3;
        const int lowerLineY = offsetY + h - 6;
        // draw upper line segment (leaving the life line)
        painter->drawLine(offsetX, offsetY, offsetX + w, offsetY);
        // draw line segment parallel to (and at the right of) the life line
        painter->drawLine(offsetX + w, offsetY, offsetX + w, lowerLineY);
        // draw lower line segment (back to the life line)
        paintArrow(painter, offsetX, lowerLineY, w, Qt::LeftArrow);
        offsetX -= wr;
        offsetY -= 3;
    } else if(x1 < x2) {
        if (messageOverlaps)  {
            offsetX += 8;
            w -= 8;
        }
        QPen pen = painter->pen();
        int startX = offsetX + w - wr + 1;
        painter->fillRect(startX, offsetY, wr, h,  QBrush(Qt::white));         //box
        painter->drawRect(startX, offsetY, wr, h);                             //box
        painter->drawLine(offsetX, offsetY + arrowWidth, startX, offsetY + arrowWidth);          //arrow line
        if (w > boxWidth + arrowWidth)
            paintSolidArrowhead(painter, startX - 1, offsetY + arrowWidth, Qt::RightArrow);
        paintArrow(painter, offsetX, offsetY + h - arrowWidth + 1, w - wr + 1, Qt::LeftArrow, true); // return arrow
        if (messageOverlaps)  {
            offsetX -= 8; //reset for drawSelected()
        }
    } else      {
        if (messageOverlaps)  {
            w -=8;
        }
        QPen pen = painter->pen();
        painter->fillRect(offsetX, offsetY, wr, h,  QBrush(Qt::white));              //box
        painter->drawRect(offsetX, offsetY, wr, h);                                    //box
        painter->drawLine(offsetX + wr + 1, offsetY + arrowWidth, offsetX + w, offsetY + arrowWidth);    //arrow line
        if (w > boxWidth + arrowWidth)
            paintSolidArrowhead(painter, offsetX + wr, offsetY + arrowWidth, Qt::LeftArrow);
        paintArrow(painter, offsetX + wr + 1, offsetY + h - arrowWidth + 1, w - wr - 1, Qt::RightArrow, true); // return arrow
    }

    UMLWidget::paint(painter, option);
}
Esempio n. 4
0
int TlenMUCRecvPresence(const char *from, int status, int flags, const char *kick)
{
	char str[512];
//	if (JabberListExist(LIST_CHATROOM, from)) {
		char *nick, *roomId, *userId;
		MUCCEVENT mucce;
		roomId = JabberLoginFromJID(from);
		userId = JabberResourceFromJID(from);
		nick = getDisplayName(userId);
		mucce.cbSize = sizeof(MUCCEVENT);
		mucce.pszModule = jabberProtoName;
		mucce.pszID = roomId;
		mucce.iType = MUCC_EVENT_STATUS;
		mucce.pszUID = userId;//from;
		mucce.pszNick = nick;
		mucce.time = time(NULL);
		mucce.bIsMe = isSelf(roomId, userId);
		mucce.dwData = status;
		mucce.dwFlags = 0;
		if (flags & USER_FLAGS_GLOBALOWNER) mucce.dwFlags |= MUCC_EF_USER_GLOBALOWNER;
		if (flags & USER_FLAGS_OWNER) mucce.dwFlags |= MUCC_EF_USER_OWNER;
		if (flags & USER_FLAGS_ADMIN) mucce.dwFlags |= MUCC_EF_USER_ADMIN;
		if (flags & USER_FLAGS_REGISTERED) mucce.dwFlags |= MUCC_EF_USER_REGISTERED;
		if (status == ID_STATUS_OFFLINE && mucce.bIsMe && kick!=NULL) {
			mucce.iType = MUCC_EVENT_ERROR;
			sprintf(str, TranslateT("You have been kicked. Reason: %s "), kick);
			mucce.pszText = str;
		}
		CallService(MS_MUCC_EVENT, 0, (LPARAM) &mucce);
		mir_free(roomId);
		mir_free(userId);
		mir_free(nick);
//	}
	return 0;
}
Esempio n. 5
0
/**
 * Calculates and sets the size of the widget for an asynchronous message.
 */
void MessageWidget::calculateDimensionsAsynchronous()
{
    int x = 0;

    int x1 = m_pOw[Uml::RoleType::A]->centerX();
    int x2 = m_pOw[Uml::RoleType::B]->centerX();

    int widgetWidth = 0;
    int widgetHeight = 8;
    if(isSelf()) {
        widgetWidth = 50;
        x = x1;
        if(height() < 20) {
            widgetHeight = 20;
        } else {
            widgetHeight = height();
        }
    } else if(x1 < x2) {
        x = x1;
        widgetWidth = x2 - x1;
    } else {
        x = x2;
        widgetWidth = x1 - x2;
    }
    x += 1;
    widgetWidth -= 2;
    setX(x);
    setSize(widgetWidth, widgetHeight);
}
	bool		SmallNineAndroid::CanOffline()
	{
		if (isSelf(m_wCurBanker) || m_nChipInScore > 0)
			return 0;

		return true;
	}
Esempio n. 7
0
void TypeConstraint::verifyFail(const Func* func, int paramNum,
                                const TypedValue* tv) const {
  Transl::VMRegAnchor _;
  std::ostringstream fname;
  fname << func->fullName()->data() << "()";
  const StringData* tn = typeName();
  if (isSelf()) {
    selfToTypeName(func, &tn);
  } else if (isParent()) {
    parentToTypeName(func, &tn);
  }

  auto const givenType = describe_actual_type(tv);

  if (isExtended()) {
    // Extended type hints raise warnings instead of recoverable
    // errors for now, to ease migration (we used to not check these
    // at all at runtime).
    assert(nullable() &&
           "only nullable extended type hints are currently supported");
    raise_warning(
      "Argument %d to %s must be of type ?%s, %s given",
      paramNum + 1, fname.str().c_str(), tn->data(), givenType);
  } else {
    raise_recoverable_error(
      "Argument %d passed to %s must be an instance of %s, %s given",
      paramNum + 1, fname.str().c_str(), tn->data(), givenType);
  }
}
Esempio n. 8
0
    void ReplSetImpl::init(OperationContext* txn, ReplSetSeedList& replSetSeedList) {
        mgr = new Manager(this);

        _cfg = 0;
        memset(_hbmsg, 0, sizeof(_hbmsg));
        strcpy(_hbmsg , "initial startup");
        changeState(MemberState::RS_STARTUP);

        _seeds = &replSetSeedList.seeds;

        LOG(1) << "replSet beginning startup..." << rsLog;

        loadConfig(txn);

        unsigned sss = replSetSeedList.seedSet.size();
        for (Member *m = head(); m; m = m->next()) {
            replSetSeedList.seedSet.erase(m->h());
        }
        for (set<HostAndPort>::iterator i = replSetSeedList.seedSet.begin();
                i != replSetSeedList.seedSet.end();
                i++) {
            if (isSelf(*i)) {
                if (sss == 1) {
                    LOG(1) << "replSet warning self is listed in the seed list and there are no "
                              "other seeds listed did you intend that?" << rsLog;
                }
            }
            else {
                log() << "replSet warning command line seed " << i->toString()
                      << " is not present in the current repl set config" << rsLog;
            }
        }
    }
Esempio n. 9
0
QString HistoryItem::inDialogsText(DrawInDialog way) const {
	auto getText = [this]() {
		if (_media) {
			return _media->chatListText();
		} else if (!emptyText()) {
			return TextUtilities::Clean(_text.originalText());
		}
		return QString();
	};
	const auto plainText = getText();
	const auto sender = [&]() -> PeerData* {
		if (isPost() || isEmpty() || (way == DrawInDialog::WithoutSender)) {
			return nullptr;
		} else if (!_history->peer->isUser() || out()) {
			return author();
		} else if (_history->peer->isSelf() && !Has<HistoryMessageForwarded>()) {
			return senderOriginal();
		}
		return nullptr;
	}();
	if (sender) {
		auto fromText = sender->isSelf() ? lang(lng_from_you) : sender->shortName();
		auto fromWrapped = textcmdLink(1, lng_dialogs_text_from_wrapped(lt_from, TextUtilities::Clean(fromText)));
		return lng_dialogs_text_with_from(lt_from_part, fromWrapped, lt_message, plainText);
	}
	return plainText;
}
Esempio n. 10
0
void TypeConstraint::init() {
  if (UNLIKELY(s_typeNamesToTypes.empty())) {
    const struct Pair {
      const StringData* name;
      Type type;
    } pairs[] = {
      { makeStaticString("HH\\bool"),   { KindOfBoolean, MetaType::Precise }},
      { makeStaticString("HH\\int"),    { KindOfInt64,   MetaType::Precise }},
      { makeStaticString("HH\\float"),  { KindOfDouble,  MetaType::Precise }},
      { makeStaticString("HH\\string"), { KindOfString,  MetaType::Precise }},
      { makeStaticString("array"),      { KindOfArray,   MetaType::Precise }},
      { makeStaticString("HH\\resource"), { KindOfResource,
                                                         MetaType::Precise }},
      { makeStaticString("HH\\num"),    { KindOfDouble,  MetaType::Number }},
      { makeStaticString("self"),       { KindOfObject,  MetaType::Self }},
      { makeStaticString("parent"),     { KindOfObject,  MetaType::Parent }},
      { makeStaticString("callable"),   { KindOfObject,  MetaType::Callable }},
    };
    for (unsigned i = 0; i < sizeof(pairs) / sizeof(Pair); ++i) {
      s_typeNamesToTypes[pairs[i].name] = pairs[i].type;
    }
  }

  if (isTypeVar()) {
    // We kept the type variable type constraint to correctly check child
    // classes implementing abstract methods or interfaces.
    m_type.dt = KindOfInvalid;
    m_type.metatype = MetaType::Precise;
    return;
  }

  if (m_typeName == nullptr) {
    m_type.dt = KindOfInvalid;
    m_type.metatype = MetaType::Precise;
    return;
  }

  Type dtype;
  TRACE(5, "TypeConstraint: this %p type %s, nullable %d\n",
        this, m_typeName->data(), isNullable());
  auto const mptr = folly::get_ptr(s_typeNamesToTypes, m_typeName);
  if (mptr) dtype = *mptr;
  if (!mptr ||
      !(isHHType() || dtype.dt == KindOfArray ||
        dtype.metatype == MetaType::Parent ||
        dtype.metatype == MetaType::Self ||
        dtype.metatype == MetaType::Callable)) {
    TRACE(5, "TypeConstraint: this %p no such type %s, treating as object\n",
          this, m_typeName->data());
    m_type = { KindOfObject, MetaType::Precise };
    m_namedEntity = Unit::GetNamedEntity(m_typeName);
    TRACE(5, "TypeConstraint: NamedEntity: %p\n", m_namedEntity);
    return;
  }
  m_type = dtype;
  assert(m_type.dt != KindOfStaticString);
  assert(IMPLIES(isParent(), m_type.dt == KindOfObject));
  assert(IMPLIES(isSelf(), m_type.dt == KindOfObject));
  assert(IMPLIES(isCallable(), m_type.dt == KindOfObject));
}
	bool		SmallNineAndroid::OnApplyBanker(const void* pBuffer, WORD wDataSize)
	{
		if (wDataSize != sizeof(CMD_S_ApplyBanker)) 
			return 0;

		CMD_S_ApplyBanker* pApplyBanker = (CMD_S_ApplyBanker *)pBuffer;

		SUser* pUser = m_pUserManager->Search(pApplyBanker->szAccount);
		if (pUser != NULL)
		{
			if (pApplyBanker->bApplyBanker)
			{
				if (BankerManager::GetSingleton().Search(pUser->dwUserID) == NULL)
				{
					BankerManager::GetSingleton().Insert(
						new SBanker(pApplyBanker->szAccount, pApplyBanker->lScore, pUser->dwUserID)
						);
				}
			}
			else
			{
				BankerManager::GetSingleton().Remove(pUser->dwUserID);
			}

			if (isSelf(pUser->dwUserID))
			{
				BankerManager::GetSingleton().RemoveRequest(pUser->dwUserID);

				CString szMessage;
				szMessage.Format("[%d][%d]已移除上庄请求,当前请求次数%d", GetUserID(), GetGameID(), BankerManager::GetSingleton().GetRequestCount());
				LogEvent(szMessage, TraceLevel_Debug);
			}
		}
		return true;
	}
Esempio n. 12
0
bool Process::isAlive()
{
    if (!isSelf())
    {
        if (!boost::filesystem::exists(lockfilePath))
        {
            return false;
        }

		bool result;
		{
			boost::mutex::scoped_lock lock(isAliveMutex);
			boost::interprocess::file_lock fileLock(lockfilePath.string().c_str());
			result = !fileLock.try_lock();
			if (!result)
			{
				fileLock.unlock();
			}
		}
        return result;
    }
    else
    {
        return true;
    }
}
Esempio n. 13
0
bool TypeConstraint::checkTypeAliasNonObj(const TypedValue* tv) const {
  assert(tv->m_type != KindOfObject); // this checks when tv is not an object
  assert(!isSelf() && !isParent());

  auto p = getTypeAliasOrClassWithAutoload(m_namedEntity, m_typeName);
  auto td = p.first;
  auto c = p.second;

  // Common case is that we actually find the alias:
  if (td) {
    if (td->nullable && tv->m_type == KindOfNull) return true;
    return td->any || equivDataTypes(td->kind, tv->m_type);
  }

  // Otherwise, this isn't a proper type alias, but it *might* be a
  // first-class enum. Check if the type is an enum and check the
  // constraint if it is. We only need to do this when the underlying
  // type is not an object, since only int and string can be enums.
  if (c && isEnum(c)) {
    auto dt = c->enumBaseTy();
    // For an enum, if the underlying type is mixed, we still require
    // it is either an int or a string!
    if (dt) {
      return equivDataTypes(*dt, tv->m_type);
    } else {
      return IS_INT_TYPE(tv->m_type) || IS_STRING_TYPE(tv->m_type);
    }
  }
  return false;
}
	bool		SmallNineAndroid::OnUpdateTime(float fElapsed)
	{
		m_fElapsed += fElapsed;
		if ((m_fElapsed / 60) >= m_fOnlineTime)
		{
			if (isSelf(m_wCurBanker))
			{
				m_fOnlineTime	= AndroidTimer::rdit(5, 15);
				m_fElapsed		= 0;
			}
			else
			{
				if (m_nChipInScore <= 0)
				{
					CString szMessage;
					szMessage.Format("[%d][%d]到达在线时间, 立刻下线", GetUserID(), GetGameID());
					LogEvent(szMessage, TraceLevel_Exception);

					BankerManager::GetSingleton().Remove(m_dwUserID);

					SetStatus(US_OFFLINE);
				}
				else
				{
					m_fOnlineTime	= AndroidTimer::rdit(5, 15);
					m_fElapsed		= 0;
				}
			}
		}
		return true;
	}
Esempio n. 15
0
MaybeDataType TypeConstraint::underlyingDataTypeResolved() const {
  assert(!isSelf() && !isParent());
  if (!hasConstraint()) return folly::none;

  auto t = underlyingDataType();

  // If we aren't a class or type alias, nothing special to do.
  if (!isObjectOrTypeAlias()) return t;

  auto p = getTypeAliasOrClassWithAutoload(m_namedEntity, m_typeName);
  auto td = p.first;
  auto c = p.second;

  // See if this is a type alias.
  if (td) {
    if (td->kind != KindOfObject) {
      t = td->kind;
    } else {
      c = td->klass;
    }
  }

  // If the underlying type is a class, see if it is an enum and get that.
  if (c && isEnum(c)) {
    t = c->enumBaseTy();
  }

  return t;
}
Esempio n. 16
0
int TlenMUCRecvMessage(const char *from, long timestamp, XmlNode *bodyNode)
{
//	if (JabberListExist(LIST_CHATROOM, from)) {
		char *localMessage;
		char *nick, *style, *roomId, *userId;
		int	 iStyle;
		MUCCEVENT mucce;
		roomId = JabberLoginFromJID(from);
		userId = JabberResourceFromJID(from);
		nick = getDisplayName(userId);
		localMessage = JabberTextDecode(bodyNode->text);
		mucce.cbSize = sizeof(MUCCEVENT);
		mucce.iType = MUCC_EVENT_MESSAGE;
		mucce.pszID = roomId;
		mucce.pszModule = jabberProtoName;
		mucce.pszText = localMessage;
		mucce.pszUID = userId;//from;
		mucce.pszNick = nick;
		mucce.time = timestamp;
		mucce.bIsMe = isSelf(roomId, userId);
		mucce.dwFlags = 0;
		mucce.iFontSize = 0;
		style = JabberXmlGetAttrValue(bodyNode, "f");
		if (style!=NULL) {
			iStyle = atoi(style);
			if (iStyle & 1) mucce.dwFlags |= MUCC_EF_FONT_BOLD;
			if (iStyle & 2) mucce.dwFlags |= MUCC_EF_FONT_ITALIC;
			if (iStyle & 4) mucce.dwFlags |= MUCC_EF_FONT_UNDERLINE;
		}
		style = JabberXmlGetAttrValue(bodyNode, "c");
		if (style!=NULL && strlen(style)>5) {
			iStyle = (stringToHex(style)<<16) | (stringToHex(style+2)<<8) | stringToHex(style+4);
		} else {
			iStyle = 0xFFFFFFFF;
		}
		mucce.color = (COLORREF) iStyle;
		style = JabberXmlGetAttrValue(bodyNode, "s");
		if (style!=NULL) {
			iStyle = atoi(style);
		} else {
			iStyle = 0;
		}
		mucce.iFontSize = iStyle;
		style = JabberXmlGetAttrValue(bodyNode, "n");
		if (style!=NULL) {
			iStyle = atoi(style)-1;
		} else {
			iStyle = 0;
		}
		mucce.iFont = iStyle;
		CallService(MS_MUCC_EVENT, 0, (LPARAM) &mucce);
		mir_free(roomId);
		mir_free(userId);
		mir_free(nick);
		mir_free(localMessage);
//	}
	return 0;
}
Esempio n. 17
0
bool TypeConstraint::checkTypedefNonObj(const TypedValue* tv) const {
  assert(tv->m_type != KindOfObject); // this checks when tv is not an object
  assert(!isSelf() && !isParent());

  auto const td = getTypedefWithAutoload(m_namedEntity, m_typeName);
  if (!td) return false;
  if (td->nullable && IS_NULL_TYPE(tv->m_type)) return true;
  return td->kind == KindOfAny || equivDataTypes(td->kind, tv->m_type);
}
Esempio n. 18
0
bool TypeConstraint::checkTypedefObj(const TypedValue* tv) const {
  assert(tv->m_type == KindOfObject); // this checks when tv is an object
  assert(!isSelf() && !isParent() && !isCallable());

  auto const td = getTypedefWithAutoload(m_namedEntity, m_typeName);
  if (!td) return false;
  if (td->nullable && IS_NULL_TYPE(tv->m_type)) return true;
  if (td->kind != KindOfObject) return td->kind == KindOfAny;
  return td->klass && tv->m_data.pobj->instanceof(td->klass);
}
Esempio n. 19
0
void TypeConstraint::verifyFail(const Func* func, int paramNum,
                                TypedValue* tv) const {
  JIT::VMRegAnchor _;

  const StringData* tn = typeName();
  if (isSelf()) {
    selfToTypeName(func, &tn);
  } else if (isParent()) {
    parentToTypeName(func, &tn);
  }

  auto const givenType = describe_actual_type(tv);

  auto c = tvToCell(tv);
  if (isArray() && !isSoft() && !func->mustBeRef(paramNum) &&
      c->m_type == KindOfObject && c->m_data.pobj->isCollection()) {
    // To ease migration, the 'array' type constraint will implicitly cast
    // collections to arrays, provided the type constraint is not soft and
    // the parameter is not by reference. We raise a notice to let the user
    // know that there was a type mismatch and that an implicit conversion
    // was performed.
    raise_notice(
      folly::format(
        "Argument {} to {}() must be of type {}, {} given; argument {} was "
        "implicitly cast to array",
        paramNum + 1, func->fullName()->data(), fullName(), givenType,
        paramNum + 1
      ).str()
    );
    tvCastToArrayInPlace(tv);
    return;
  }

  if (isExtended() && isSoft()) {
    // Soft extended type hints raise warnings instead of recoverable
    // errors, to ease migration.
    raise_debugging(
      "Argument %d to %s() must be of type %s, %s given",
      paramNum + 1, func->fullName()->data(), fullName().c_str(), givenType);
  } else if (isExtended() && isNullable()) {
    raise_typehint_error(
      folly::format(
        "Argument {} to {}() must be of type {}, {} given",
        paramNum + 1, func->fullName()->data(), fullName(), givenType
      ).str()
    );
  } else {
    raise_typehint_error(
      folly::format(
        "Argument {} passed to {}() must be an instance of {}, {} given",
        paramNum + 1, func->fullName()->data(), tn->data(), givenType
      ).str()
    );
  }
}
Esempio n. 20
0
void StaticClassName::outputCodeModel(CodeGenerator &cg) {
  if (isSelf()) {
    cg.printf("self");
  } else if (isParent()) {
    cg.printf("parent");
  } else if (isStatic()) {
    cg.printf("static");
  } else {
    cg.printf("%s", m_origClassName.c_str());
  }
}
Esempio n. 21
0
 void HybridReplicationCoordinator::setImplConfigHack(const ReplSetConfig* config) {
     int myIndex = -1;
     for (size_t i = 0; i < config->members.size(); ++i) { // find my index in the config
         if (isSelf(config->members[i].h)) {
             myIndex = i;
             break;
         }
     }
     fassert(18646, myIndex >= 0);
     _impl.forceCurrentRSConfigHack(config->asBson(), myIndex);
 }
Esempio n. 22
0
void StaticClassName::outputCodeModel(CodeGenerator &cg) {
  if (isSelf()) {
    cg.printValue("self");
  } else if (isParent()) {
    cg.printValue("parent");
  } else if (isStatic()) {
    cg.printValue("static");
  } else {
    cg.printValue(m_origClassName);
  }
}
Esempio n. 23
0
void Process::join()
{
    if (!isSelf())
    {
        if (boost::filesystem::exists(lockfilePath))
        {
            boost::interprocess::file_lock fileLock(lockfilePath.string().c_str());
            boost::interprocess::scoped_lock<boost::interprocess::file_lock> lock(fileLock);
        }
    }
}
Esempio n. 24
0
    void Manager::checkElectableSet() {
        unsigned otherOp = rs->lastOtherOpTime().getSecs();
        
        // make sure the electable set is up-to-date
        if (rs->elect.aMajoritySeemsToBeUp() &&
            rs->iAmPotentiallyHot() &&
            (otherOp == 0 || rs->lastOpTimeWritten.getSecs() >= otherOp - 10)) {
            theReplSet->addToElectable(rs->selfId());
        }
        else {
            theReplSet->rmFromElectable(rs->selfId());
        }

        // check if we should ask the primary (possibly ourselves) to step down
        const Member *highestPriority = theReplSet->getMostElectable();
        const Member *primary = rs->box.getPrimary();
        
        if (primary && highestPriority &&
            highestPriority->config().priority > primary->config().priority &&
            // if we're stepping down to allow another member to become primary, we
            // better have another member (otherOp), and it should be up-to-date
            otherOp != 0 && highestPriority->hbinfo().opTime.getSecs() >= otherOp - 10) {
            log() << "stepping down " << primary->fullName() << " (priority " <<
                primary->config().priority << "), " << highestPriority->fullName() <<
                " is priority " << highestPriority->config().priority << " and " <<
                (otherOp - highestPriority->hbinfo().opTime.getSecs()) << " seconds behind" << endl;

            if (isSelf(primary->h())) {
                // replSetStepDown tries to acquire the same lock
                // msgCheckNewState takes, so we can't call replSetStepDown on
                // ourselves.
                rs->relinquish();
            }
            else {
                BSONObj cmd = BSON( "replSetStepDown" << 1 );
                ScopedConn conn(primary->fullName());
                BSONObj result;

                try {
                    if (!conn.runCommand("admin", cmd, result, 0)) {
                        log() << "stepping down " << primary->fullName()
                              << " failed: " << result << endl;
                    }
                }
                catch (DBException &e) {
                    log() << "stepping down " << primary->fullName() << " threw exception: "
                          << e.toString() << endl;
                }
            }
        }
    }
Esempio n. 25
0
    void ReplSetImpl::init(OperationContext* txn, ReplSetSeedList& replSetSeedList) {
        mgr = new Manager(this);

        _cfg = 0;
        memset(_hbmsg, 0, sizeof(_hbmsg));
        strcpy(_hbmsg , "initial startup");
        lastH = 0;
        changeState(MemberState::RS_STARTUP);

        _seeds = &replSetSeedList.seeds;

        LOG(1) << "replSet beginning startup..." << rsLog;

        loadConfig(txn);

        unsigned sss = replSetSeedList.seedSet.size();
        for (Member *m = head(); m; m = m->next()) {
            replSetSeedList.seedSet.erase(m->h());
        }
        for (set<HostAndPort>::iterator i = replSetSeedList.seedSet.begin();
                i != replSetSeedList.seedSet.end();
                i++) {
            if (isSelf(*i)) {
                if (sss == 1) {
                    LOG(1) << "replSet warning self is listed in the seed list and there are no "
                              "other seeds listed did you intend that?" << rsLog;
                }
            }
            else {
                log() << "replSet warning command line seed " << i->toString()
                      << " is not present in the current repl set config" << rsLog;
            }
        }

        // Figure out indexPrefetch setting
        std::string& prefetch = getGlobalReplicationCoordinator()->getSettings().rsIndexPrefetch;
        if (!prefetch.empty()) {
            IndexPrefetchConfig prefetchConfig = PREFETCH_ALL;
            if (prefetch == "none")
                prefetchConfig = PREFETCH_NONE;
            else if (prefetch == "_id_only")
                prefetchConfig = PREFETCH_ID_ONLY;
            else if (prefetch == "all")
                prefetchConfig = PREFETCH_ALL;
            else
                warning() << "unrecognized indexPrefetch setting: " << prefetch << endl;
            setIndexPrefetchConfig(prefetchConfig);
        }
    }
Esempio n. 26
0
Process::~Process()
{
    if (isSelf())
    {
        fileLock->unlock();
        delete lockfile;
		// This would clean up resources we used.
		// However, on Windows files will not get removed until
		// the process holding the file is closed.
		// When using the Unity editor the process will not get closed
		// in between tries causing the crash of the process
		// in the next try.
        // boost::filesystem::remove(lockfilePath);
    }
}
Esempio n. 27
0
    /** @param cfgString <setname>/<seedhost1>,<seedhost2> */
    void parseReplSetSeedList(const std::string& cfgString,
                              std::string& setname,
                              std::vector<HostAndPort>& seeds,
                              std::set<HostAndPort>& seedSet) {
        const char *p = cfgString.c_str();
        const char *slash = strchr(p, '/');
        if( slash )
            setname = string(p, slash-p);
        else
            setname = p;
        uassert(13093,
                "bad --replSet config string format is: <setname>[/<seedhost1>,<seedhost2>,...]",
                !setname.empty());

        if( slash == 0 )
            return;

        p = slash + 1;
        while( 1 ) {
            const char *comma = strchr(p, ',');
            if( comma == 0 ) comma = strchr(p,0);
            if( p == comma )
                break;
            {
                HostAndPort m;
                try {
                    m = HostAndPort( string(p, comma-p) );
                }
                catch(...) {
                    uassert(13114, "bad --replSet seed hostname", false);
                }
                uassert(13096, "bad --replSet command line config string - dups?",
                        seedSet.count(m) == 0);
                seedSet.insert(m);
                //uassert(13101, "can't use localhost in replset host list", !m.isLocalHost());
                if (isSelf(m)) {
                    LOG(1) << "replSet ignoring seed " << m.toString() << " (=self)" << rsLog;
                }
                else
                    seeds.push_back(m);
                if( *comma == 0 )
                    break;
                p = comma + 1;
            }
        }
    }
Esempio n. 28
0
/**
 * Overrides method from UMLWidget.
 */
QSizeF MessageWidget::minimumSize() const
{
    if (m_sequenceMessageType == Uml::SequenceMessage::Synchronous) {
        return QSizeF(width(), 20);
    } else if (m_sequenceMessageType == Uml::SequenceMessage::Asynchronous) {
        return isSelf() ? QSizeF(width(), 20) : QSizeF(width(), 8);
    } else if (m_sequenceMessageType == Uml::SequenceMessage::Creation) {
        return QSizeF(width(), 8);
    } else if (m_sequenceMessageType == Uml::SequenceMessage::Lost) {
        return QSizeF(width(), 10);
    } else if (m_sequenceMessageType == Uml::SequenceMessage::Found) {
        return QSizeF(width(), 10);
    } else {
        uWarning() << "Unknown message type";
    }
    return QSize(width(), height());
}
Esempio n. 29
0
std::string TypeConstraint::displayName(const Func* func /*= nullptr*/) const {
  const StringData* tn = typeName();
  std::string name;
  if (isSoft()) {
    name += '@';
  }
  if (isNullable() && isExtended()) {
    name += '?';
  }
  if (func && isSelf()) {
    selfToTypeName(func, &tn);
    name += tn->data();
  } else if (func && isParent()) {
    parentToTypeName(func, &tn);
    name += tn->data();
  } else {
    const char* str = tn->data();
    auto len = tn->size();
    if (len > 3 && tolower(str[0]) == 'h' && tolower(str[1]) == 'h' &&
        str[2] == '\\') {
      bool strip = false;
      const char* stripped = str + 3;
      switch (len - 3) {
        case 3:
          strip = (!strcasecmp(stripped, "int") ||
                   !strcasecmp(stripped, "num"));
          break;
        case 4: strip = !strcasecmp(stripped, "bool"); break;
        case 5: strip = !strcasecmp(stripped, "float"); break;
        case 6: strip = !strcasecmp(stripped, "string"); break;
        case 8:
          strip = (!strcasecmp(stripped, "resource") ||
                   !strcasecmp(stripped, "noreturn") ||
                   !strcasecmp(stripped, "arraykey"));
          break;
        default:
          break;
      }
      if (strip) {
        str = stripped;
      }
    }
    name += str;
  }
  return name;
}
Esempio n. 30
0
void TypeConstraint::init() {
  if (isTypeVar()) {
    // We kept the type variable type constraint to correctly check child
    // classes implementing abstract methods or interfaces.
    m_type.dt = folly::none;
    m_type.metatype = MetaType::Precise;
    return;
  }

  if (m_typeName == nullptr) {
    m_type.dt = folly::none;
    m_type.metatype = MetaType::Precise;
    return;
  }

  Type dtype;
  TRACE(5, "TypeConstraint: this %p type %s, nullable %d\n",
        this, m_typeName->data(), isNullable());
  auto const mptr = typeNameToType(m_typeName);
  if (mptr) dtype = *mptr;
  if (!mptr ||
      !(isHHType() || dtype.dt == KindOfArray ||
        dtype.dt == KindOfBoolean ||
        dtype.dt == KindOfString ||
        dtype.dt == KindOfInt64 ||
        dtype.dt == KindOfDouble ||
        dtype.dt == KindOfResource ||
        dtype.metatype == MetaType::ArrayKey ||
        dtype.metatype == MetaType::Number ||
        dtype.metatype == MetaType::Parent ||
        dtype.metatype == MetaType::Self ||
        dtype.metatype == MetaType::Callable)) {
    TRACE(5, "TypeConstraint: this %p no such type %s, treating as object\n",
          this, m_typeName->data());
    m_type = { KindOfObject, MetaType::Precise };
    m_namedEntity = NamedEntity::get(m_typeName);
    TRACE(5, "TypeConstraint: NamedEntity: %p\n", m_namedEntity);
    return;
  }
  m_type = dtype;
  assert(m_type.dt != KindOfStaticString);
  assert(IMPLIES(isParent(), m_type.dt == KindOfObject));
  assert(IMPLIES(isSelf(), m_type.dt == KindOfObject));
  assert(IMPLIES(isCallable(), m_type.dt == KindOfObject));
}