vfs: check userland buffers before reading them.
[haiku.git] / src / servers / mail / LEDAnimation.cpp
blob3be7d02dbf82d2c89f9ad35514578bcaf8798d03
3 #include "LEDAnimation.h"
5 #include <InterfaceDefs.h>
7 #include <stdio.h>
9 #define SNOOZE_TIME 150000
12 LEDAnimation::LEDAnimation()
14 fThread(-1),
15 fRunning(false),
16 fOrigModifiers(::modifiers())
21 LEDAnimation::~LEDAnimation()
23 Stop();
27 void
28 LEDAnimation::Start()
30 // don't do anything if the thread is already running
31 if (fThread >= 0)
32 return;
34 fOrigModifiers = ::modifiers();
35 ::set_keyboard_locks(0);
36 fRunning = true;
37 fThread = ::spawn_thread(AnimationThread,"LED thread",B_NORMAL_PRIORITY,this);
38 ::resume_thread(fThread);
42 void
43 LEDAnimation::Stop()
45 // don't do anything if the thread doesn't run
46 if (fThread < 0)
47 return;
49 fRunning = false;
50 status_t result;
51 ::wait_for_thread(fThread,&result);
53 ::set_keyboard_locks(fOrigModifiers);
57 int32
58 LEDAnimation::AnimationThread(void* data)
60 LEDAnimation *anim = (LEDAnimation*)data;
62 while (anim->fRunning) {
63 LED(B_NUM_LOCK,true);
64 LED(B_NUM_LOCK,false);
66 LED(B_CAPS_LOCK,true);
67 LED(B_CAPS_LOCK,false);
69 LED(B_SCROLL_LOCK,true);
70 LED(B_SCROLL_LOCK,false);
72 LED(B_CAPS_LOCK,true);
73 LED(B_CAPS_LOCK,false);
75 anim->fThread = -1;
76 return 0;
80 void
81 LEDAnimation::LED(uint32 mod,bool on)
83 uint32 current_modifiers = ::modifiers();
84 if (on)
85 current_modifiers |= mod;
86 else
87 current_modifiers &= ~mod;
88 ::set_keyboard_locks(current_modifiers);
89 if (on)
90 ::snooze(SNOOZE_TIME);