Skip to content

Commit

Permalink
Merge 02d9546 into 25780f9
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavidsaver committed Apr 5, 2023
2 parents 25780f9 + 02d9546 commit 5d87376
Show file tree
Hide file tree
Showing 82 changed files with 8,463 additions and 273 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ tools_DEPEND_DIRS = src
DIRS += ioc
ioc_DEPEND_DIRS = src

ifdef BASE_3_15
DIRS += qsrv
qsrv_DEPEND_DIRS = src ioc
endif

DIRS += test
test_DEPEND_DIRS = src ioc

Expand Down
15 changes: 8 additions & 7 deletions coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ make -C "$TDIR" -j8 \
CMD_LDFLAGS='-fprofile-arcs -ftest-coverage' \
runtests

OUTDIR="$PWD"
cd "$TDIR"/src/O.*
OUTDIR="$PWD"/coverage
install -d "$OUTDIR"

gcovr -v -r .. --html --html-details -o coverage.html
cd "$TDIR"/src/O.linux-*
gcovr -v -r .. --html --html-details -o "$OUTDIR"/coverage.html

tar -cavf "$OUTDIR"/coverage.tar.bz2 coverage*.html
cd "$TDIR"/ioc/O.linux-*
gcovr -v -r .. --html --html-details -o "$OUTDIR"/coverage-ioc.html

install -d "$OUTDIR/coverage"
rm -f "$OUTDIR/coverage"/*
tar -C "$OUTDIR/coverage" -xaf "$OUTDIR"/coverage.tar.bz2
cd "$OUTDIR"
tar -cavf coverage.tar.bz2 coverage*.html
56 changes: 53 additions & 3 deletions ioc/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#
# Copyright - See the COPYRIGHT that is included with this distribution.
# pvxs is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#
# Author George S. McIntyre <george@level-n.com>, 2023
#

TOP=..

include $(TOP)/configure/CONFIG
# cfg/ sometimes isn't correctly included due to a Base bug
# cfg/ sometimes isn't correctly included due to an issue in epics-base
# so we do here (maybe again) as workaround
include $(TOP)/configure/CONFIG_PVXS_MODULE
include $(TOP)/configure/CONFIG_PVXS_VERSION
Expand All @@ -23,13 +31,55 @@ SHRLIB_VERSION = $(PVXS_MAJOR_VERSION).$(PVXS_MINOR_VERSION)

pvxsIoc_SRCS += iochooks.cpp

ifdef BASE_3_15

pvxsIoc_SRCS += credentials.cpp
pvxsIoc_SRCS += channel.cpp
pvxsIoc_SRCS += demo.cpp
pvxsIoc_SRCS += dberrormessage.cpp
pvxsIoc_SRCS += imagedemo.c
pvxsIoc_SRCS += iocsource.cpp
pvxsIoc_SRCS += localfieldlog.cpp
pvxsIoc_SRCS += securityclient.cpp
pvxsIoc_SRCS += singlesource.cpp
pvxsIoc_SRCS += singlesourcehooks.cpp
pvxsIoc_SRCS += singlesrcsubscriptionctx.cpp
pvxsIoc_SRCS += typeutils.cpp

ifdef BASE_7_0

pvxsIoc_SRCS += field.cpp
pvxsIoc_SRCS += fielddefinition.cpp
pvxsIoc_SRCS += fieldname.cpp
pvxsIoc_SRCS += fieldsubscriptionctx.cpp
pvxsIoc_SRCS += group.cpp
pvxsIoc_SRCS += groupconfigprocessor.cpp
pvxsIoc_SRCS += groupprocessorcontext.cpp
pvxsIoc_SRCS += groupsource.cpp
pvxsIoc_SRCS += groupsourcehooks.cpp

else # BASE_7_0

pvxsIoc_SRCS += dummygroup.cpp

endif # BASE_7_0

pvxsIoc_LIBS += $(EPICS_BASE_IOC_LIBS)

else # BASE_3_15

pvxsIoc_SRCS += dummysingle.cpp
pvxsIoc_SRCS += dummygroup.cpp

pvxsIoc_LIBS += Com

endif # BASE_3_15

LIB_LIBS += pvxs
LIB_LIBS += $(EPICS_BASE_IOC_LIBS)

#===========================

include $(TOP)/configure/RULES
include $(TOP)/configure/RULES_PVXS_MODULE
#----------------------------------------
# ADD RULES AFTER THIS LINE

37 changes: 37 additions & 0 deletions ioc/channel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright - See the COPYRIGHT that is included with this distribution.
* pvxs is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*
* Author George S. McIntyre <george@level-n.com>, 2023
*
*/

#include <string>

#include "channel.h"
#include "utilpvt.h"

namespace pvxs {
namespace ioc {
/**
* Construct a group channel from a given db channel name
*
* @param name the db channel name
*/
Channel::Channel(const std::string& name)
:pDbChannel(std::shared_ptr<dbChannel>(dbChannelCreate(name.c_str()),
[](dbChannel* ch) {
if (ch) {
dbChannelDelete(ch);
}
}))
{
if(!pDbChannel)
throw std::runtime_error(SB()<<"Invalid PV: "<<name);
if (dbChannelOpen(pDbChannel.get()))
throw std::invalid_argument(SB() << "Failed dbChannelOpen(\"" << dbChannelName(pDbChannel) <<"\")");
}

} // pvxs
} // ioc
92 changes: 92 additions & 0 deletions ioc/channel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

