- Implement Trigger method to allow buffers

- Identation, 80/90, tabs & whitespaces



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32788 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes
2009-08-28 17:17:52 +00:00
parent cb5961b774
commit d1966ec2c2
+23 -7
View File
@@ -42,12 +42,24 @@ class PortListener {
} }
status_t TriggerCode(int32 code) status_t Trigger(int32 code)
{ {
return write_port(fPort, code, NULL, 0); return write_port(fPort, code, NULL, 0);
} }
status_t Trigger(int32 code, TYPE* buffer, size_t size = 0)
{
if (buffer == NULL)
return B_ERROR;
if (size == 0)
return write_port(fPort, code, buffer, sizeof(TYPE));
else
return write_port(fPort, code, buffer, size);
}
status_t InitCheck() status_t InitCheck()
{ {
// Create Port // Create Port
@@ -64,11 +76,13 @@ class PortListener {
fThread = find_thread(fThreadName); fThread = find_thread(fThreadName);
if (fThread < B_OK) { if (fThread < B_OK) {
#ifdef KERNEL_LAND #ifdef KERNEL_LAND
fThread = spawn_kernel_thread((thread_func)&PortListener<TYPE,MAX_MESSAGE_SIZE, fThread = spawn_kernel_thread((thread_func)&PortListener<TYPE,
MAX_MESSAGE_DEEP, PRIORITY>::threadFunction, fThreadName, PRIORITY, &fInformation); MAX_MESSAGE_SIZE, MAX_MESSAGE_DEEP, PRIORITY>::threadFunction,
fThreadName, PRIORITY, &fInformation);
#else #else
fThread = spawn_thread((thread_func)&PortListener<TYPE,MAX_MESSAGE_SIZE, fThread = spawn_thread((thread_func)&PortListener<TYPE,
MAX_MESSAGE_DEEP, PRIORITY>::threadFunction, fThreadName, PRIORITY, &fInformation); MAX_MESSAGE_SIZE, MAX_MESSAGE_DEEP, PRIORITY>::threadFunction,
fThreadName, PRIORITY, &fInformation);
#endif #endif
} }
@@ -93,14 +107,17 @@ class PortListener {
status_t Stop() status_t Stop()
{ {
status_t status; status_t status;
close_port(fPort);
// Closing the port should provoke the thread to finish
wait_for_thread(fThread, &status); wait_for_thread(fThread, &status);
return status; return status;
} }
private: private:
struct PortListenerInfo { struct PortListenerInfo {
port_id* port; port_id* port;
port_listener_func func; port_listener_func func;
@@ -158,4 +175,3 @@ class PortListener {
}; // PortListener }; // PortListener
#endif // PORTLISTENER_H_ #endif // PORTLISTENER_H_