void CThreadPoolManager::StopAll()
{
    m_bStop = true;
    LockTask();
    pthread_cond_signal(&m_cond_task);
    UnlockTask();
    pthread_join(m_taskThreadId, NULL);
    //等待当前所有任务执行完毕
    m_taskPool->StopPool();
    m_threadPool->StopPool(true); // 停止线程池工作
}
Exemple #2
0
bool CTaskFileHelper::Load(const TCHAR* szFileName) {
    CScopeLock LockTask(LockTaskData, UnlockTaskData);
    StartupStore(_T(". LoadTask : <%s>%s"), szFileName, NEWLINE);

    ClearTask();

    FILE* stream = _tfopen(szFileName, TEXT("rb"));
    if (stream) {
        fseek(stream, 0, SEEK_END); // seek to end of file
        long size = ftell(stream); // get current file pointer
        fseek(stream, 0, SEEK_SET); // seek back to beginning of file

        char * buff = (char*) calloc(size + 1, sizeof (char));
        long nRead = fread(buff, sizeof (char), size, stream);
        if (nRead != size) {
            fclose(stream);
            free(buff);
            return false;
        }
        fclose(stream);
        TCHAR * szXML = (TCHAR*) calloc(size + 1, sizeof (TCHAR));
        utf2unicode(buff, szXML, size + 1);
        free(buff);
        XMLNode rootNode = XMLNode::parseString(szXML, _T("lk-task"));

        if (rootNode) {
            LoadWayPointList(rootNode.getChildNode(_T("waypoints"), 0));
            if (!LoadTaskPointList(rootNode.getChildNode(_T("taskpoints"), 0))) {
                free(szXML);
                return false;
            }
            if (!LoadStartPoint(rootNode.getChildNode(_T("startpoints"), 0))) {
                free(szXML);
                return false;
            }
            LoadOptions(rootNode);
        }

        free(szXML);
    }

    RefreshTask();

    TaskModified = false;
    TargetModified = false;
    _tcscpy(LastTaskFileName, szFileName);

    return true;
}
Exemple #3
0
void MapWindow::DrawTaskSectors(HDC hdc, RECT rc) {
int Active = ActiveWayPoint;
if(ValidTaskPoint(PanTaskEdit))
Active = PanTaskEdit;

CScopeLock LockTask(LockTaskData, UnlockTaskData);

    /*******************************************************************************************************/
int TaskPoints =0;
while(ValidTaskPoint(TaskPoints))
TaskPoints++;
if(TaskPoints < 2)
return;
if(TaskPoints > 5)
return;
int a=0, b=1;

if(TaskPoints ==3)
{
  switch (Active)
  {
    case 0: a = 0; b = 1; break;
    case 1: a = 0; b = 1; break;
    case 2: a = 1; b = 2; break;
  }
}

if(TaskPoints ==4)
{
  switch (Active)
  {
    case 0: a = 1; b = 2; break;
    case 1: a = 2; b = 0; break;
    case 2: a = 0; b = 1; break;
    case 3: a = 1; b = 2; break;
  }
}

if(TaskPoints ==5)
{
  switch (Active)
  {
    case 0: a = 3; b = 1; break;
    case 1: a = 2; b = 3; break;
    case 2: a = 3; b = 1; break;
    case 3: a = 1; b = 2; break;
    case 4: a = 3; b = 1; break;
  }
}



double	lat1 = WayPointList[Task[a].Index].Latitude;
double	lon1 = WayPointList[Task[a].Index].Longitude;
double	lat2 = WayPointList[Task[b].Index].Latitude;
double	lon2 = WayPointList[Task[b].Index].Longitude;

RenderFAISector ( hdc, rc, lat1, lon1, lat2, lon2, 1, RGB_YELLOW );
RenderFAISector ( hdc, rc, lat1, lon1, lat2, lon2, 0, RGB_CYAN );



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


}
Exemple #4
0
bool CTaskFileHelper::Save(const TCHAR* szFileName) {
    if (!WayPointList) return false; // this should never happen, but just to be safe...

    CScopeLock LockTask(LockTaskData, UnlockTaskData);
    StartupStore(_T(". SaveTask : saving <%s>%s"), szFileName, NEWLINE);

    ///////////////////////////////////////////////////////////////
    // TODO : this code is temporary before rewriting task system
    if (AATEnabled || DoOptimizeRoute()) {
        for (unsigned i = 0; ValidTaskPoint(i); ++i) {
            int type = -1;
            if (i == 0) { // Start
                Task[0].AATCircleRadius = StartRadius;
                Task[0].AATSectorRadius = StartRadius;
                Task[0].OutCircle = !PGStartOut;
                type = StartLine;
            } else if (!ValidTaskPoint(i + 1)) { //Finish
                Task[i].AATCircleRadius = FinishRadius;
                Task[i].AATSectorRadius = FinishRadius;
                type = FinishLine;
            }
            if (type != -1) {
                switch (type) {
                    case 0: //circle
                        Task[i].AATType = CIRCLE;
                        break;
                    case 1: //line
                        Task[i].AATType = LINE;
                        break;
                    case 2: //sector
                        Task[i].AATType = SECTOR;
                        break;
                }
            }
        }
    }
    ///////////////////////////////////////////////////////////////


    XMLNode topNode = XMLNode::createXMLTopNode();
    XMLNode rootNode = topNode.AddChild(ToString(_T("lk-task")), false);

    if (!SaveOption(rootNode)) {
        return false;
    }

    if (!SaveTaskPointList(rootNode.AddChild(ToString(_T("taskpoints")), false))) {
        return false;
    }
    if (EnableMultipleStartPoints && ValidStartPoint(0)) {
        if (!SaveStartPointList(rootNode.AddChild(ToString(_T("startpoints")), false))) {
            return false;
        }
    }
    if (!SaveWayPointList(rootNode.AddChild(ToString(_T("waypoints")), false))) {
        return false;
    }

    int ContentSize = 0;
    LPCTSTR szContent = topNode.createXMLString(1, &ContentSize);
    Utf8File file;
    if (!file.Open(szFileName, Utf8File::io_create)) {
        return false;
    }

    file.WriteLn(szContent);
    file.Close();

    return true;
}