/*
* Copyright - See the COPYRIGHT that is included with this distribution.
* pvxs is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*
* Author George S. McIntyre <george@level-n.com>, 2023
*
*/

#ifndef PVXS_CHANNEL_H
#define PVXS_CHANNEL_H

#include <string>
#include <memory>

#include <dbChannel.h>

namespace pvxs {
namespace ioc {

/**
* This class encapsulates a shared pointer to a dbChannel but provides constructors
* from string and dbChannel to make its use simpler. It can be used wherever a dbChannel is used.
* As a bonus when constructed with parameters it provides an already open dbChannel.
*/
class Channel {
private:
std::shared_ptr<dbChannel> pDbChannel;

public:
Channel() = default;
// This constructor calls dbChannelOpen()
explicit Channel(const std::string& name);

/**
* Destructor is default because pDbChannel cleans up after itself.
*/
~Channel() = default;

/**
* Cast as a shared pointer to a dbChannel. This returns the pDbChannel member
*
* @return the pDbChannel member
*/
operator dbChannel*() const {
return pDbChannel.get();
}
/**
* Const pointer indirection operator
* @return pointer to the dbChannel associated with this group channel
*/
const dbChannel* operator->() const {
return pDbChannel.get();
}

explicit operator bool() const {
return pDbChannel.operator bool();
}

/**
* Move constructor
*
* @param other other Channel
*/
Channel(Channel&& other) noexcept
:pDbChannel(std::move(other.pDbChannel)) {
}

/**
* Move assignment operator
*
* @param other the other channel
* @return the moved channel
*/
Channel& operator=(Channel&& other) noexcept {
pDbChannel = std::move(other.pDbChannel);
other.pDbChannel = nullptr;
return *this;
}

// Disallowed methods. Copy and move constructors
Channel(const Channel&) = delete;
const std::shared_ptr<dbChannel>& shared_ptr() const {
return pDbChannel;
};
};

} // pvxs
} // ioc

#endif //PVXS_CHANNEL_H
48 changes: 48 additions & 0 deletions ioc/credentials.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright - See the COPYRIGHT that is included with this distribution.
* pvxs is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*
* Author George S. McIntyre <george@level-n.com>, 2023
*
*/

#include <utilpvt.h>

#include "credentials.h"

namespace pvxs {
namespace ioc {

/**
* eg.
* "username" implies "ca/" prefix
* "krb/principle"
* "role/groupname"
*
* @param clientCredentials
*/

Credentials::Credentials(const server::ClientCredentials& clientCredentials) {
// Extract host name part (or whole thing if no colon present)
auto pos = clientCredentials.peer.find_first_of(':');
host = clientCredentials.peer.substr(0, pos);

// "ca" style credentials
if (clientCredentials.method == "ca") {
pos = clientCredentials.account.find_last_of('/');
if (pos == std::string::npos) {
cred.emplace_back(clientCredentials.account);
} else {
cred.emplace_back(clientCredentials.account.substr(pos + 1));
}
} else {
cred.emplace_back(SB() << clientCredentials.method << '/' << clientCredentials.account);
}

for (const auto& role: clientCredentials.roles()) {
cred.emplace_back(SB() << "role/" << role);
}
}
} // pvxs
} // ioc
39 changes: 39 additions & 0 deletions ioc/credentials.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright - See the COPYRIGHT that is included with this distribution.
* pvxs is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*
* Author George S. McIntyre <george@level-n.com>, 2023
*
*/

#ifndef PVXS_CREDENTIALS_H
#define PVXS_CREDENTIALS_H

#include <vector>
#include <string>

#include <pvxs/source.h>

namespace pvxs {
namespace ioc {

/**
* eg.
* "username" implies "ca/" prefix
* "krb/principle"
* "role/groupname"
*/
class Credentials {
public:
std::vector<std::string> cred;
std::string host;
explicit Credentials(const server::ClientCredentials& clientCredentials);
Credentials(const Credentials&) = delete;
Credentials(Credentials&&) = default;
};

} // pvxs
} // ioc

#endif //PVXS_CREDENTIALS_H
47 changes: 47 additions & 0 deletions ioc/dbentry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright - See the COPYRIGHT that is included with this distribution.
* pvxs is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*
* Author George S. McIntyre <george@level-n.com>, 2023
*
*/

#ifndef PVXS_DBENTRY_H
#define PVXS_DBENTRY_H

#include <dbStaticLib.h>
#include <dbAccess.h>

namespace pvxs {
namespace ioc {

/**
* Wrapper class for DBENTRY that is a type that encapsulates an IOC database entry.
*/
class DBEntry {
DBENTRY ent{};
public:
DBEntry() {
dbInitEntry(pdbbase, &ent);
}
DBEntry(const DBEntry&) = delete;
DBEntry(DBEntry&&) = delete;

~DBEntry() {
dbFinishEntry(&ent);
}

operator DBENTRY*() {
return &ent;
}

DBENTRY* operator->() {
return &ent;
}

};

} // ioc
} // pvxs
#endif //PVXS_DBENTRY_H
Loading

0 comments on commit 5d87376

Please sign in to comment.