Files
epics-base/modules/database/src/ioc/db/dbExtractArray.c
Ben Franksen 27fe3e4468 refactor db_field_log and filters to get rid of dbfl_type_rec
This refactor simplifies and streamlines the code associated with server
side filters. Apart from immediate benefits (clearer code, less duplication)
it is also hoped that this will make it easier to add write filters.

The data pointer dbfl_ref.field can now either point to a copy owned by a
filter, or it can point to the original data owned by a record. In the
latter case, the dbfl_ref.dtor is NULL.

The dbExtractArray* functions are unified to the single function
dbExtractArray and stripped of conversion functionality. This is redundant
because we always call dbGet after applying filters, which takes care of
conversion. Accordingly, dbChannelMakeArrayCopy is now obsolete and its
single use (in the ts filter) replaced with dbExtractArray. Instead, we add
the helper function dbChannelGetArrayInfo to wrap the common boilerplate
around calls to the get_array_info method, used in both arr.c and ts.c.
2021-01-12 17:49:10 +01:00

57 lines
1.9 KiB
C

/*************************************************************************\
* Copyright (c) 2010 Brookhaven National Laboratory.
* Copyright (c) 2010 Helmholtz-Zentrum Berlin
* fuer Materialien und Energie GmbH.
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* SPDX-License-Identifier: EPICS
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Ralph Lange <Ralph.Lange@bessy.de>
*
* based on dbConvert.c, see copyNoConvert
* written by: Bob Dalesio, Marty Kraimer
*/
#include <string.h>
#include <assert.h>
#include "epicsTypes.h"
#define epicsExportSharedSymbols
#include "dbAddr.h"
#include "dbExtractArray.h"
void dbExtractArray(const void *pfrom, void *pto, short field_size,
long nRequest, long no_elements, long offset, long increment)
{
char *pdst = (char *) pto;
const char *psrc = (char *) pfrom;
/* assert preconditions */
assert(nRequest >= 0);
assert(no_elements >= 0);
assert(increment > 0);
assert(0 <= offset);
assert(offset < no_elements);
if (increment == 1) {
long nUpperPart =
nRequest < no_elements - offset ? nRequest : no_elements - offset;
memcpy(pdst, psrc + (offset * field_size), field_size * nUpperPart);
if (nRequest > nUpperPart)
memcpy(pdst + (field_size * nUpperPart), psrc,
field_size * (nRequest - nUpperPart));
} else {
for (; nRequest > 0; nRequest--, pdst += field_size, offset += increment) {
offset %= no_elements;
memcpy(pdst, psrc + (offset * field_size), field_size);
}
}
}