36#include "ocpn_frame.h"
39extern int g_nCPUCount;
45SENCJobTicket::SENCJobTicket() {
46 m_SENCResult = SENC_BUILD_INACTIVE;
47 m_status = THREAD_INACTIVE;
50const wxEventType wxEVT_OCPN_BUILDSENCTHREAD = wxNewEventType();
55OCPN_BUILDSENC_ThreadEvent::OCPN_BUILDSENC_ThreadEvent(wxEventType commandType,
57 : wxEvent(id, commandType) {
61OCPN_BUILDSENC_ThreadEvent::~OCPN_BUILDSENC_ThreadEvent() {}
63wxEvent *OCPN_BUILDSENC_ThreadEvent::Clone()
const {
65 newevent->stat = this->stat;
66 newevent->type = this->type;
67 newevent->m_ticket = this->m_ticket;
75SENCThreadManager::SENCThreadManager() {
78 int nCPU = wxMax(1, wxThread::GetCPUCount());
79 if (g_nCPUCount > 0) nCPU = g_nCPUCount;
82 if (nCPU < 1) nCPU = 1;
84 m_max_jobs = wxMax(nCPU - 1, 1);
88 printf(
" SENC: nCPU: %d m_max_jobs :%d\n", nCPU, m_max_jobs);
93 wxEVT_OCPN_BUILDSENCTHREAD,
94 (wxObjectEventFunction)(wxEventFunction)&SENCThreadManager::OnEvtThread);
100SENCThreadManager::~SENCThreadManager() {
104SENCThreadStatus SENCThreadManager::ScheduleJob(
SENCJobTicket *ticket) {
106 for (
size_t i = 0; i < ticket_list.size(); i++) {
107 if (ticket_list[i]->m_FullPath000 == ticket->m_FullPath000)
108 return THREAD_PENDING;
111 ticket->m_status = THREAD_PENDING;
112 ticket_list.push_back(ticket);
118 return THREAD_PENDING;
121void SENCThreadManager::StartTopJob() {
125 for (
size_t i = 0; i < ticket_list.size(); i++) {
126 if (ticket_list[i]->m_status == THREAD_STARTED) nRunning++;
130 if (nRunning < m_max_jobs) {
132 startCandidate = NULL;
133 for (
size_t i = 0; i < ticket_list.size(); i++) {
134 if (ticket_list[i]->m_status == THREAD_PENDING) {
135 startCandidate = ticket_list[i];
141 if (startCandidate) {
146 startCandidate->m_thread = thread;
147 startCandidate->m_status = THREAD_STARTED;
148 thread->SetPriority(20);
156 count.Printf(_T(
" %ld"), ticket_list.size());
157 if (gFrame->GetPrimaryCanvas())
158 gFrame->GetPrimaryCanvas()->SetAlertString(_(
"Preparing vector chart ") +
168 for (
size_t i = 0; i < ticket_list.size(); i++) {
169 if (ticket_list[i] == ticket) {
173 ticket_list.erase(ticket_list.begin() + i);
182 for (
size_t i = 0; i < ticket_list.size(); i++) {
183 if (ticket_list[i]->m_status == THREAD_STARTED) nRunning++;
188 count.Printf(_T(
" %ld"), ticket_list.size());
189 if (gFrame->GetPrimaryCanvas())
190 gFrame->GetPrimaryCanvas()->SetAlertString(_(
"Preparing vector chart ") +
193 if (gFrame->GetPrimaryCanvas())
194 gFrame->GetPrimaryCanvas()->SetAlertString(_T(
""));
199int SENCThreadManager::GetJobCount() {
return ticket_list.size(); }
201bool SENCThreadManager::IsChartInTicketlist(
s57chart *chart) {
202 for (
size_t i = 0; i < ticket_list.size(); i++) {
203 if (ticket_list[i]->m_chart == chart)
return true;
208bool SENCThreadManager::SetChartPointer(
s57chart *chart,
void *new_ptr) {
210 for (
size_t i = 0; i < ticket_list.size(); i++) {
211 if (ticket_list[i]->m_chart == chart) {
212 ticket_list[i]->m_chart = (
s57chart *)new_ptr;
219#define NBAR_LENGTH 40
224 switch (event.type) {
225 case SENC_BUILD_STARTED:
227 Sevent.type = SENC_BUILD_STARTED;
228 Sevent.m_ticket =
event.m_ticket;
231 case SENC_BUILD_DONE_NOERROR:
233 Sevent.type = SENC_BUILD_DONE_NOERROR;
234 Sevent.m_ticket =
event.m_ticket;
235 FinishJob(event.m_ticket);
239 case SENC_BUILD_DONE_ERROR:
241 Sevent.type = SENC_BUILD_DONE_ERROR;
242 Sevent.m_ticket =
event.m_ticket;
243 FinishJob(event.m_ticket);
250 if (gFrame) gFrame->GetEventHandler()->AddPendingEvent(Sevent);
259 m_FullPath000 = ticket->m_FullPath000;
260 m_SENCFileName = ticket->m_SENCFileName;
267void *SENCBuildThread::Entry() {
282 senc.setRegistrar(g_poRegistrar);
283 senc.setRefLocn(m_ticket->ref_lat, m_ticket->ref_lon);
284 senc.SetLODMeters(m_ticket->m_LOD_meters);
285 senc.setNoErrDialog(
true);
287 m_ticket->m_SENCResult = SENC_BUILD_STARTED;
290 Sevent.type = SENC_BUILD_STARTED;
291 Sevent.m_ticket = m_ticket;
292 if (m_manager) m_manager->QueueEvent(Sevent.Clone());
294 int ret = senc.createSenc200(m_FullPath000, m_SENCFileName,
false);
298 Nevent.m_ticket = m_ticket;
299 if (ret == ERROR_INGESTING000)
300 Nevent.type = SENC_BUILD_DONE_ERROR;
302 Nevent.type = SENC_BUILD_DONE_NOERROR;
304 m_ticket->m_SENCResult = Sevent.type;
305 if (m_manager) m_manager->QueueEvent(Nevent.Clone());
316 catch (
const std::exception &e ) {
317 const char *msg = e.what();