Skip to content

Commit

Permalink
fix: inline methods that use unlinked functions (indilib#1312)
Browse files Browse the repository at this point in the history
  • Loading branch information
pawel-soja authored Jan 7, 2021
1 parent c9efe69 commit f626bcf
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 88 deletions.
127 changes: 39 additions & 88 deletions libs/indibase/property/indiproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,47 @@
*******************************************************************************/

#include "indiproperty.h"
#include "indiproperty_p.h"

#include <cstdlib>
#include <cstring>
#include <cstdarg>

extern "C" void indi_property_weak_function_throw(...)
namespace INDI
{
fprintf(stderr, "Unsupported function call. Please add indidriver to linker.\n");
}

#define WEAK_FUNCTION(FUNCTION) extern "C" FUNCTION __attribute__((weak, alias("indi_property_weak_function_throw")));

WEAK_FUNCTION(void IUSaveConfigNumber(FILE *, const INumberVectorProperty *))
WEAK_FUNCTION(void IUSaveConfigText(FILE *, const ITextVectorProperty *))
WEAK_FUNCTION(void IUSaveConfigSwitch(FILE *, const ISwitchVectorProperty *))
WEAK_FUNCTION(void IUSaveConfigBLOB(FILE *, const IBLOBVectorProperty *))

WEAK_FUNCTION(void IDDefTextVA(const ITextVectorProperty *, const char *, va_list))
WEAK_FUNCTION(void IDDefNumberVA(const INumberVectorProperty *, const char *, va_list))
WEAK_FUNCTION(void IDDefSwitchVA(const ISwitchVectorProperty *, const char *, va_list))
WEAK_FUNCTION(void IDDefLightVA(const ILightVectorProperty *, const char *, va_list))
WEAK_FUNCTION(void IDDefBLOBVA(const IBLOBVectorProperty *, const char *, va_list))
PropertyPrivate::PropertyPrivate(void *property, INDI_PROPERTY_TYPE type)
: property(property)
, type(property ? type : INDI_UNKNOWN)
, registered(property != nullptr)
{ }

WEAK_FUNCTION(void IDSetTextVA(const ITextVectorProperty *, const char *, va_list))
WEAK_FUNCTION(void IDSetNumberVA(const INumberVectorProperty *, const char *, va_list))
WEAK_FUNCTION(void IDSetSwitchVA(const ISwitchVectorProperty *, const char *, va_list))
WEAK_FUNCTION(void IDSetLightVA(const ILightVectorProperty *, const char *, va_list))
WEAK_FUNCTION(void IDSetBLOBVA(const IBLOBVectorProperty *, const char *, va_list))
PropertyPrivate::PropertyPrivate(ITextVectorProperty *property)
: property(property)
, type(property ? INDI_TEXT : INDI_UNKNOWN)
, registered(property != nullptr)
{ }

namespace INDI
{
PropertyPrivate::PropertyPrivate(INumberVectorProperty *property)
: property(property)
, type(property ? INDI_NUMBER : INDI_UNKNOWN)
, registered(property != nullptr)
{ }

class PropertyPrivate
{
public:
void *property = nullptr;
BaseDevice *baseDevice = nullptr;
INDI_PROPERTY_TYPE type = INDI_UNKNOWN;
bool registered = false;
bool dynamic = false;
PropertyPrivate::PropertyPrivate(ISwitchVectorProperty *property)
: property(property)
, type(property ? INDI_SWITCH : INDI_UNKNOWN)
, registered(property != nullptr)
{ }

PropertyPrivate(void *property = nullptr, INDI_PROPERTY_TYPE type = INDI_UNKNOWN);
virtual ~PropertyPrivate();
};
PropertyPrivate::PropertyPrivate(ILightVectorProperty *property)
: property(property)
, type(property ? INDI_LIGHT : INDI_UNKNOWN)
, registered(property != nullptr)
{ }

PropertyPrivate::PropertyPrivate(void *property, INDI_PROPERTY_TYPE type)
PropertyPrivate::PropertyPrivate(IBLOBVectorProperty *property)
: property(property)
, type(property ? type : INDI_UNKNOWN)
, type(property ? INDI_BLOB : INDI_UNKNOWN)
, registered(property != nullptr)
{ }

Expand Down Expand Up @@ -131,37 +124,39 @@ PropertyPrivate::~PropertyPrivate()
}

Property::Property()
: d_ptr(new PropertyPrivate())
: d_ptr(new PropertyPrivate(nullptr, INDI_UNKNOWN))
{ }

Property::Property(void *property, INDI_PROPERTY_TYPE type)
: d_ptr(new PropertyPrivate(property, type))
{ }

Property::Property(INumberVectorProperty *property)
: d_ptr(new PropertyPrivate(property, INDI_NUMBER))
: d_ptr(new PropertyPrivate(property))
{ }

Property::Property(ITextVectorProperty *property)
: d_ptr(new PropertyPrivate(property, INDI_TEXT))
: d_ptr(new PropertyPrivate(property))
{ }

Property::Property(ISwitchVectorProperty *property)
: d_ptr(new PropertyPrivate(property, INDI_SWITCH))
: d_ptr(new PropertyPrivate(property))
{ }

Property::Property(ILightVectorProperty *property)
: d_ptr(new PropertyPrivate(property, INDI_LIGHT))
: d_ptr(new PropertyPrivate(property))
{ }

Property::Property(IBLOBVectorProperty *property)
: d_ptr(new PropertyPrivate(property, INDI_BLOB))
: d_ptr(new PropertyPrivate(property))
{ }

Property::~Property()
{
{ }

}
Property::Property(PropertyPrivate &dd)
: d_ptr(&dd)
{ }

void Property::setProperty(void *p)
{
Expand Down Expand Up @@ -225,18 +220,6 @@ BaseDevice *Property::getBaseDevice() const
return d->baseDevice;
}

void Property::save(FILE *fp)
{
switch (getType())
{
case INDI_NUMBER: IUSaveConfigNumber (fp, getNumber()); break;
case INDI_TEXT: IUSaveConfigText (fp, getText()); break;
case INDI_SWITCH: IUSaveConfigSwitch (fp, getSwitch()); break;
//case INDI_LIGHT: IUSaveConfigLight (fp, getLight()); break;
case INDI_BLOB: IUSaveConfigBLOB (fp, getBLOB()); break;
default:;;
}
}

void Property::setName(const char *name)
{
Expand Down Expand Up @@ -493,36 +476,4 @@ IBLOBVectorProperty *Property::getBLOB() const
return nullptr;
}

void Property::apply(const char *format, ...)
{
va_list ap;
va_start(ap, format);
switch (getType())
{
case INDI_NUMBER: IDSetNumberVA(getNumber(), format, ap); break;
case INDI_TEXT: IDSetTextVA(getText(), format, ap); break;
case INDI_SWITCH: IDSetSwitchVA(getSwitch(), format, ap); break;
case INDI_LIGHT: IDSetLightVA(getLight(), format, ap); break;
case INDI_BLOB: IDSetBLOBVA(getBLOB(), format, ap); break;
default:;;
}
va_end(ap);
}

void Property::define(const char *format, ...)
{
va_list ap;
va_start(ap, format);
switch (getType())
{
case INDI_NUMBER: IDDefNumberVA(getNumber(), format, ap); break;
case INDI_TEXT: IDDefTextVA(getText(), format, ap); break;
case INDI_SWITCH: IDDefSwitchVA(getSwitch(), format, ap); break;
case INDI_LIGHT: IDDefLightVA(getLight(), format, ap); break;
case INDI_BLOB: IDDefBLOBVA(getBLOB(), format, ap); break;
default:;;
}
va_end(ap);
}

}
50 changes: 50 additions & 0 deletions libs/indibase/property/indiproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "indiutility.h"
#include <memory>

