Eddystone test using modified DAL

Dependencies:   BLE_API mbed-dev-bin nRF51822

Dependents:   microbit-eddystone

Fork of microbit-dal by Lancaster University

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RefCounted.h Source File

RefCounted.h

00001 /*
00002 The MIT License (MIT)
00003 
00004 Copyright (c) 2016 British Broadcasting Corporation.
00005 This software is provided by Lancaster University by arrangement with the BBC.
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a
00008 copy of this software and associated documentation files (the "Software"),
00009 to deal in the Software without restriction, including without limitation
00010 the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011 and/or sell copies of the Software, and to permit persons to whom the
00012 Software is furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00020 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00022 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00023 DEALINGS IN THE SOFTWARE.
00024 */
00025 
00026 #ifndef REF_COUNTED_H
00027 #define REF_COUNTED_H
00028 
00029 #include "mbed.h"
00030 #include "MicroBitConfig.h"
00031 #include "MicroBitDevice.h"
00032 
00033 /**
00034   * Base class for payload for ref-counted objects. Used by ManagedString and MicroBitImage.
00035   * There is no constructor, as this struct is typically malloc()ed.
00036   */
00037 struct RefCounted
00038 {
00039 public:
00040 
00041     /**
00042       * The high 15 bits hold the number of outstanding references. The lowest bit is always 1
00043       * to make sure it doesn't look like vtable.
00044       * Should never be even or one (object should be deleted then).
00045       * When it's set to 0xffff, it means the object sits in flash and should not be counted.
00046       */
00047     uint16_t refCount;
00048 
00049     /**
00050       * Increment reference count.
00051       */
00052     void incr();
00053 
00054     /**
00055       * Decrement reference count.
00056       */
00057     void decr();
00058 
00059     /**
00060       * Initializes for one outstanding reference.
00061       */
00062     void init();
00063 
00064     /**
00065       * Checks if the object resides in flash memory.
00066       *
00067       * @return true if the object resides in flash memory, false otherwise.
00068       */
00069     bool isReadOnly();
00070 };
00071 
00072 #endif