BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Signal.cpp Source File

Signal.cpp

00001 /*
00002  * Signal.cpp
00003  * Copyright (c) 2017, ZHAW
00004  * All rights reserved.
00005  *
00006  *  Created on: 08.02.2017
00007  *      Author: Marcel Honegger
00008  */
00009 
00010 #include "Signal.h"
00011 
00012 using namespace std;
00013 
00014 int32_t Signal::signals = 0;
00015 
00016 /**
00017  * Creates a signal object and assignes a unique flag.
00018  */
00019 Signal::Signal() {
00020     
00021     mutex.lock();
00022     
00023     int32_t n = 0;
00024     while ((((1 << n) & signals) > 0) && (n < 30)) n++;
00025     signal = (1 << n);
00026     
00027     mutex.unlock();
00028 }
00029 
00030 /**
00031  * Deletes the signal object and releases the assigned flag.
00032  */
00033 Signal::~Signal() {
00034     
00035     mutex.lock();
00036     
00037     signals &= ~signal;
00038     
00039     mutex.unlock();
00040 }
00041 
00042 /**
00043  * Gets the assigned signal flag.
00044  */
00045 int32_t Signal::read() {
00046     
00047     return signal;
00048 }
00049 
00050 /**
00051  * The empty operator is a shorthand notation of the <code>read()</code> method.
00052  */
00053 Signal::operator int32_t() {
00054     
00055     return read();
00056 }