27 #include "wx/wxprec.h"
36 #include "ocpn_frame.h"
39 extern int g_nCPUCount;
40 extern S57ClassRegistrar *g_poRegistrar;
45 SENCJobTicket::SENCJobTicket() {
46 m_SENCResult = SENC_BUILD_INACTIVE;
47 m_status = THREAD_INACTIVE;
50 const wxEventType wxEVT_OCPN_BUILDSENCTHREAD = wxNewEventType();
55 OCPN_BUILDSENC_ThreadEvent::OCPN_BUILDSENC_ThreadEvent(wxEventType commandType,
57 : wxEvent(id, commandType) {
61 OCPN_BUILDSENC_ThreadEvent::~OCPN_BUILDSENC_ThreadEvent() {}
63 wxEvent *OCPN_BUILDSENC_ThreadEvent::Clone()
const {
65 newevent->stat = this->stat;
66 newevent->type = this->type;
67 newevent->m_ticket = this->m_ticket;
75 SENCThreadManager::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);
87 wxLogDebug(
"SENC: nCPU: %d m_max_jobs :%d\n", nCPU, m_max_jobs);
92 wxEVT_OCPN_BUILDSENCTHREAD,
93 (wxObjectEventFunction)(wxEventFunction)&SENCThreadManager::OnEvtThread);
99 SENCThreadManager::~SENCThreadManager() {
103 SENCThreadStatus SENCThreadManager::ScheduleJob(
SENCJobTicket *ticket) {
105 for (
size_t i = 0; i < ticket_list.size(); i++) {
106 if (ticket_list[i]->m_FullPath000 == ticket->m_FullPath000)
107 return THREAD_PENDING;
110 ticket->m_status = THREAD_PENDING;
111 ticket_list.push_back(ticket);
117 return THREAD_PENDING;
120 void SENCThreadManager::StartTopJob() {
124 for (
size_t i = 0; i < ticket_list.size(); i++) {
125 if (ticket_list[i]->m_status == THREAD_STARTED) nRunning++;
129 if (nRunning < m_max_jobs) {
131 startCandidate = NULL;
132 for (
size_t i = 0; i < ticket_list.size(); i++) {
133 if (ticket_list[i]->m_status == THREAD_PENDING) {
134 startCandidate = ticket_list[i];
140 if (startCandidate) {
145 startCandidate->m_thread = thread;
146 startCandidate->m_status = THREAD_STARTED;
147 thread->SetPriority(20);
155 count.Printf(_T(
" %ld"), ticket_list.size());
156 if (gFrame->GetPrimaryCanvas())
157 gFrame->GetPrimaryCanvas()->SetAlertString(_(
"Preparing vector chart ") +
167 for (
size_t i = 0; i < ticket_list.size(); i++) {
168 if (ticket_list[i] == ticket) {
172 ticket_list.erase(ticket_list.begin() + i);
181 for (
size_t i = 0; i < ticket_list.size(); i++) {
182 if (ticket_list[i]->m_status == THREAD_STARTED) nRunning++;
187 count.Printf(_T(
" %ld"), ticket_list.size());
188 if (gFrame->GetPrimaryCanvas())
189 gFrame->GetPrimaryCanvas()->SetAlertString(_(
"Preparing vector chart ") +
192 if (gFrame->GetPrimaryCanvas())
193 gFrame->GetPrimaryCanvas()->SetAlertString(_T(
""));
198 int SENCThreadManager::GetJobCount() {
return ticket_list.size(); }
200 bool SENCThreadManager::IsChartInTicketlist(
s57chart *chart) {
201 for (
size_t i = 0; i < ticket_list.size(); i++) {
202 if (ticket_list[i]->m_chart == chart)
return true;
207 bool SENCThreadManager::SetChartPointer(
s57chart *chart,
void *new_ptr) {
209 for (
size_t i = 0; i < ticket_list.size(); i++) {
210 if (ticket_list[i]->m_chart == chart) {
211 ticket_list[i]->m_chart = (
s57chart *)new_ptr;
218 #define NBAR_LENGTH 40
223 switch (event.type) {
224 case SENC_BUILD_STARTED:
226 Sevent.type = SENC_BUILD_STARTED;
227 Sevent.m_ticket =
event.m_ticket;
230 case SENC_BUILD_DONE_NOERROR:
232 Sevent.type = SENC_BUILD_DONE_NOERROR;
233 Sevent.m_ticket =
event.m_ticket;
234 FinishJob(event.m_ticket);
238 case SENC_BUILD_DONE_ERROR:
240 Sevent.type = SENC_BUILD_DONE_ERROR;
241 Sevent.m_ticket =
event.m_ticket;
242 FinishJob(event.m_ticket);
249 if (gFrame) gFrame->GetEventHandler()->AddPendingEvent(Sevent);
258 m_FullPath000 = ticket->m_FullPath000;
259 m_SENCFileName = ticket->m_SENCFileName;
266 void *SENCBuildThread::Entry() {
281 senc.setRegistrar(g_poRegistrar);
282 senc.setRefLocn(m_ticket->ref_lat, m_ticket->ref_lon);
283 senc.SetLODMeters(m_ticket->m_LOD_meters);
284 senc.setNoErrDialog(
true);
286 m_ticket->m_SENCResult = SENC_BUILD_STARTED;
289 Sevent.type = SENC_BUILD_STARTED;
290 Sevent.m_ticket = m_ticket;
291 if (m_manager) m_manager->QueueEvent(Sevent.Clone());
293 int ret = senc.createSenc200(m_FullPath000, m_SENCFileName,
false);
297 Nevent.m_ticket = m_ticket;
298 if (ret == ERROR_INGESTING000)
299 Nevent.type = SENC_BUILD_DONE_ERROR;
301 Nevent.type = SENC_BUILD_DONE_NOERROR;
303 m_ticket->m_SENCResult = Sevent.type;
304 if (m_manager) m_manager->QueueEvent(Nevent.Clone());
315 catch (
const std::exception &e ) {
316 const char *msg = e.what();