Exemplo n.º 1
0
Time ScanTime(const char *s, Time def)
{
	Time tm;
	if(StrToTime(tm, s))
		return tm;
	return def;
}
Exemplo n.º 2
0
Time ScanTime(const char *datefmt, const char *s, Time def)
{
	Time tm;
	if(StrToTime(datefmt, tm, s))
		return tm;
	return def;
}
Exemplo n.º 3
0
void CTaskFileHelper::LoadTimeGate(XMLNode node) {
    if (node) {
        GetAttribute(node, _T("number"), PGNumberOfGates);
        LPCTSTR szTime = NULL;
        GetAttribute(node, _T("open-time"), szTime);
        StrToTime(szTime, &PGOpenTimeH, &PGOpenTimeM);
        GetAttribute(node, _T("interval-time"), PGGateIntervalTime);
    }
}
Exemplo n.º 4
0
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormShow(TObject *Sender){
	// 读取本地的一些设置,或是上次的配置参数
	TIniFile *ini = new TIniFile(GetCurrentDir() + "\\app.ini");
	int userId = ini->ReadInteger("Center", "UserId", 0);
	AnsiString st = ini->ReadString("Center", "ST", "");
	DateTimePicker->Time = ini->ReadTime("Center", "ShutdownTime", StrToTime("23:45:00"));
	//是否跳过登录界面
	if (userId ==0 || st ==""){
		LoginForm->ShowModal();
	}else{
		controller->centerId =userId;
		controller->centerSt =st;
	}
    TimerTask->Enabled =true;
	// 创建一个ActionList用于动态保存各个标签页的Action
	actionList = new TActionList(MainForm);
	// 读取本地的一些设置,或是上次的配置参数
	MainForm->Width = ini->ReadInteger("FormSize", "Width", 1024);
	MainForm->Height = ini->ReadInteger("FormSize", "Height", 768);
	delete ini;
	//
	FrameMonitor =new TFrameMonitor(this); 		   //用这个Frame,主要是用来加竖滚动条的,并且支持鼠标滑轮滚动
	FrameMonitor->Parent =PanelMonitorGroup;
	//文件打印内容明细
	StringGridTxt->Cells[0][0] ="行数";
	StringGridTxt->Cells[1][0] ="游戏ID";
	StringGridTxt->Cells[2][0] ="玩法类型";
	StringGridTxt->Cells[3][0] ="投注方式";
	StringGridTxt->Cells[4][0] ="彩票号码";
	StringGridTxt->Cells[5][0] ="倍";
	StringGridTxt->Cells[6][0] ="金额分";
	for (int i =0; i <StringGridTxt->RowCount; i++)	StringGridTxt->Cells[0][i+1] =IntToStr(i +1);
	//后台管理浏览器加载,防止Document设置Cookie时为空
	WideString HomePage =LOGIN_URL;
	WebBrowser->Navigate(HomePage.c_bstr());
	//显示登录页并且最大化窗口
	PageControl->ActivePageIndex =1;
	//总控制器初始化
	controller->Init();
	//调整位置
	FormResize(this);
    ShowErrMessage();
}
Exemplo n.º 5
0
int CTradeOrderManager::Trade(StockTradeOp op, CString const & code, CString const & price, CString const & quant)
{
    // we should make sure code/price/quant have valid value and loc data is ready

    CStockLocateData &loc = theApp.AppData().LocateData();

    HWND tree = nullptr;
    HTREEITEM item = nullptr;
    POINT pos;
    HWND hp = nullptr;
    HWND hc = nullptr;
    HWND hq = nullptr;
    HWND ho = nullptr;
    UINT capId;
    UINT flag;

    switch (op)
    {
    case STO_Buy:
        tree = loc.LocInfo(LT_Buy).hwnd;
        item = loc.LocInfo(LT_Buy).hitem;
        pos = loc.LocInfo(LT_Buy).pos;
        hp = loc.LocInfo(LT_BuyPrice).hwnd;
        hc = loc.LocInfo(LT_BuyCode).hwnd;
        hq = loc.LocInfo(LT_BuyQuant).hwnd;
        ho = loc.LocInfo(LT_BuyOrder).hwnd;
        capId = IDS_BUY_CONFIRM;
        flag = IDS_TRADE_BUY_FLAG;
        break;
    case STO_Sell:
        tree = loc.LocInfo(LT_Sell).hwnd;
        item = loc.LocInfo(LT_Sell).hitem;
        pos = loc.LocInfo(LT_Sell).pos;
        hp = loc.LocInfo(LT_SellPrice).hwnd;
        hc = loc.LocInfo(LT_SellCode).hwnd;
        hq = loc.LocInfo(LT_SellQuant).hwnd;
        ho = loc.LocInfo(LT_SellOrder).hwnd;
        capId = IDS_SELL_CONFIRM;
        flag = IDS_TRADE_SELL_FLAG;
        break;
    default:
        return ST_TO_F;
    }

    HandlePtr process = loc.TargetProcess();

    if (!process)
        return ST_TO_F;

    if (WinApi::SelectTreeItem(process, tree, item, pos))
    {
        ::Sleep(ST_SLEEP_T);

        if (!this->SetText(hc, code))
            return ST_TO_F;

        ::Sleep(ST_SLEEP_T);

        if (!this->SetText(hp, price))
            return ST_TO_F;

        ::Sleep(ST_SLEEP_T);

        if (!this->SetText(hq, quant))
            return ST_TO_F;

        ::Sleep(ST_SLEEP_T);

        ::PostMessage(ho, BM_CLICK, 0, 0); // Must use post

        ::Sleep(ST_SLEEP_T);

        HWND hconfirm = ::FindWindow(nullptr, CString(MAKEINTRESOURCE(capId)));

        if (!hconfirm)
            return ST_TO_F;

        ::SendMessage(hconfirm, WM_COMMAND, MAKEWPARAM(IDOK, 0), 0);

        ::Sleep(ST_SLEEP_T);

        HWND hhint = ::FindWindow(nullptr, CString(MAKEINTRESOURCE(IDS_HINT)));

        if (hhint)
        {
            ::SendMessage(hhint, WM_COMMAND, MAKEWPARAM(IDOK, 0), 0);
        }

        int id = ++m_id;

        TradeOrder &order = m_orders[id];

        order.local = TradeClock::now();
        order.time = order.local;
        order.code = code;
        order.price = price;
        order.quant = quant;
        order.flag.LoadString(flag);
        order.turnover = quant;
        order.deal = true;

        m_total += (_ttoi(quant));

        LocateInfo const& cancel = loc.LocInfo(LT_Cancel);
        if (WinApi::SelectTreeItem(process, tree, cancel.hitem, cancel.pos))
        {
            ::Sleep(ST_SLEEP_T);

            HWND clst = loc.LocInfo(LT_CancelList).hwnd;

            VirtualPtr pItem = MakeVirtualPtr(::VirtualAllocEx(process.get(), nullptr, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE));
            VirtualPtr pText = MakeVirtualPtr(::VirtualAllocEx(process.get(), nullptr, sizeof(TCHAR) * ST_ORDER_COL_LEN, MEM_COMMIT, PAGE_READWRITE));

            int row = ::SendMessage(clst, LVM_GETITEMCOUNT, 0, 0);
            if (row > 0)
            {
                int tcol = loc.ListCol(LT_CancelList, SOF_Time).col;
                for (int i = 0; i < row; ++i)
                {
                    TCHAR timeT[ST_ORDER_COL_LEN] = { 0 };

                    if (WinApi::QueryListItemText(process, clst, i, tcol, &timeT[0], sizeof(TCHAR) * ST_ORDER_COL_LEN, pItem, pText))
                    {
                        TradeTimePoint time = StrToTime(timeT);
                        TradeDuration dura;
                        CalcAbsDuration(dura, time, order.local)

                        if (dura <= sTimeDelt)
                        {
                            int codeCol = loc.ListCol(LT_CancelList, SOF_Code).col;
                            int priceCol = loc.ListCol(LT_CancelList, SOF_Price).col;
                            int quantCol = loc.ListCol(LT_CancelList, SOF_Quant).col;

                            TCHAR codeT[ST_ORDER_COL_LEN] = { 0 };
                            TCHAR priceT[ST_ORDER_COL_LEN] = { 0 };
                            TCHAR quantT[ST_ORDER_COL_LEN] = { 0 };

                            if (WinApi::QueryListItemText(process, clst, i, codeCol, &codeT[0], sizeof(TCHAR) * ST_ORDER_COL_LEN, pItem, pText) &&
                                WinApi::QueryListItemText(process, clst, i, priceCol, &priceT[0], sizeof(TCHAR) * ST_ORDER_COL_LEN, pItem, pText) &&
                                WinApi::QueryListItemText(process, clst, i, quantCol, &quantT[0], sizeof(TCHAR) * ST_ORDER_COL_LEN, pItem, pText))
                            {
                                if ((code == codeT) && (price == priceT) && (quant == quantT))
                                {
                                    order.deal = false;

                                    order.time = time;

                                    int idCol = loc.ListCol(LT_CancelList, SOF_Id).col;
                                    int turnoverCol = loc.ListCol(LT_CancelList, SOF_Turnover).col;

                                    TCHAR idT[ST_ORDER_COL_LEN] = { 0 };
                                    TCHAR turnoverT[ST_ORDER_COL_LEN] = { 0 };

                                    if (WinApi::QueryListItemText(process, clst, i, idCol, &idT[0], sizeof(TCHAR) * ST_ORDER_COL_LEN, pItem, pText) &&
                                        WinApi::QueryListItemText(process, clst, i, turnoverCol, &turnoverT[0], sizeof(TCHAR) * ST_ORDER_COL_LEN, pItem, pText))
                                    {
                                        order.id = idT;
                                        order.turnover = turnoverT;
                                    }

                                    break;
                                }
                            }
                        }
                    }
                }
            }
Exemplo n.º 6
0
bool LoadCupTask(LPCTSTR szFileName) {
  //  LockTaskData();

  mapCode2Waypoint_t mapWaypoint;

  //  ClearTask();
  size_t idxTP = 0;
  bool bTakeOff = true;
  bool bLoadComplet = true;
  bool bLastInvalid=true;

  TCHAR szString[READLINE_LENGTH + 1];
  TCHAR TpCode[NAME_SIZE + 1];

  szString[READLINE_LENGTH] = _T('\0');
  TpCode[NAME_SIZE] = _T('\0');

  memset(szString, 0, sizeof (szString)); // clear Temp Buffer
  WAYPOINT newPoint = {0};
  WAYPOINT* WPtoAdd=NULL;

  enum {
    none, Waypoint, TaskTp, Option
  } FileSection = none;
  zzip_stream stream(szFileName, "rt");
  iNO_Tasks =0;
  TaskIndex =0;
  for (int i =0 ; i< MAX_TASKS;i++)
    szTaskStrings[ i] = NULL;
#define MULTITASKS_CUP
#ifdef MULTITASKS_CUP
    if (stream) {
      while (stream.read_line(szString)) {

          if ((FileSection == none) && ((_tcsncmp(_T("name,code,country"), szString, 17) == 0) ||
              (_tcsncmp(_T("Title,Code,Country"), szString, 18) == 0))) {
              FileSection = Waypoint;
              continue;
          } else if ((FileSection == Waypoint) && (_tcscmp(szString, _T("-----Related Tasks-----")) == 0)) {
              FileSection = TaskTp;
              continue;
          }


          if(  FileSection == TaskTp)
            {
              if(_tcsstr(szString, _T("\",\""))!= NULL)   // really a task? (not an option)
                {
                  if(iNO_Tasks < MAX_TASKS)   // Space in List left
                    {//[READLINE_LENGTH + 1];
                      szTaskStrings[ iNO_Tasks] =  new TCHAR[READLINE_LENGTH + 1];
                      if(  szTaskStrings[ iNO_Tasks] != NULL)
                      {
                        _tcscpy(szTaskStrings[ iNO_Tasks] , szString);  // copy task string
                         // StartupStore(_T("..Cup Task : %s  %s"), szTaskStrings[ iNO_Tasks], NEWLINE);
                        iNO_Tasks++;
                      }
                      else
                        StartupStore(_T("..Cup Task: no memory %s"), NEWLINE);
                    }
                  else
                    StartupStore(_T("..Cup Task Too many Tasks (more than %i) %s"), MAX_TASKS, NEWLINE);
                }
            }
      }
      stream.close();
      StartupStore(_T("..Cup Selected Task:%i %s  %s"), TaskIndex, szTaskStrings[ TaskIndex] , NEWLINE);
    }

  int res = 0;
  if(iNO_Tasks >1)   // Selection only if more than one task found
    res = dlgTaskSelectListShowModal();

  for (int i =0 ; i< MAX_TASKS;i++)    // free dynamic memory
    if(szTaskStrings[i] != NULL)
      {
        // StartupStore(_T("..Cup Task : delete dynamic memoryLine %i %s"), i,NEWLINE);
        delete[] szTaskStrings[i];
        szTaskStrings[i] = NULL;
      }
   if(res == mrCancel)
     return false;

  /***********************************************************************************/

  LockTaskData();
  ClearTask();
  stream.open(szFileName, "rt");
#endif

  FileSection = none;
  int i=0;
  if (stream) {
      while (stream.read_line(szString)) {

          if ((FileSection == none) && ((_tcsncmp(_T("name,code,country"), szString, 17) == 0) ||
              (_tcsncmp(_T("Title,Code,Country"), szString, 18) == 0))) {
              FileSection = Waypoint;
              continue;
          } else if ((FileSection == Waypoint) && (_tcscmp(szString, _T("-----Related Tasks-----")) == 0)) {
              FileSection = TaskTp;

              continue;
          }

          TCHAR *pToken = NULL;
          TCHAR *pWClast = NULL;

          switch (FileSection) {
          case Waypoint:
            memset(&newPoint, 0, sizeof(newPoint));
            if (ParseCUPWayPointString(szString, &newPoint)) {
                mapWaypoint[newPoint.Name] = newPoint;
            }
            break;
          case TaskTp:
            // 1. Description
            //       First column is the description of the task. If filled it should be double quoted.
            //       If left empty, then SeeYou will determine the task type on runtime.
            if ((pToken = strsep_r(szString, TEXT(","), &pWClast)) == NULL) {
                //  UnlockTaskData();  // no need to skip if only name missing!!!
                //  return false;
            }

            // 2. and all successive columns, separated by commas
            //       Each column represents one waypoint name double quoted. The waypoint name must be exactly the
            //       same as the Long name of a waypoint listed above the Related tasks.
            WPtoAdd=NULL;

            if (i++ == TaskIndex)  // load selected task
              {
                while (bLoadComplet && (pToken = strsep_r(NULL, TEXT(","), &pWClast)) != NULL) {
                    if (idxTP < MAXTASKPOINTS) {
                        _tcsncpy(TpCode, pToken, NAME_SIZE);
                        CleanCupCode(TpCode);
                        mapCode2Waypoint_t::iterator It = mapWaypoint.find(TpCode);
                        if(!ISGAAIRCRAFT) {
                            if (It != mapWaypoint.end()) {
                                if (bTakeOff) {
                                    // skip TakeOff Set At Home Waypoint
                                    int ix = FindOrAddWaypoint(&(It->second),false);
                                    if (ix>=0) {
#if 0 // REMOVE
                                        // We must not change HomeWaypoint without user knowing!
                                        // The takeoff and homewaypoint are independent from task.
                                        // In addition, this is a bug because on next run the index is invalid
                                        // and we have no more HowWaypoint!
                                        HomeWaypoint = ix;
#endif
                                        bTakeOff = false;
                                    }
#if BUGSTOP
                                    else LKASSERT(0); // .. else is unmanaged, TODO
#endif
                                } else {
                                    int ix =  FindOrAddWaypoint(&(It->second),false);
                                    if (ix>=0) Task[idxTP++].Index = ix;
#if BUGSTOP
                                    else LKASSERT(0); // .. else is unmanaged, TODO
#endif
                                }
                                bLastInvalid=false;
                            } else {
                                // An invalid takeoff, probably a "???" , which we ignore
#if TESTBENCH
                                if (bTakeOff) StartupStore(_T("....... CUP Takeoff not found: <%s>\n"),TpCode);
#endif
                                // in any case bTakeOff now is false
                                bTakeOff=false;
                                bLastInvalid=true;
                            }
                        } else { //ISGAIRRCRAFT
                            if(It != mapWaypoint.end()) {
                                if(WPtoAdd!=NULL) {
                                    //add what we found in previous cycle: it was not the last one
                                    int ix = FindOrAddWaypoint(WPtoAdd,false);
                                    if (ix>=0) Task[idxTP++].Index = ix;
#if BUGSTOP
                                    else LKASSERT(0); // .. else is unmanaged, TODO
#endif
                                }
                                if (bTakeOff) { //it's the first: may be we have a corresponding airfield
                                    //look for departure airfield and add it
                                    int ix = FindOrAddWaypoint(&(It->second),true);
                                    if (ix>=0) {
                                        Task[idxTP++].Index = ix;
                                        bTakeOff = false;
                                    }
#if BUGSTOP
                                    else LKASSERT(0); // .. else is unmanaged, TODO
#endif
                                } else WPtoAdd=&(It->second); //store it for next cycle (may be it is the last one)
                            }
                        }
                    } else {
                        bLoadComplet = false;
                    }
                }
                if(ISGAAIRCRAFT) { //For GA: check if we have an airport corresponding to the last WP
                    if(WPtoAdd!=NULL) { //if we have the last one (probably an airfield) still to add...
                        if(idxTP<MAXTASKPOINTS) {
                            int ix=FindOrAddWaypoint(WPtoAdd,true); //look for arrival airport and add it
                            if (ix>=0) {
                                Task[idxTP++].Index= ix;
                            }
#if BUGSTOP
                            else LKASSERT(0); // .. else is unmanaged, TODO
#endif
                        }
                        else bLoadComplet=false;
                    }
                }
                FileSection = Option;
              }
            break;
          case Option:
            if ((pToken = strsep_r(szString, TEXT(","), &pWClast)) != NULL) {
                if (_tcscmp(pToken, _T("Options")) == 0) {
                    while ((pToken = strsep_r(NULL, TEXT(","), &pWClast)) != NULL) {
                        if (_tcsstr(pToken, _T("NoStart=")) == pToken) {
                            // Opening of start line
                            PGNumberOfGates = 1;
                            StrToTime(pToken + 8, &PGOpenTimeH, &PGOpenTimeM);
                        } else if (_tcsstr(pToken, _T("TaskTime=")) == pToken) {
                            // Designated Time for the task
                            // TODO :
                        } else if (_tcsstr(pToken, _T("WpDis=")) == pToken) {
                            // Task distance calculation. False = use fixes, True = use waypoints
                            // TODO :
                        } else if (_tcsstr(pToken, _T("NearDis=")) == pToken) {
                            // Distance tolerance
                            // TODO :
                        } else if (_tcsstr(pToken, _T("NearAlt=")) == pToken) {
                            // Altitude tolerance
                            // TODO :
                        } else if (_tcsstr(pToken, _T("MinDis=")) == pToken) {
                            // Uncompleted leg.
                            // False = calculate maximum distance from last observation zone.
                            // TODO :
                        } else if (_tcsstr(pToken, _T("RandomOrder=")) == pToken) {
                            // if true, then Random order of waypoints is checked
                            // TODO :
                        } else if (_tcsstr(pToken, _T("MaxPts=")) == pToken) {
                            // Maximum number of points
                            // TODO :
                        } else if (_tcsstr(pToken, _T("BeforePts=")) == pToken) {
                            // Number of mandatory waypoints at the beginning. 1 means start line only, two means
                            //      start line plus first point in task sequence (Task line).
                            // TODO :
                        } else if (_tcsstr(pToken, _T("AfterPts=")) == pToken) {
                            // Number of mandatory waypoints at the end. 1 means finish line only, two means finish line
                            //      and one point before finish in task sequence (Task line).
                            // TODO :
                        } else if (_tcsstr(pToken, _T("Bonus=")) == pToken) {
                            // Bonus for crossing the finish line
                            // TODO :
                        }
                    }
                } else if (_tcsstr(pToken, _T("ObsZone=")) == pToken) {
                    TCHAR *sz = NULL;
                    CupObsZoneUpdater TmpZone;
                    TmpZone.mIdx = _tcstol(pToken + 8, &sz, 10);
                    if (TmpZone.mIdx < MAXTASKPOINTS) {
                        while ((pToken = strsep_r(NULL, TEXT(","), &pWClast)) != NULL) {
                            if (_tcsstr(pToken, _T("Style=")) == pToken) {
                                // Direction. 0 - Fixed value, 1 - Symmetrical, 2 - To next point, 3 - To previous point, 4 - To start point
                                TmpZone.mType = _tcstol(pToken + 6, &sz, 10);
                            } else if (_tcsstr(pToken, _T("R1=")) == pToken) {
                                // Radius 1
                                TmpZone.mR1 = ReadLength(pToken + 3);
                            } else if (_tcsstr(pToken, _T("A1=")) == pToken) {
                                // Angle 1 in degrees
                                TmpZone.mA1 = _tcstod(pToken + 3, &sz);
                            } else if (_tcsstr(pToken, _T("R2=")) == pToken) {
                                // Radius 2
                                TmpZone.mR2 = ReadLength(pToken + 3);
                            } else if (_tcsstr(pToken, _T("A2=")) == pToken) {
                                // Angle 2 in degrees
                                TmpZone.mA2 = _tcstod(pToken + 3, &sz);
                            } else if (_tcsstr(pToken, _T("A12=")) == pToken) {
                                // Angle 12
                                TmpZone.mA12 = _tcstod(pToken + 4, &sz);
                            } else if (_tcsstr(pToken, _T("Line=")) == pToken) {
                                // true For Line Turmpoint type
                                // Exist only for start an Goalin LK
                                TmpZone.mLine = (_tcstol(pToken + 5, &sz, 10) == 1);
                            }
                        }
                        TmpZone.UpdateTask();
                    }
                }
            }
            break;
          case none:
          default:
            break;
          }
          memset(szString, 0, sizeof (szString)); // clear Temp Buffer
      }
  }
  if(!ISGAAIRCRAFT) {
      // Landing don't exist in LK Task Systems, so Remove It;
      if ( bLoadComplet && !bLastInvalid ) {
          RemoveTaskPoint(getFinalWaypoint());
      }
  }
  UnlockTaskData();
  for (mapCode2Waypoint_t::iterator It = mapWaypoint.begin(); It != mapWaypoint.end(); ++It) {
      if (It->second.Comment) {
          free(It->second.Comment);
      }
      if (It->second.Details) {
          free(It->second.Details);
      }
  }
  mapWaypoint.clear();

  return ValidTaskPoint(0);
}
Exemplo n.º 7
0
static char *get_event_condition(char *src, edg_wll_QueryRec *cond)
{
	char	   *s;


	s = get_attr_name(src, tmps, 500);

	if ( tmps[0] == '\0' ) return NULL;

	if ( !strcmp(tmps, "time") ) cond->attr = EDG_WLL_QUERY_ATTR_TIME;
	else if ( !strcmp(tmps, "state_enter_time") ) cond->attr = EDG_WLL_QUERY_ATTR_STATEENTERTIME;
	else if ( !strcmp(tmps, "last_update_time") ) cond->attr = EDG_WLL_QUERY_ATTR_LASTUPDATETIME;
	else if ( !strcmp(tmps, "jdl_attr") ) cond->attr = EDG_WLL_QUERY_ATTR_JDL_ATTR;
	else if ( !strcmp(tmps, "level") ) cond->attr = EDG_WLL_QUERY_ATTR_LEVEL;
	else if ( !strcmp(tmps, "host") ) cond->attr = EDG_WLL_QUERY_ATTR_HOST;
	else if ( !strcmp(tmps, "source") ) cond->attr = EDG_WLL_QUERY_ATTR_SOURCE;
	else if ( !strcmp(tmps, "instance") ) cond->attr = EDG_WLL_QUERY_ATTR_INSTANCE;
	else if ( !strcmp(tmps, "event_type") ) cond->attr = EDG_WLL_QUERY_ATTR_EVENT_TYPE;
	else
	{
		cond->attr = EDG_WLL_QUERY_ATTR_USERTAG;
		cond->attr_id.tag = strdup(tmps);
	}

	if ( !(s = get_op(s, &(cond->op))) ) return NULL;

	if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL;

	switch ( cond->attr )
	{
	case EDG_WLL_QUERY_ATTR_USERTAG:
	case EDG_WLL_QUERY_ATTR_HOST:
	case EDG_WLL_QUERY_ATTR_INSTANCE:
	case EDG_WLL_QUERY_ATTR_JDL_ATTR:
		if ( !(cond->value.c = strdup(tmps)) )
			return 0;
		break;

	case EDG_WLL_QUERY_ATTR_SOURCE:
		if ( !strcasecmp(tmps, "UserInterface") ) cond->value.i = EDG_WLL_SOURCE_USER_INTERFACE;
		else if ( !strcasecmp(tmps, "NetworkServer") ) cond->value.i = EDG_WLL_SOURCE_NETWORK_SERVER;
		else if ( !strcasecmp(tmps, "WorkloadManager") ) cond->value.i = EDG_WLL_SOURCE_WORKLOAD_MANAGER;
		else if ( !strcasecmp(tmps, "BigHelper") ) cond->value.i = EDG_WLL_SOURCE_BIG_HELPER;
		else if ( !strcasecmp(tmps, "JobController") ) cond->value.i = EDG_WLL_SOURCE_JOB_SUBMISSION;
		else if ( !strcasecmp(tmps, "LogMonitor") ) cond->value.i = EDG_WLL_SOURCE_LOG_MONITOR;
		else if ( !strcasecmp(tmps, "LRMS") ) cond->value.i = EDG_WLL_SOURCE_LRMS;
		else if ( !strcasecmp(tmps, "Application") ) cond->value.i = EDG_WLL_SOURCE_APPLICATION;
		else
		{
			fprintf(stderr,"%s: invalid source value (%s)\n", myname, tmps);
			return NULL;
		}
		break;

	case EDG_WLL_QUERY_ATTR_EVENT_TYPE:
	case EDG_WLL_QUERY_ATTR_LEVEL:
		cond->value.i = atoi(tmps);
		if ( cond->op == EDG_WLL_QUERY_OP_WITHIN )
		{
			if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL;
			if ( tmps[0] == '\0' )
			{
				fprintf(stderr,"%s: second interval boundary not set\n", myname);
				return NULL;
			}
			cond->value2.i = atoi(tmps);
		}
		break;

	case EDG_WLL_QUERY_ATTR_TIME:
		cond->value.t.tv_sec = StrToTime(tmps);
		if ( cond->op == EDG_WLL_QUERY_OP_WITHIN )
		{
			if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL;
			if ( tmps[0] == '\0' )
			{
				fprintf(stderr,"%s: second interval boundary not set\n", myname);
				return NULL;
			}
			cond->value2.t.tv_sec = StrToTime(tmps);
		}
		break;

	default:
		break;
	}

	while ( isblank(*s) || (*s == ';') ) s++;			/* skip whitespaces */

	return s;
}
Exemplo n.º 8
0
static char *get_job_condition(char *src, edg_wll_QueryRec *cond)
{
	char	   *s;


	s = get_attr_name(src, tmps, 500);

	if ( tmps[0] == '\0' ) return NULL;

	if ( !strcmp(tmps, "jobid") ) cond->attr = EDG_WLL_QUERY_ATTR_JOBID;
	else if ( !strcmp(tmps, "owner") ) cond->attr = EDG_WLL_QUERY_ATTR_OWNER;
	else if ( !strcmp(tmps, "status") ) cond->attr = EDG_WLL_QUERY_ATTR_STATUS;
	else if ( !strcmp(tmps, "location") ) cond->attr = EDG_WLL_QUERY_ATTR_LOCATION;
	else if ( !strcmp(tmps, "destination") ) cond->attr = EDG_WLL_QUERY_ATTR_DESTINATION;
	else if ( !strcmp(tmps, "done_code") ) cond->attr = EDG_WLL_QUERY_ATTR_DONECODE;
	else if ( !strcmp(tmps, "exit_code") ) cond->attr = EDG_WLL_QUERY_ATTR_EXITCODE;
	else if ( !strcmp(tmps, "parent_job") ) cond->attr = EDG_WLL_QUERY_ATTR_PARENT;
	else if ( !strcmp(tmps, "time") ) cond->attr = EDG_WLL_QUERY_ATTR_TIME;
	else if ( !strcmp(tmps, "state_enter_time") ) cond->attr = EDG_WLL_QUERY_ATTR_STATEENTERTIME;
	else if ( !strcmp(tmps, "last_update_time") ) cond->attr = EDG_WLL_QUERY_ATTR_LASTUPDATETIME;
	else if ( !strcmp(tmps, "jdl_attr") ) cond->attr = EDG_WLL_QUERY_ATTR_JDL_ATTR;
	else if ( !strcmp(tmps, "job_type") ) cond->attr = EDG_WLL_QUERY_ATTR_JOB_TYPE;
	else if ( !strcmp(tmps, "vm_status") ) cond->attr = EDG_WLL_QUERY_ATTR_VM_STATUS; 


       /**< When entered current status */
        /**< Time of the last known event of the job */
         /**< Network server aka RB aka WMproxy endpoint */

	else
	{
		cond->attr = EDG_WLL_QUERY_ATTR_USERTAG;
		cond->attr_id.tag = strdup(tmps);
	}

	if ( !(s = get_op(s, &(cond->op))) ) return NULL;

	if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL;

	switch ( cond->attr )
	{
	case EDG_WLL_QUERY_ATTR_JOBID:
	case EDG_WLL_QUERY_ATTR_PARENT:
		if ( glite_jobid_parse(tmps, (glite_jobid_t *)&cond->value.j) )
		{
			fprintf(stderr,"%s: %s: cannot parse jobId\n", myname, tmps);
			return NULL;
		}
		break;

	case EDG_WLL_QUERY_ATTR_OWNER:
		if ( !strcmp("NULL", tmps) )
			cond->value.c = NULL;
		else if ( !(cond->value.c = strdup(tmps)) )
			return 0;
		break;

	case EDG_WLL_QUERY_ATTR_LOCATION:
	case EDG_WLL_QUERY_ATTR_DESTINATION:
	case EDG_WLL_QUERY_ATTR_USERTAG:
		if ( !(cond->value.c = strdup(tmps)) )
			return 0;
		break;

	case EDG_WLL_QUERY_ATTR_JDL_ATTR:
		if ( !(cond->value.c = strdup(tmps)) )
			return 0;
		if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL;
		if ( tmps[0] == '\0' )
		{
			fprintf(stderr,"%s: you need to specify attribute name\n", myname);
			return NULL;
		}
		if ( !(cond->attr_id.tag = strdup(tmps)) )
			return 0;
		break;

	case EDG_WLL_QUERY_ATTR_STATUS:
		if ( 0 > (cond->value.i = edg_wll_StringToStat(tmps))) {
			fprintf(stderr,"%s: invalid status value (%s)\n", myname, tmps);
			return 0;
		}
		break;

	case EDG_WLL_QUERY_ATTR_DONECODE:
	case EDG_WLL_QUERY_ATTR_EXITCODE:
	case EDG_WLL_QUERY_ATTR_RESUBMITTED:
		cond->value.i = atoi(tmps);
		if ( cond->op == EDG_WLL_QUERY_OP_WITHIN )
		{
			if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL;
			if ( tmps[0] == '\0' )
			{
				fprintf(stderr,"%s: second interval boundary not set\n", myname);
				return NULL;
			}
			cond->value2.i = atoi(tmps);
		}
		break;
	case EDG_WLL_QUERY_ATTR_TIME:
		cond->value.t.tv_sec = StrToTime(tmps);
		if ( cond->op == EDG_WLL_QUERY_OP_WITHIN )
		{
			if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL;
			if ( tmps[0] == '\0' )
			{
				fprintf(stderr,"%s: second interval boundary not set\n", myname);
				return NULL;
			}
			cond->value2.t.tv_sec = StrToTime(tmps);
		}
		if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL;
		if ( tmps[0] == '\0' )
		{
			fprintf(stderr,"%s: time condition must be associated with state condition\n", myname);
			return NULL;
		}
		if ( 0 > (cond->value.i = edg_wll_StringToStat(tmps))) {
			fprintf(stderr,"%s: invalid status value (%s)\n", myname, tmps);
			return 0;
		}
        	break;

	case EDG_WLL_QUERY_ATTR_LASTUPDATETIME:
	case EDG_WLL_QUERY_ATTR_STATEENTERTIME:
		cond->value.t.tv_sec = StrToTime(tmps);
		if ( cond->op == EDG_WLL_QUERY_OP_WITHIN )
		{
			if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL;
			if ( tmps[0] == '\0' )
			{
				fprintf(stderr,"%s: second interval boundary not set\n", myname);
				return NULL;
			}
			cond->value2.t.tv_sec = StrToTime(tmps);
		}
		break;

	case EDG_WLL_QUERY_ATTR_JOB_TYPE:
		if ( 0 > (cond->value.i = edg_wll_JobtypeStrToCode(tmps))) {
			fprintf(stderr,"%s: invalid job type (%s)\n", myname, tmps);
			return 0;
		}
		break;
	
	case EDG_WLL_QUERY_ATTR_VM_STATUS:
		if ( 0 > (cond->value.i = edg_wll_StringToVMStat(tmps))) {
			fprintf(stderr,"%s: invalid VM status value (%s)\n", myname, tmps);
			return 0;
		}
		break;

	default:
		break;
	}

	while ( isblank(*s) || (*s == ';') ) s++;			/* skip whitespaces */

	return s;
}
Exemplo n.º 9
0
const char *StrToTime(Time& d, const char *s)
{
	return StrToTime(*s_date_scan_thread ? s_date_scan_thread : s_date_scan_main, d, s);
}
Exemplo n.º 10
0
int
main(int argc, char **argv)
{
	struct CatalogEntry ced;
	struct CatalogEntry *ce = &ced;
	struct VolId vid;
	char	buf[256];
	char	*string;
	uint64_t value;
	uint32_t mask;
	int		field;
	int		status;

	if (CatalogInit(program_name) == -1) {
		error(EXIT_FAILURE, errno, GetCustMsg(18211));
				/* Catalog initialization failed */
	}

	argv++;
	argc--;
	if (argc < 2 || argc > 3) {
		if (argc == 1 && strcmp(*argv, "-flags") == 0) {
			usage_help();
		} else {
			usage();
		}
	}

	if (strcmp(*argv, "-capacity") == 0) {
		argc--;
		argv++;
		field = CEF_Capacity;
		if (StrToFsize(*argv, &value) == -1) {
			error(EXIT_USAGE, 0, GetCustMsg(13612), *argv);
		}
		value /= 1024;
	} else if (strcmp(*argv, "-count") == 0) {
		char	*final_char;

		argc--;
		argv++;
		field = CEF_Access;
		value = strtoll(*argv, &final_char, 0);
		if (final_char != NULL && *final_char != '\0') {
			error(0, 0, GetCustMsg(13614), *argv);
			usage();
		}
	} else if (strcmp(*argv, "-mtype") == 0) {
		argc--;
		argv++;
		field = CEF_MediaType;
		string = *argv;
	} else if (strcmp(*argv, "-space") == 0) {
		argc--;
		argv++;
		field = CEF_Space;
		if (StrToFsize(*argv, &value) == -1) {
			error(EXIT_USAGE, 0, GetCustMsg(13613), *argv);
		}
		value /= 1024;
	} else if (strcmp(*argv, "-time") == 0) {
		argc--;
		argv++;
		field = CEF_MountTime;
		value = StrToTime(*argv);
		if ((int64_t)value <= 0) {
		/* N.B. bad indentation here to meet cstyle requirements */
		fprintf(stderr,
		    "%s: Cannot convert date \"%s\".  Valid formats are:\n"
		    "            yyyy-mm-dd [hh:mm[:ss]]\n"
		    "            Month-name Day [4-digit-year] [hh:mm]\n"
		    "      -or-  Day Month-name [4-digit-year] [hh:mm]\n",
		    program_name, *argv);
		exit(EXIT_FAILURE);
		}
	} else if (strcmp(*argv, "-vsn") == 0) {
		argc--;
		argv++;
		field = CEF_Vsn;
		string = *argv;
	} else if (strcmp(*argv, "-I") == 0) {
		argc--;
		argv++;
		field = CEF_VolInfo;
		string = *argv;
	} else if (**argv == '-' || **argv == '+') {
		char	*flags;
		/* User specified "+-flags specifier" */

		field = CEF_Status;
		flags = *argv + 1;
		mask = 0;
		while (*flags != '\0') {
			switch (*flags++) {

			case 'A':	mask |= CES_needs_audit;	break;
			case 'l':	mask |= CES_labeled;		break;
			case 'E':	mask |= CES_bad_media;		break;
			case 'o':	mask |= CES_occupied;		break;
			case 'C':	mask |= CES_cleaning;		break;
			case 'b':	mask |= CES_bar_code;		break;
			case 'W':	mask |= CES_writeprotect;	break;
			case 'R':	mask |= CES_read_only;		break;
			case 'c':	mask |= CES_recycle;		break;
			case 'U':	mask |= CES_unavail;		break;
			case 'N':	mask |= CES_non_sam;		break;
			case 'p':	mask |= CES_priority;		break;
			case 'X':	mask |= CES_export_slot;	break;
			case 'd':	mask |= CES_dupvsn;		break;
			case 'f':	mask |= CES_archfull;		break;
			default:
				error(0, 0, GetCustMsg(13615), *argv);
				usage();
				break;
			}
		}
		if (**argv == '-')  value = 0;
		else  value = mask;
	} else {
		error(0, 0, GetCustMsg(13611), *argv);
		usage();
	}

	argc--;
	argv++;

	/*
	 * There must be only one argument left - the volume identifier.
	 */
	if (*argv == NULL) {		/* not enough */
		usage();
	} else if (argc != 1) {		/* too many   */
		error(0, 0, GetCustMsg(13600), *argv);
		usage();
	}

	/*
	 * Convert argument to volume identifier.
	 */
	if (StrToVolId(*argv, &vid) != 0) {
		error(EXIT_FAILURE, errno, GetCustMsg(13600), *argv);
	}

	/*
	 * Use CatalogGetEntry() to validate the specifier.
	 */
	if ((ce = CatalogGetEntry(&vid, &ced)) == NULL) {
		error(EXIT_FAILURE, errno, GetCustMsg(13600), *argv);
	}

	/*
	 * Make the required change.
	 */
	if ((field != CEF_Vsn) && (field != CEF_MediaType) &&
	    (field != CEF_VolInfo)) {

		if ((field != CEF_Capacity) && (field != CEF_Space))
			status = CatalogSetField(&vid, field,
			    (uint32_t)value, mask);
		else {
			status = CatalogSetField(&vid, field, value, mask);
			if (field == CEF_Capacity) {
				field = CEF_Status;
				value = mask = CES_capacity_set;
				(void) CatalogSetField(&vid, field,
				    (uint32_t)value, mask);
			}
		}
	} else {
		status = CatalogSetString(&vid, field, string);
	}
	if (status != 0) {
		error(EXIT_FAILURE, errno, GetCustMsg(13616), *argv);
	}

	/*
	 * Display results.
	 */
	if (vid.ViFlags == VI_cart) {
		/*
		 * Volume was specified as eq:slot[:partition]
		 * If tape, list partition 0
		 * If m.o., list partitions 1 and 2
		 */
		vid.ViFlags |= VI_part;
		for (vid.ViPart = 0; /* Terminated inside. */; vid.ViPart++) {
			if ((ce = CatalogGetEntry(&vid, &ced)) == NULL)
				break;
			printf("%s\n",
			    CatalogStrFromEntry(ce, buf, sizeof (buf)));
			vid.ViPart = ce->CePart;
		}
	} else if ((ce = CatalogGetEntry(&vid, &ced)) != NULL)  {
		printf("%s\n", CatalogStrFromEntry(ce, buf, sizeof (buf)));
	}
	return (EXIT_SUCCESS);
}