1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
#include "./eraseMedium.h"
#include "api.h"
#include <api/service/waservicefactory.h>
EraseMedium::EraseMedium(void)
{
primoSDK=0;
waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(obj_primo::getServiceGuid());
if (sf) primoSDK = reinterpret_cast<obj_primo *>(sf->getInterface());
hThread = NULL;
evntStop = NULL;
evntThreadExit = NULL;
errorCode = PRIMOSDK_OK;
notifyCB = NULL;
}
EraseMedium::~EraseMedium(void)
{
Stop();
waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(obj_primo::getServiceGuid());
if (sf) sf->releaseInterface(primoSDK);
}
DWORD EraseMedium::SetEject(DWORD eject)
{
DWORD tmp = this->eject;
this->eject = eject;
return tmp;
}
DWORD EraseMedium::Start(DWORD drive, DWORD eraseMode, ERASEMEDIUMCALLBACK notifyCB, void *userParam, int block)
{
this->notifyCB = notifyCB;
this->userparam = userParam;
OnNotify(ERASEMEDIUM_READY, PRIMOSDK_OK);
if (hThread)
{
OnNotify(ERASEMEDIUM_ALREADYSTARTED, PRIMOSDK_OK);
return PRIMOSDK_OK;
}
OnNotify(ERASEMEDIUM_INITIALIZING, PRIMOSDK_OK);
if (!primoSDK)
{
OnNotify(ERASEMEDIUM_UNABLEINITPRIMO, PRIMOSDK_NOTLOADED);
return errorCode;
}
// check unit
errorCode = primoSDK->UnitReady(&drive);
if (PRIMOSDK_OK != errorCode)
{
OnNotify(ERASEMEDIUM_DEVICENOTREADY, errorCode);
return errorCode;
}
// check that disc is erasable
DWORD erasable;
errorCode = primoSDK->DiscInfoEx(&drive, 0, NULL, NULL, &erasable, NULL, NULL, NULL);
if (PRIMOSDK_OK != errorCode)
{
OnNotify(ERASEMEDIUM_DISCINFOERROR, errorCode);
return errorCode;
}
if (!erasable)
{
OnNotify(ERASEMEDIUM_DISCNOTERASABLE, PRIMOSDK_OK);
return errorCode;
}
// begin burn
errorCode = BeginBurn(primoSDK, drive, &bs);
if (PRIMOSDK_OK != errorCode)
{
OnNotify(ERASEMEDIUM_BEGINBURNFAILED, errorCode);
return errorCode;
}
// erasing
errorCode = primoSDK->EraseMedium(&bs.drive, eraseMode);
if(PRIMOSDK_OK == errorCode)
{
OnNotify(ERASEMEDIUM_ERASING, PRIMOSDK_OK);
evntStop = CreateEvent(NULL, FALSE, FALSE, NULL);
if (block) errorCode = StatusThread(this);
else
{
DWORD threadID;
hThread = CreateThread(NULL, 0, StatusThread, (LPVOID)this, NULL, &threadID);
}
}
else
{
OnNotify(ERASEMEDIUM_ERASEMEDIUMFAILED, errorCode);
}
return errorCode;
}
void EraseMedium::Stop(void)
{
if (hThread && evntStop)
{
DWORD waitResult;
MSG msg;
if (!evntThreadExit) evntThreadExit = CreateEvent(NULL, FALSE, FALSE, NULL);
SetEvent(evntStop);
while(WAIT_TIMEOUT == (waitResult = WaitForSingleObject(evntThreadExit, 10)))
{
if (!evntStop) break;
while(PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
CloseHandle(evntThreadExit);
evntThreadExit = NULL;
}
}
DWORD EraseMedium::OnNotify(DWORD eraseCode, DWORD primoCode)
{
return (notifyCB) ? notifyCB(this, userparam, eraseCode, primoCode) : ERASEMEDIUM_CONTINUE;
}
DWORD WINAPI EraseMedium::StatusThread(void* parameter)
{
EraseMedium *object = (EraseMedium*)parameter;
DWORD current, total, waitResult;
object->errorCode = PRIMOSDK_RUNNING;
while(PRIMOSDK_RUNNING == object->errorCode && WAIT_TIMEOUT == (waitResult = WaitForSingleObject(object->evntStop, 1000)))
{
if (ERASEMEDIUM_STOP == object->OnNotify(ERASEMEDIUM_ERASING, PRIMOSDK_OK)) SetEvent(object->evntStop);
object->errorCode = object->primoSDK->RunningStatus(PRIMOSDK_GETSTATUS, ¤t, &total);
}
if (WAIT_OBJECT_0 == waitResult)
{ // aborting
object->OnNotify(ERASEMEDIUM_CANCELING, PRIMOSDK_OK);
DWORD test = object->primoSDK->RunningStatus(PRIMOSDK_ABORT, ¤t, &total);
do
{
Sleep(1000);
object->errorCode = object->primoSDK->RunningStatus(PRIMOSDK_GETSTATUS, ¤t, &total);
}while(PRIMOSDK_RUNNING == object->errorCode);
}
if (PRIMOSDK_OK != object->errorCode && PRIMOSDK_USERABORT != object->errorCode)
{
object->OnNotify(ERASEMEDIUM_ERASEMEDIUMFAILED, object->errorCode);
}
// check unit status
DWORD cmd, sense, asc, ascq;
object->errorCode = object->primoSDK->UnitStatus(&object->bs.drive, &cmd, &sense, &asc, &ascq);
if (object->errorCode != PRIMOSDK_OK)
{
object->OnNotify(ERASEMEDIUM_ERASEMEDIUMFAILED, object->errorCode);
}
// end burn
object->bs.eject = object->eject;
object->OnNotify(ERASEMEDIUM_FINISHING, PRIMOSDK_OK);
DWORD errorCode2 = EndBurn(&object->bs);
if (PRIMOSDK_OK != errorCode2)
{
object->OnNotify(ERASEMEDIUM_ENDBURNFAILED, object->errorCode);
}
if (PRIMOSDK_OK == object->errorCode) object->errorCode = errorCode2;
object->primoSDK->Release();
CloseHandle(object->hThread);
object->hThread = NULL;
CloseHandle(object->evntStop);
object->evntStop = NULL;
object->OnNotify( (PRIMOSDK_USERABORT == object->errorCode) ? ERASEMEDIUM_ABORTED : ERASEMEDIUM_COMPLETED, object->errorCode);
if (object->evntThreadExit) SetEvent(object->evntThreadExit);
return object->errorCode;
}
|