Esempio n. 1
0
	virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
	{
		CInterfaceManager *pIM = CInterfaceManager::getInstance();
		string dbdst = getParam (Params, "dbdst");
		string dbsrc = getParam (Params, "dbsrc");
		CCDBNodeBranch *pNBdst = pIM->getDbBranch(dbdst);
		CCDBNodeBranch *pNBsrc = pIM->getDbBranch(dbsrc);

		// Branch copy

		if ((pNBdst != NULL) && (pNBsrc != NULL))
		{
			//nlinfo("copying from %s to %s",pNBsrc->getName()->c_str(), pNBdst->getName()->c_str());

			// Parse all children of the src branch
			uint nbLeaves = pNBsrc->countLeaves();
			for (uint i = 0; i < nbLeaves; ++i)
			{
				uint count = i;
				CCDBNodeLeaf *pNLsrc = pNBsrc->findLeafAtCount(count);
				// Find its access name
				string sTmp = *pNLsrc->getName();
				CCDBNodeBranch *pParent = pNLsrc->getParent();
				while (pParent != pNBsrc)
				{
					sTmp = *pParent->getName() + ":" + sTmp;
					pParent = pParent->getParent();
				}
				// Find the correspondant node in the dst branch
				CCDBNodeLeaf *pNLdst = dynamic_cast<CCDBNodeLeaf*>(pNBdst->getNode(ICDBNode::CTextId(sTmp)));
				if (pNLdst == NULL)
				{
					nlwarning ("cannot find destination leaf %s",sTmp.c_str());
				}
				else
				{
					pNLdst->setValue64(pNLsrc->getValue64());

					//sint32 nVal = pNLsrc->getValue64();
					//nlinfo("set value %d for node %s", nVal, sTmp.c_str());
				}
			}
			return;
		}

		// Not branch copy so leaf copy

		CInterfaceProperty ipsrc;
		CInterfaceProperty ipdst;
		if (!ipsrc.link (dbsrc.c_str()))
		{
			nlwarning("cannot find leaf %s",dbsrc.c_str());
			return;
		}
		if (!ipdst.link (dbdst.c_str()))
		{
			nlwarning("cannot find leaf %s",dbdst.c_str());
			return;
		}
		// copy
		ipdst.setSInt64 (ipsrc.getSInt64());
	}
Esempio n. 2
0
	virtual void execute (CCtrlBase *pCaller, const string &Params)
	{
		CInterfaceManager *pIM = CInterfaceManager::getInstance();
		string dblink   = getParam (Params, "dblink");
		string property = getParam (Params, "target_property");
		string propertyToEval = getParam (Params, "target");
		string expr = getParam (Params, "value");
		//nlinfo("set %s %s %s %s", dblink.c_str(), property.c_str(), propertyToEval.c_str(), expr.c_str());
		CInterfaceExprValue value;
		if (CInterfaceExpr::eval(expr, value, NULL))
		{
			if (!dblink.empty())
			{
				// Do not allow Write on SERVER: or LOCAL:
				static const std::string	dbServer= "SERVER:";
				static const std::string	dbLocal= "LOCAL:";
				static const std::string	dbLocalR2= "LOCAL:R2";
				if( (0==dblink.compare(0,    dbServer.size(),    dbServer)) ||
					(0==dblink.compare(0,    dbLocal.size(),    dbLocal))
					)
				{
					if (0!=dblink.compare(0,    dbLocalR2.size(),    dbLocalR2))
					{
						//nlwarning("You are not allowed to write on 'SERVER:...' or 'LOCAL:...' database");
						nlstop;
						return;
					}
				}

				string dblinkeval;
				CInterfaceExpr::unpackDBentry(dblink.c_str(), NULL, dblinkeval);
				if (!value.toInteger())
				{
					nlwarning("<CAHSet:execute> expression doesn't evaluate to a numerical value");
				}
				CInterfaceProperty ip;

				if (!value.toInteger())
				{
					nlwarning("<CAHSet:execute> expression doesn't evaluate to a numerical value");
				}
				if (ip.link (dblinkeval.c_str()))
				{
					ip.setSInt64(value.getInteger());
				}
			}

			if (!propertyToEval.empty())
			{
				CInterfaceExprValue res;
				if (!CInterfaceExpr::eval(propertyToEval, res, NULL)) return;
				res.toString();
				property = res.getString();
			}


			if (!property.empty())
			{
				std::vector<CInterfaceLink::CTargetInfo> targets;
				// find first enclosing group
				CCtrlBase *currCtrl = pCaller;
				CInterfaceGroup *ig = NULL;
				while (currCtrl)
				{
					ig = dynamic_cast<CInterfaceGroup *>(currCtrl);
					if (ig != NULL) break;
					currCtrl = currCtrl->getParent();
				}
				if (ig == NULL)
				{
					string elt = property.substr(0,property.rfind(':'));
					CInterfaceElement *pIE = pIM->getElementFromId(elt);
					ig = dynamic_cast<CInterfaceGroup*>(pIE);
					if (ig == NULL && pIE != NULL)
						ig = pIE->getParent();
				}

				if (ig != NULL)
				{
					CInterfaceParser::splitLinkTargets(property, ig, targets);
					for(uint k = 0; k < targets.size(); ++k)
					{
						if (targets[k].Elem) targets[k].affect(value);
					}
				}
			}
		}
		else
		{
			nlwarning("<CAHSet::execute> Couldn't evaluate expression to affect, expr = %s", expr.c_str());
		}
	}