#include <cstdarg>
#include "indidriver.h"

namespace INDI
{
class BaseDevice;
Expand Down Expand Up @@ -96,6 +99,53 @@ class Property

protected:
std::shared_ptr<PropertyPrivate> d_ptr;
Property(PropertyPrivate &dd);
};


inline void Property::save(FILE *fp)
{
switch (getType())
{
case INDI_NUMBER: IUSaveConfigNumber (fp, getNumber()); break;
case INDI_TEXT: IUSaveConfigText (fp, getText()); break;
case INDI_SWITCH: IUSaveConfigSwitch (fp, getSwitch()); break;
//case INDI_LIGHT: IUSaveConfigLight (fp, getLight()); break;
case INDI_BLOB: IUSaveConfigBLOB (fp, getBLOB()); break;
default:;;
}
}

inline void Property::apply(const char *format, ...)
{
va_list ap;
va_start(ap, format);
switch (getType())
{
case INDI_NUMBER: IDSetNumberVA(getNumber(), format, ap); break;
case INDI_TEXT: IDSetTextVA(getText(), format, ap); break;
case INDI_SWITCH: IDSetSwitchVA(getSwitch(), format, ap); break;
case INDI_LIGHT: IDSetLightVA(getLight(), format, ap); break;
case INDI_BLOB: IDSetBLOBVA(getBLOB(), format, ap); break;
default:;;
}
va_end(ap);
}

inline void Property::define(const char *format, ...)
{
va_list ap;
va_start(ap, format);
switch (getType())
{
case INDI_NUMBER: IDDefNumberVA(getNumber(), format, ap); break;
case INDI_TEXT: IDDefTextVA(getText(), format, ap); break;
case INDI_SWITCH: IDDefSwitchVA(getSwitch(), format, ap); break;
case INDI_LIGHT: IDDefLightVA(getLight(), format, ap); break;
case INDI_BLOB: IDDefBLOBVA(getBLOB(), format, ap); break;
default:;;
}
va_end(ap);
}

} // namespace INDI
46 changes: 46 additions & 0 deletions libs/indibase/property/indiproperty_p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
Copyright(c) 2011 Jasem Mutlaq. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*******************************************************************************/

#pragma once

#include "indibase.h"

namespace INDI
{

class BaseDevice;
class PropertyPrivate
{
public:
void *property = nullptr;
BaseDevice *baseDevice = nullptr;
INDI_PROPERTY_TYPE type = INDI_UNKNOWN;
bool registered = false;
bool dynamic = false;

PropertyPrivate(void *property, INDI_PROPERTY_TYPE type);
PropertyPrivate(ITextVectorProperty *property);
PropertyPrivate(INumberVectorProperty *property);
PropertyPrivate(ISwitchVectorProperty *property);
PropertyPrivate(ILightVectorProperty *property);
PropertyPrivate(IBLOBVectorProperty *property);

virtual ~PropertyPrivate();
};

}

0 comments on commit f626bcf

Please sign in to comment.