diff --git a/pvAccessApp/ca/caConstants.h b/pvAccessApp/ca/caConstants.h index 753438a..6799e62 100644 --- a/pvAccessApp/ca/caConstants.h +++ b/pvAccessApp/ca/caConstants.h @@ -1,8 +1,7 @@ -/* - * constants.h - * - * Created on: Oct 8, 2010 - * Author: Miha Vitorovic +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ #ifndef CONSTANTS_H_ @@ -17,70 +16,70 @@ using epics::pvData::uint32; using epics::pvData::String; namespace epics { - namespace pvAccess { +namespace pvAccess { - /** CA protocol magic number */ - const int8 CA_MAGIC = 0xCA; - - /** CA protocol major revision (implemented by this library). */ - const int8 CA_MAJOR_PROTOCOL_REVISION = 5; - - /** CA protocol minor revision (implemented by this library). */ - const int8 CA_MINOR_PROTOCOL_REVISION = 0; - - /** Unknown CA protocol minor revision. */ - const int8 CA_UNKNOWN_MINOR_PROTOCOL_REVISION = 0; - - /** CA version signature (e.g. 0x50). */ - const int8 CA_VERSION = ((uint8_t)CA_MAJOR_PROTOCOL_REVISION<<4)|CA_MINOR_PROTOCOL_REVISION; - - /** CA protocol port base. */ - const int32 CA_PORT_BASE = 5056; - - /** Default CA server port. */ - const int32 CA_SERVER_PORT = CA_PORT_BASE+2*CA_MAJOR_PROTOCOL_REVISION; - - /** Default CA beacon port. */ - const int32 CA_BROADCAST_PORT = CA_SERVER_PORT+1; - - /** CA protocol message header size. */ - const int16 CA_MESSAGE_HEADER_SIZE = 8; - - /** - * UDP maximum send message size. - * MAX_UDP: 1500 (max of ethernet and 802.{2,3} MTU) - 20/40(IPv4/IPv6) - * - 8(UDP) - some reserve (the MTU of Ethernet is currently independent - * of its speed variant) - */ - const int32 MAX_UDP_SEND = 1440; - - /** UDP maximum receive message size. */ - const int32 MAX_UDP_RECV = 0xFFFF+16; - - /** TCP maximum receive message size. */ - const int32 MAX_TCP_RECV = 1024*16; - - /** Maximum number of search requests in one search message. */ - const int32 MAX_SEARCH_BATCH_COUNT = 0xFFFF; - - /** Default priority (corresponds to POSIX SCHED_OTHER) */ - const int16 CA_DEFAULT_PRIORITY = 0; - - /** Unreasonable channel name length. */ - const uint32 UNREASONABLE_CHANNEL_NAME_LENGTH = 500; - - /** Invalid data type. */ - const int16 INVALID_DATA_TYPE = (int16)0xFFFF; - - /** Invalid IOID. */ - const int32 INVALID_IOID = 0; - - /** All messages must be aligned to 8-bytes (64-bit). */ - const int32 CA_ALIGNMENT = 8; - - /** Default CA provider name. */ - const String PVACCESS_DEFAULT_PROVIDER = "local"; - } + /** CA protocol magic number */ + const int8 CA_MAGIC = 0xCA; + + /** CA protocol major revision (implemented by this library). */ + const int8 CA_MAJOR_PROTOCOL_REVISION = 5; + + /** CA protocol minor revision (implemented by this library). */ + const int8 CA_MINOR_PROTOCOL_REVISION = 0; + + /** Unknown CA protocol minor revision. */ + const int8 CA_UNKNOWN_MINOR_PROTOCOL_REVISION = 0; + + /** CA version signature (e.g. 0x50). */ + const int8 CA_VERSION = ((uint8_t)CA_MAJOR_PROTOCOL_REVISION<<4)|CA_MINOR_PROTOCOL_REVISION; + + /** CA protocol port base. */ + const int32 CA_PORT_BASE = 5056; + + /** Default CA server port. */ + const int32 CA_SERVER_PORT = CA_PORT_BASE+2*CA_MAJOR_PROTOCOL_REVISION; + + /** Default CA beacon port. */ + const int32 CA_BROADCAST_PORT = CA_SERVER_PORT+1; + + /** CA protocol message header size. */ + const int16 CA_MESSAGE_HEADER_SIZE = 8; + + /** + * UDP maximum send message size. + * MAX_UDP: 1500 (max of ethernet and 802.{2,3} MTU) - 20/40(IPv4/IPv6) + * - 8(UDP) - some reserve (the MTU of Ethernet is currently independent + * of its speed variant) + */ + const int32 MAX_UDP_SEND = 1440; + + /** UDP maximum receive message size. */ + const int32 MAX_UDP_RECV = 0xFFFF+16; + + /** TCP maximum receive message size. */ + const int32 MAX_TCP_RECV = 1024*16; + + /** Maximum number of search requests in one search message. */ + const int32 MAX_SEARCH_BATCH_COUNT = 0xFFFF; + + /** Default priority (corresponds to POSIX SCHED_OTHER) */ + const int16 CA_DEFAULT_PRIORITY = 0; + + /** Unreasonable channel name length. */ + const uint32 UNREASONABLE_CHANNEL_NAME_LENGTH = 500; + + /** Invalid data type. */ + const int16 INVALID_DATA_TYPE = (int16)0xFFFF; + + /** Invalid IOID. */ + const int32 INVALID_IOID = 0; + + /** All messages must be aligned to 8-bytes (64-bit). */ + const int32 CA_ALIGNMENT = 8; + + /** Default CA provider name. */ + const String PVACCESS_DEFAULT_PROVIDER = "local"; +} } #endif /* CONSTANTS_H_ */ diff --git a/pvAccessApp/ca/clientFactory.cpp b/pvAccessApp/ca/clientFactory.cpp index 1634c9b..91ac70d 100644 --- a/pvAccessApp/ca/clientFactory.cpp +++ b/pvAccessApp/ca/clientFactory.cpp @@ -1,8 +1,12 @@ -/* clientFactory.cpp */ -/* Author: Matej Sekoranja Date: 2011.2.1 */ - +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ + #include -#include +#include + #include using namespace epics::pvData; diff --git a/pvAccessApp/ca/clientFactory.h b/pvAccessApp/ca/clientFactory.h index 099e2f4..c0bc9db 100644 --- a/pvAccessApp/ca/clientFactory.h +++ b/pvAccessApp/ca/clientFactory.h @@ -1,11 +1,17 @@ -/* clientFactory.h */ +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ + #ifndef CLIENTFACTORY_H #define CLIENTFACTORY_H #include #include -namespace epics { namespace pvAccess { +namespace epics { +namespace pvAccess { class ClientFactory { public: diff --git a/pvAccessApp/ca/version.cpp b/pvAccessApp/ca/version.cpp index 4a50289..12d6e24 100644 --- a/pvAccessApp/ca/version.cpp +++ b/pvAccessApp/ca/version.cpp @@ -1,8 +1,7 @@ -/* - * version.cpp - * - * Created on: Oct 8, 2010 - * Author: Miha Vitorovic +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ #include @@ -13,32 +12,31 @@ using std::stringstream; using epics::pvData::String; namespace epics { - namespace pvAccess { +namespace pvAccess { +const String Version::getLongVersionString() const { + stringstream ret; + ret<0) { + ret<<"D"<0) { - ret<<"D"<0) { - ret<<"D"<0) { + ret<<"D"< namespace epics { - namespace pvAccess { +namespace pvAccess { using epics::pvData::String; @@ -28,17 +27,19 @@ namespace epics { * @param developmentVersion development version. */ Version(String productName, String implementationLangugage, - int majorVersion, int minorVersion, int maintenanceVersion, - int developmentVersion) : - _productName(productName), _implementationLanguage( - implementationLangugage), _majorVersion(majorVersion), - _minorVersion(minorVersion), _maintenanceVersion( - maintenanceVersion), _developmentVersion( - developmentVersion) { + int majorVersion, int minorVersion, + int maintenanceVersion, int developmentVersion) : + _productName(productName), + _implementationLanguage(implementationLangugage), + _majorVersion(majorVersion), + _minorVersion(minorVersion), + _maintenanceVersion(maintenanceVersion), + _developmentVersion(developmentVersion) + { } /** The name of the product */ - const inline String getProductName() const { + inline const String getProductName() const { return _productName; } @@ -129,7 +130,7 @@ namespace epics { int _maintenanceVersion; int _developmentVersion; }; - } +} } #endif /* VERSION_H_ */ diff --git a/pvAccessApp/utils/configuration.cpp b/pvAccessApp/utils/configuration.cpp index de9a2d4..e1f1707 100644 --- a/pvAccessApp/utils/configuration.cpp +++ b/pvAccessApp/utils/configuration.cpp @@ -1,11 +1,14 @@ -/* - * configuration.cpp +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ #include #include -namespace epics { namespace pvAccess { +namespace epics { +namespace pvAccess { using namespace epics::pvData; using namespace std; @@ -193,7 +196,7 @@ void Properties::list() SystemConfigurationImpl::SystemConfigurationImpl() { - _envParam.name = new char[MAX_NAME_LENGHT]; + _envParam.name = new char[256]; _envParam.pdflt = NULL; // no exception, default value is taken //_ibuffer.exceptions ( ifstream::failbit | ifstream::badbit ); diff --git a/pvAccessApp/utils/configuration.h b/pvAccessApp/utils/configuration.h index c888c83..0dfceb8 100644 --- a/pvAccessApp/utils/configuration.h +++ b/pvAccessApp/utils/configuration.h @@ -1,5 +1,7 @@ -/* - * configuration.h +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ #ifndef CONFIGURATION_H @@ -20,14 +22,9 @@ #include -namespace epics { namespace pvAccess { +namespace epics { +namespace pvAccess { -#define MAX_NAME_LENGHT 300 - - -/** - * Properties - */ class Properties { public: @@ -73,14 +70,13 @@ private: class Configuration : private epics::pvData::NoDefaultMethods { public: - typedef std::tr1::shared_ptr shared_pointer; - typedef std::tr1::shared_ptr const_shared_pointer; + POINTER_DEFINITIONS(Configuration); - /* + /** * Destructor. */ virtual ~Configuration() {}; - /* + /** * Get the environment variable specified by name or return default value * if it does not exist. * @@ -90,7 +86,7 @@ public: * @return environment variable value as bool or default value if it does not exist. */ virtual bool getPropertyAsBoolean(const std::string name, const bool defaultValue) = 0; - /* + /** * Get the environment variable specified by name or return default value * if it does not exist. * @@ -100,7 +96,7 @@ public: * @return environment variable value as int32 or default value if it does not exist. */ virtual epics::pvData::int32 getPropertyAsInteger(const std::string name, const epics::pvData::int32 defaultValue) = 0; - /* + /** * Get the environment variable specified by name or return default value * if it does not exist. * @@ -110,7 +106,7 @@ public: * @return environment variable value as float or default value if it does not exist. */ virtual float getPropertyAsFloat(const std::string name, const float defaultValue) = 0; - /* + /** * Get the environment variable specified by name or return default value * if it does not exist. * @@ -120,7 +116,7 @@ public: * @return environment variable value as double or default value if it does not exist. */ virtual float getPropertyAsDouble(const std::string name, const double defaultValue) = 0; - /* + /** * Get the environment variable specified by name or return default value * if it does not exist. * @@ -156,11 +152,11 @@ private: class ConfigurationProvider : private epics::pvData::NoDefaultMethods { public: - /* + /** * Destructor. */ virtual ~ConfigurationProvider() {}; - /* + /** * Return configuration specified by name. * * @param name name of the configuration to return. @@ -168,7 +164,7 @@ public: * @return configuration specified by name or NULL if it does not exists. */ virtual Configuration* getConfiguration(const std::string name) = 0; - /* + /** * Register configuration. * * @param name name of the configuration to register. @@ -181,7 +177,7 @@ class ConfigurationProviderImpl: public ConfigurationProvider { public: ConfigurationProviderImpl(); - /* + /** * Destructor. Note: Registered configurations will be deleted!! */ ~ConfigurationProviderImpl(); @@ -199,7 +195,7 @@ private: class ConfigurationFactory : private epics::pvData::NoDefaultMethods { public: - /* + /** * Lazily creates configuration provider. * * @param name name of the configuration to register. diff --git a/pvAccessApp/utils/hexDump.cpp b/pvAccessApp/utils/hexDump.cpp index 75d2e1e..08cd607 100644 --- a/pvAccessApp/utils/hexDump.cpp +++ b/pvAccessApp/utils/hexDump.cpp @@ -1,8 +1,7 @@ -/* - * hexDump.cpp - * - * Created on: Nov 3, 2010 - * Author: Miha Vitorovic +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ #include @@ -16,103 +15,91 @@ using std::endl; using std::cout; namespace epics { - namespace pvAccess { +namespace pvAccess { - String toHex(int8); - char toAscii(int8); +/// Byte to hexchar mapping. +static const char lookup[] = { + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; - void hexDump(const String name, const int8 *bs, int len) { - hexDump(name, bs, 0, len); - } +/// Get hex representation of byte. +String toHex(int8 b) { + String sb; - void hexDump(const String name, const int8 *bs, int start, int len) { - hexDump("", name, bs, start, len); - } + int upper = (b>>4)&0x0F; + sb += lookup[upper]; - void hexDump(const String prologue, const String name, const int8 *bs, - int start, int len) { + int lower = b&0x0F; + sb += lookup[lower]; - stringstream header; + sb += ' '; - header<>4)&0x0F; - sb += lookup[upper]; - - int lower = b&0x0F; - sb += lookup[lower]; - - sb += ' '; - - return sb; - } - - /** - * Get ASCII representation of byte, dot if non-readable. - * @param b - * @return ASCII representation of byte, dot if non-readable. - */ - char toAscii(int8 b) { - if(b>(int8)31&&b<(int8)127) - return (char)b; - else - return '.'; - } - - } + return sb; +} + +/// Get ASCII representation of byte, dot if non-readable. +char toAscii(int8 b) { + if(b>(int8)31&&b<(int8)127) + return (char)b; + else + return '.'; +} + +void hexDump(const String name, const int8 *bs, int len) { + hexDump(name, bs, 0, len); +} + +void hexDump(const String name, const int8 *bs, int start, int len) { + hexDump("", name, bs, start, len); +} + +void hexDump(const String prologue, const String name, const int8 *bs, + int start, int len) { + + stringstream header; + + header< namespace epics { - namespace pvAccess { +namespace pvAccess { - /** - * Output a buffer in hex format. - * @param name name (description) of the message. - * @param bs buffer to dump - * @param len first bytes (length) to dump. - */ - void hexDump(const epics::pvData::String name, const epics::pvData::int8 *bs, int len); + /** + * Output a buffer in hex format. + * @param name name (description) of the message. + * @param bs buffer to dump + * @param len first bytes (length) to dump. + */ + void hexDump(const epics::pvData::String name, const epics::pvData::int8 *bs, int len); - /** - * Output a buffer in hex format. - * @param[in] name name (description) of the message. - * @param[in] bs buffer to dump - * @param[in] start dump message using given offset. - * @param[in] len first bytes (length) to dump. - */ - void hexDump(const epics::pvData::String name, const epics::pvData::int8 *bs, int start, int len); + /** + * Output a buffer in hex format. + * @param[in] name name (description) of the message. + * @param[in] bs buffer to dump + * @param[in] start dump message using given offset. + * @param[in] len first bytes (length) to dump. + */ + void hexDump(const epics::pvData::String name, const epics::pvData::int8 *bs, int start, int len); - /** - * Output a buffer in hex format. - * @param[in] prologue string to prefixed to debug output, can be null - * @param[in] name name (description) of the message. - * @param[in] bs buffer to dump - * @param[in] start dump message using given offset. - * @param[in] len first bytes (length) to dump. - */ - void hexDump(const epics::pvData::String prologue, const epics::pvData::String name, const epics::pvData::int8 *bs, - int start, int len); + /** + * Output a buffer in hex format. + * @param[in] prologue string to prefixed to debug output, can be null + * @param[in] name name (description) of the message. + * @param[in] bs buffer to dump + * @param[in] start dump message using given offset. + * @param[in] len first bytes (length) to dump. + */ + void hexDump(const epics::pvData::String prologue, const epics::pvData::String name, + const epics::pvData::int8 *bs, int start, int len); - } +} } #endif /* HEXDUMP_H_ */ diff --git a/pvAccessApp/utils/inetAddressUtil.cpp b/pvAccessApp/utils/inetAddressUtil.cpp index a07b377..4c40b67 100644 --- a/pvAccessApp/utils/inetAddressUtil.cpp +++ b/pvAccessApp/utils/inetAddressUtil.cpp @@ -1,23 +1,18 @@ -/* - * inetAddressUtil.cpp - * - * Created on: Nov 12, 2010 - * Author: Miha Vitorovic +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ -/* pvAccess */ -#include -/* pvData */ +#include #include #include -/* EPICSv3 */ #include #include #include #include -/* standard */ #include #include #include @@ -27,140 +22,140 @@ using namespace std; using namespace epics::pvData; namespace epics { - namespace pvAccess { +namespace pvAccess { - void addDefaultBroadcastAddress(InetAddrVector* v, unsigned short p) { - osiSockAddr pNewNode; - pNewNode.ia.sin_family = AF_INET; - pNewNode.ia.sin_addr.s_addr = htonl(INADDR_BROADCAST); - pNewNode.ia.sin_port = htons(p); - v->push_back(pNewNode); - } - - InetAddrVector* getBroadcastAddresses(SOCKET sock, - unsigned short defaultPort) { - ELLLIST as; - ellInit(&as); - osiSockAddr serverAddr; - memset(&serverAddr, 0, sizeof(osiSockAddr)); - InetAddrVector * v = new InetAddrVector; - osiSockDiscoverBroadcastAddresses(&as, sock, &serverAddr); - for(ELLNODE * n = ellFirst(&as); n != NULL; n = ellNext(n)) - { - osiSockAddrNode * sn = (osiSockAddrNode *)n; - sn->addr.ia.sin_port = htons(defaultPort); - v->push_back(sn->addr); - } - ellFree(&as); - return v; - } - - void encodeAsIPv6Address(ByteBuffer* buffer, const osiSockAddr* address) { - // IPv4 compatible IPv6 address - // first 80-bit are 0 - buffer->putLong(0); - buffer->putShort(0); - // next 16-bits are 1 - buffer->putShort(0xFFFF); - // following IPv4 address in big-endian (network) byte order - uint32_t ipv4Addr = ntohl(address->ia.sin_addr.s_addr); - buffer->putByte((int8)((ipv4Addr>>24)&0xFF)); - buffer->putByte((int8)((ipv4Addr>>16)&0xFF)); - buffer->putByte((int8)((ipv4Addr>>8)&0xFF)); - buffer->putByte((int8)(ipv4Addr&0xFF)); - } - - osiSockAddr* intToIPv4Address(int32 addr) { - osiSockAddr* ret = new osiSockAddr; - ret->ia.sin_family = AF_INET; - ret->ia.sin_addr.s_addr = htonl(addr); - ret->ia.sin_port = 0; - - return ret; - } - - int32 ipv4AddressToInt(const osiSockAddr& addr) { - return (int32)ntohl(addr.ia.sin_addr.s_addr); - } - - int32 parseInetAddress(const String addr) { - int32 retAddr; - - size_t dot = addr.find('.'); - if(dot==String::npos) THROW_BASE_EXCEPTION("Not an IPv4 address."); - int byte = atoi(addr.substr(0, dot).c_str()); - if(byte<0||byte>255) THROW_BASE_EXCEPTION("Not an IPv4 address."); - retAddr = byte; - - int num = dot+1; - dot = addr.find('.', num); - if(dot==String::npos) THROW_BASE_EXCEPTION("Not an IPv4 address."); - byte = atoi(addr.substr(num, dot-num).c_str()); - if(byte<0||byte>255) THROW_BASE_EXCEPTION("Not an IPv4 address."); - retAddr <<= 8; - retAddr |= byte; - - num = dot+1; - dot = addr.find('.', num); - if(dot==String::npos) THROW_BASE_EXCEPTION("Not an IPv4 address."); - byte = atoi(addr.substr(num, dot-num).c_str()); - if(byte<0||byte>255) THROW_BASE_EXCEPTION("Not an IPv4 address."); - retAddr <<= 8; - retAddr |= byte; - - num = dot+1; - byte = atoi(addr.substr(num).c_str()); - if(byte<0||byte>255) THROW_BASE_EXCEPTION("Not an IPv4 address."); - retAddr <<= 8; - retAddr |= byte; - - return htonl(retAddr); - } - - InetAddrVector* getSocketAddressList(String list, int defaultPort, - const InetAddrVector* appendList) { - InetAddrVector* iav = new InetAddrVector(); - - // parse string - size_t subStart = 0; - size_t subEnd; - while((subEnd = list.find(' ', subStart))!=String::npos) { - String address = list.substr(subStart, (subEnd-subStart)); - osiSockAddr addr; - aToIPAddr(address.c_str(), defaultPort, &addr.ia); - iav->push_back(addr); - subStart = list.find_first_not_of(" \t\r\n\v", subEnd); - } - - if(subStart!=String::npos&&list.length()>0) { - osiSockAddr addr; - aToIPAddr(list.substr(subStart).c_str(), defaultPort, &addr.ia); - iav->push_back(addr); - } - - if(appendList!=NULL) { - for(size_t i = 0; isize(); i++) - iav->push_back(appendList->at(i)); - } - return iav; - } - - const String inetAddressToString(const osiSockAddr &addr, - bool displayPort, bool displayHex) { - stringstream saddr; - - int ipa = ntohl(addr.ia.sin_addr.s_addr); - - saddr<<((int)(ipa>>24)&0xFF)<<'.'; - saddr<<((int)(ipa>>16)&0xFF)<<'.'; - saddr<<((int)(ipa>>8)&0xFF)<<'.'; - saddr<<((int)ipa&0xFF); - if(displayPort) saddr<<":"<push_back(pNewNode); +} + +InetAddrVector* getBroadcastAddresses(SOCKET sock, + unsigned short defaultPort) { + ELLLIST as; + ellInit(&as); + osiSockAddr serverAddr; + memset(&serverAddr, 0, sizeof(osiSockAddr)); + InetAddrVector * v = new InetAddrVector; + osiSockDiscoverBroadcastAddresses(&as, sock, &serverAddr); + for(ELLNODE * n = ellFirst(&as); n != NULL; n = ellNext(n)) + { + osiSockAddrNode * sn = (osiSockAddrNode *)n; + sn->addr.ia.sin_port = htons(defaultPort); + v->push_back(sn->addr); + } + ellFree(&as); + return v; +} + +void encodeAsIPv6Address(ByteBuffer* buffer, const osiSockAddr* address) { + // IPv4 compatible IPv6 address + // first 80-bit are 0 + buffer->putLong(0); + buffer->putShort(0); + // next 16-bits are 1 + buffer->putShort(0xFFFF); + // following IPv4 address in big-endian (network) byte order + uint32_t ipv4Addr = ntohl(address->ia.sin_addr.s_addr); + buffer->putByte((int8)((ipv4Addr>>24)&0xFF)); + buffer->putByte((int8)((ipv4Addr>>16)&0xFF)); + buffer->putByte((int8)((ipv4Addr>>8)&0xFF)); + buffer->putByte((int8)(ipv4Addr&0xFF)); +} + +osiSockAddr* intToIPv4Address(int32 addr) { + osiSockAddr* ret = new osiSockAddr; + ret->ia.sin_family = AF_INET; + ret->ia.sin_addr.s_addr = htonl(addr); + ret->ia.sin_port = 0; + + return ret; +} + +int32 ipv4AddressToInt(const osiSockAddr& addr) { + return (int32)ntohl(addr.ia.sin_addr.s_addr); +} + +int32 parseInetAddress(const String addr) { + int32 retAddr; + + size_t dot = addr.find('.'); + if(dot==String::npos) THROW_BASE_EXCEPTION("Not an IPv4 address."); + int byte = atoi(addr.substr(0, dot).c_str()); + if(byte<0||byte>255) THROW_BASE_EXCEPTION("Not an IPv4 address."); + retAddr = byte; + + int num = dot+1; + dot = addr.find('.', num); + if(dot==String::npos) THROW_BASE_EXCEPTION("Not an IPv4 address."); + byte = atoi(addr.substr(num, dot-num).c_str()); + if(byte<0||byte>255) THROW_BASE_EXCEPTION("Not an IPv4 address."); + retAddr <<= 8; + retAddr |= byte; + + num = dot+1; + dot = addr.find('.', num); + if(dot==String::npos) THROW_BASE_EXCEPTION("Not an IPv4 address."); + byte = atoi(addr.substr(num, dot-num).c_str()); + if(byte<0||byte>255) THROW_BASE_EXCEPTION("Not an IPv4 address."); + retAddr <<= 8; + retAddr |= byte; + + num = dot+1; + byte = atoi(addr.substr(num).c_str()); + if(byte<0||byte>255) THROW_BASE_EXCEPTION("Not an IPv4 address."); + retAddr <<= 8; + retAddr |= byte; + + return htonl(retAddr); +} + +InetAddrVector* getSocketAddressList(String list, int defaultPort, + const InetAddrVector* appendList) { + InetAddrVector* iav = new InetAddrVector(); + + // parse string + size_t subStart = 0; + size_t subEnd; + while((subEnd = list.find(' ', subStart))!=String::npos) { + String address = list.substr(subStart, (subEnd-subStart)); + osiSockAddr addr; + aToIPAddr(address.c_str(), defaultPort, &addr.ia); + iav->push_back(addr); + subStart = list.find_first_not_of(" \t\r\n\v", subEnd); + } + + if(subStart!=String::npos&&list.length()>0) { + osiSockAddr addr; + aToIPAddr(list.substr(subStart).c_str(), defaultPort, &addr.ia); + iav->push_back(addr); + } + + if(appendList!=NULL) { + for(size_t i = 0; isize(); i++) + iav->push_back(appendList->at(i)); + } + return iav; +} + +const String inetAddressToString(const osiSockAddr &addr, + bool displayPort, bool displayHex) { + stringstream saddr; + + int ipa = ntohl(addr.ia.sin_addr.s_addr); + + saddr<<((int)(ipa>>24)&0xFF)<<'.'; + saddr<<((int)(ipa>>16)&0xFF)<<'.'; + saddr<<((int)(ipa>>8)&0xFF)<<'.'; + saddr<<((int)ipa&0xFF); + if(displayPort) saddr<<":"< #include + #include #include namespace epics { - namespace pvAccess { +namespace pvAccess { - typedef std::vector InetAddrVector; + typedef std::vector InetAddrVector; - /** - * returns a vector containing all the IPv4 broadcast addresses - * on this machine. IPv6 doesn't have a local broadcast address. - * Conversion of the defaultPort to network byte order performed by - * the function. - */ - InetAddrVector* getBroadcastAddresses(SOCKET sock, - unsigned short defaultPort); + /** + * Returns a vector containing all the IPv4 broadcast addresses on this machine. + * IPv6 doesn't have a local broadcast address. + * Conversion of the defaultPort to network byte order performed by + * the function. + */ + InetAddrVector* getBroadcastAddresses(SOCKET sock, unsigned short defaultPort); - /** - * Encode IPv4 address as IPv6 address. - * @param buffer byte-buffer where to put encoded data. - * @param address address to encode. - */ - void - encodeAsIPv6Address(epics::pvData::ByteBuffer* buffer, const osiSockAddr* address); + /** + * Encode IPv4 address as IPv6 address. + * @param buffer byte-buffer where to put encoded data. + * @param address address to encode. + */ + void encodeAsIPv6Address(epics::pvData::ByteBuffer* buffer, const osiSockAddr* address); - /** - * Convert an integer into an IPv4 INET address. - * @param addr integer representation of a given address. - * @return IPv4 INET address. - */ - osiSockAddr* intToIPv4Address(epics::pvData::int32 addr); + /** + * Convert an integer into an IPv4 INET address. + * @param addr integer representation of a given address. + * @return IPv4 INET address. + */ + osiSockAddr* intToIPv4Address(epics::pvData::int32 addr); - /** - * Convert an IPv4 INET address to an integer. - * @param addr IPv4 INET address. - * @return integer representation of a given address. - */ - epics::pvData::int32 ipv4AddressToInt(const osiSockAddr& addr); + /** + * Convert an IPv4 INET address to an integer. + * @param addr IPv4 INET address. + * @return integer representation of a given address. + */ + epics::pvData::int32 ipv4AddressToInt(const osiSockAddr& addr); - /** - * Parse space delimited addresss[:port] string and return array of InetSocketAddress. - * @param list space delimited addresss[:port] string. - * @param defaultPort port take if not specified. - * @param appendList list to be appended. - * @return array of InetSocketAddress. - */ - InetAddrVector* getSocketAddressList(epics::pvData::String list, int defaultPort, - const InetAddrVector* appendList = NULL); + /** + * Parse space delimited addresss[:port] string and return array of InetSocketAddress. + * @param list space delimited addresss[:port] string. + * @param defaultPort port take if not specified. + * @param appendList list to be appended. + * @return array of InetSocketAddress. + */ + InetAddrVector* getSocketAddressList(epics::pvData::String list, int defaultPort, + const InetAddrVector* appendList = NULL); - const epics::pvData::String inetAddressToString(const osiSockAddr &addr, - bool displayPort = true, bool displayHex = false); + const epics::pvData::String inetAddressToString(const osiSockAddr &addr, + bool displayPort = true, bool displayHex = false); - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - /** - * comparators for osiSockAddr - */ - struct comp_osiSockAddrPtr { - bool operator()(osiSockAddr const *a, osiSockAddr const *b) { - if(a->sa.sa_familysa.sa_family) return true; - if((a->sa.sa_family==b->sa.sa_family)&&(a->ia.sin_addr.s_addr - ia.sin_addr.s_addr)) return true; - if((a->sa.sa_family==b->sa.sa_family)&&(a->ia.sin_addr.s_addr - ==b->ia.sin_addr.s_addr)&&(a->ia.sin_port - ia.sin_port)) return true; - return false; - } - }; + // comparators for osiSockAddr - struct comp_osiSock_lt { - bool operator()(const osiSockAddr& a, const osiSockAddr& b) { - if(a.sa.sa_familysa.sa_familysa.sa_family) return true; + if((a->sa.sa_family==b->sa.sa_family)&&(a->ia.sin_addr.s_addr + ia.sin_addr.s_addr)) return true; + if((a->sa.sa_family==b->sa.sa_family)&&(a->ia.sin_addr.s_addr + ==b->ia.sin_addr.s_addr)&&(a->ia.sin_port + ia.sin_port)) return true; + return false; + } + }; - //TODO if unordered map is used instead of map we can use sockAddrAreIdentical routine from osiSock.h - struct comp_osiSockAddr { - bool operator()(osiSockAddr const a, osiSockAddr const b) { - if(a.sa.sa_family @@ -9,7 +11,8 @@ using namespace epics::pvData; using namespace std; using std::tr1::static_pointer_cast; -namespace epics { namespace pvAccess { +namespace epics { +namespace pvAccess { const int8 IntrospectionRegistry::NULL_TYPE_CODE = (int8)-1; const int8 IntrospectionRegistry::ONLY_ID_TYPE_CODE = (int8)-2; @@ -176,7 +179,7 @@ void IntrospectionRegistry::serialize(FieldConstPtr field, StructureConstPtr par { case epics::pvData::scalar: { - ScalarConstPtr scalar = static_pointer_cast(field); + ScalarConstPtr scalar = static_pointer_cast(field); control->ensureBuffer(1); buffer->putByte((int8)(epics::pvData::scalar << 4 | scalar->getScalarType())); SerializeHelper::serializeString(field->getFieldName(), buffer, control); @@ -184,7 +187,7 @@ void IntrospectionRegistry::serialize(FieldConstPtr field, StructureConstPtr par } case epics::pvData::scalarArray: { - ScalarArrayConstPtr array = static_pointer_cast(field); + ScalarArrayConstPtr array = static_pointer_cast(field); control->ensureBuffer(1); buffer->putByte((int8)(epics::pvData::scalarArray << 4 | array->getElementType())); SerializeHelper::serializeString(field->getFieldName(), buffer, control); @@ -192,7 +195,7 @@ void IntrospectionRegistry::serialize(FieldConstPtr field, StructureConstPtr par } case epics::pvData::structure: { - StructureConstPtr structure = static_pointer_cast(field); + StructureConstPtr structure = static_pointer_cast(field); control->ensureBuffer(1); buffer->putByte((int8)(epics::pvData::structure << 4)); serializeStructureField(buffer, control, registry, structure); @@ -200,12 +203,12 @@ void IntrospectionRegistry::serialize(FieldConstPtr field, StructureConstPtr par } case epics::pvData::structureArray: { - StructureArrayConstPtr structureArray = static_pointer_cast(field); + StructureArrayConstPtr structureArray = static_pointer_cast(field); control->ensureBuffer(1); buffer->putByte((int8)(epics::pvData::structureArray << 4)); SerializeHelper::serializeString(field->getFieldName(), buffer, control); // we also need to serialize structure field... - StructureConstPtr structureElement = structureArray->getStructure(); + StructureConstPtr structureElement = structureArray->getStructure(); serializeStructureField(buffer, control, registry, structureElement); break; } @@ -281,7 +284,7 @@ FieldConstPtr IntrospectionRegistry::deserialize(ByteBuffer* buffer, Deserializa default: { // TODO log - return FieldConstPtr(); + return FieldConstPtr(); } } } diff --git a/pvAccessApp/utils/introspectionRegistry.h b/pvAccessApp/utils/introspectionRegistry.h index 097fee2..1508627 100644 --- a/pvAccessApp/utils/introspectionRegistry.h +++ b/pvAccessApp/utils/introspectionRegistry.h @@ -1,5 +1,7 @@ -/* - * introspectionRegistry.h +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ #ifndef INTROSPECTIONREGISTRY_H @@ -14,8 +16,6 @@ #include #include -#include - #include #include @@ -30,7 +30,8 @@ using epics::pvData::PVStructurePtr; using std::string; using epics::pvData::int8; -namespace epics { namespace pvAccess { +namespace epics { +namespace pvAccess { typedef std::map registryMap_t; diff --git a/pvAccessApp/utils/logger.cpp b/pvAccessApp/utils/logger.cpp index 0b0ef7e..879195f 100644 --- a/pvAccessApp/utils/logger.cpp +++ b/pvAccessApp/utils/logger.cpp @@ -1,8 +1,7 @@ -/* - * logger.cpp - * - * Created on: Dec 10, 2010 - * Author: Miha Vitorovic +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ #include @@ -33,7 +32,7 @@ namespace epics { #define TIMETEXTLEN 32 - static pvAccessLogLevel g_pvAccessLogLevel = logLevelDebug; //logLevelInfo; + static pvAccessLogLevel g_pvAccessLogLevel = logLevelInfo; void pvAccessLog(pvAccessLogLevel level, const char* format, ...) { diff --git a/pvAccessApp/utils/logger.h b/pvAccessApp/utils/logger.h index 4a74b47..18c5c3e 100644 --- a/pvAccessApp/utils/logger.h +++ b/pvAccessApp/utils/logger.h @@ -1,8 +1,7 @@ -/* - * logger.h - * - * Created on: Dec 10, 2010 - * Author: Miha Vitorovic +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ #ifndef LOGGER_H_ @@ -13,55 +12,55 @@ #include namespace epics { - namespace pvAccess { +namespace pvAccess { - typedef enum { logLevelAll = 0, logLevelTrace, logLevelDebug, logLevelInfo, - logLevelWarn, logLevelError, logLevelFatal, logLevelOff } pvAccessLogLevel; - /* - ALL - The ALL has the lowest possible rank and is intended to turn on all logging. - TRACE - The TRACE Level designates finer-grained informational events than the DEBUG - DEBUG - The DEBUG Level designates fine-grained informational events that are most useful to debug an application. - INFO - The INFO level designates informational messages that highlight the progress of the application at coarse-grained level. - WARN - The WARN level designates potentially harmful situations. - ERROR - The ERROR level designates error events that might still allow the application to continue running. - FATAL - The FATAL level designates very severe error events that will presumably lead the application to abort. - OFF - The OFF has the highest possible rank and is intended to turn off logging. + typedef enum { logLevelAll = 0, logLevelTrace, logLevelDebug, logLevelInfo, + logLevelWarn, logLevelError, logLevelFatal, logLevelOff } pvAccessLogLevel; + /* + ALL + The ALL has the lowest possible rank and is intended to turn on all logging. + TRACE + The TRACE Level designates finer-grained informational events than the DEBUG + DEBUG + The DEBUG Level designates fine-grained informational events that are most useful to debug an application. + INFO + The INFO level designates informational messages that highlight the progress of the application at coarse-grained level. + WARN + The WARN level designates potentially harmful situations. + ERROR + The ERROR level designates error events that might still allow the application to continue running. + FATAL + The FATAL level designates very severe error events that will presumably lead the application to abort. + OFF + The OFF has the highest possible rank and is intended to turn off logging. + */ + + + void pvAccessLog(pvAccessLogLevel level, const char* format, ...); + void pvAccessSetLogLevel(pvAccessLogLevel level); + + #define LOG(level, format, ...) pvAccessLog(level, format, ##__VA_ARGS__) + #define SET_LOG_LEVEL(level) pvAccessSetLogLevel(level) + + // EPICS errlog + //#define LOG errlogSevPrintf + //#define SET_LOG_LEVEL(level) errlogSetSevToLog(level) + + // none + //#define LOG(level, fmt, ...) + //#define SET_LOG_LEVEL(level) + + /** + * Create a logger that will write to file indicated by the fname. + * After creation you are free to use standard EPICSv3 functions from + * errlog.h. + * + * @param[in] fname The file to write to. If the file exists, it + * is opened for append. */ + void createFileLogger( epics::pvData::String fname ); - - void pvAccessLog(pvAccessLogLevel level, const char* format, ...); - void pvAccessSetLogLevel(pvAccessLogLevel level); - - #define LOG(level, format, ...) pvAccessLog(level, format, ##__VA_ARGS__) - #define SET_LOG_LEVEL(level) pvAccessSetLogLevel(level) - - // EPICS errlog - //#define LOG errlogSevPrintf - //#define SET_LOG_LEVEL(level) errlogSetSevToLog(level) - - // none - //#define LOG(level, fmt, ...) - //#define SET_LOG_LEVEL(level) - - /** - * Create a logger that will write to file indicated by the fname. - * After creation you are free to use standard EPICSv3 functions from - * errlog.h. - * - * @param[in] fname The file to write to. If the file exists, it - * is opened for append. - */ - void createFileLogger( epics::pvData::String fname ); - - } +} } #endif /* LOGGER_H_ */ diff --git a/pvAccessApp/utils/namedLockPattern.h b/pvAccessApp/utils/namedLockPattern.h index 1f703ac..5de14db 100644 --- a/pvAccessApp/utils/namedLockPattern.h +++ b/pvAccessApp/utils/namedLockPattern.h @@ -1,5 +1,7 @@ -/* - * namedLockPattern.h +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ #ifndef NAMEDLOCKPATTERN_H diff --git a/pvAccessApp/utils/referenceCountingLock.cpp b/pvAccessApp/utils/referenceCountingLock.cpp index 32889ca..e59f55b 100644 --- a/pvAccessApp/utils/referenceCountingLock.cpp +++ b/pvAccessApp/utils/referenceCountingLock.cpp @@ -1,10 +1,13 @@ -/* - * namedLockPattern.cpp +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ #include -namespace epics { namespace pvAccess { +namespace epics { +namespace pvAccess { using namespace epics::pvData; @@ -77,6 +80,7 @@ void ReferenceCountingLock::release() }*/ } +// TODO use atomic primitive impl. int ReferenceCountingLock::increment() { Lock guard(_countMutex); diff --git a/pvAccessApp/utils/referenceCountingLock.h b/pvAccessApp/utils/referenceCountingLock.h index 4725ace..0a15298 100644 --- a/pvAccessApp/utils/referenceCountingLock.h +++ b/pvAccessApp/utils/referenceCountingLock.h @@ -1,14 +1,17 @@ -/* - * referenceCountingLock.h +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ - + #ifndef REFERENCECOUNTINGLOCK_H #define REFERENCECOUNTINGLOCK_H #include #include -namespace epics { namespace pvAccess { +namespace epics { +namespace pvAccess { /** * Reference counting mutex implementation w/ deadlock detection. diff --git a/pvAccessApp/utils/transportRegistry.cpp b/pvAccessApp/utils/transportRegistry.cpp index 24f6523..df668fc 100644 --- a/pvAccessApp/utils/transportRegistry.cpp +++ b/pvAccessApp/utils/transportRegistry.cpp @@ -1,5 +1,7 @@ -/* - * transportRegistry.cpp +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ #include @@ -7,7 +9,8 @@ using namespace epics::pvData; using namespace std; -namespace epics { namespace pvAccess { +namespace epics { +namespace pvAccess { TransportRegistry::TransportRegistry(): _transports(), _transportCount(0), _mutex() { diff --git a/pvAccessApp/utils/transportRegistry.h b/pvAccessApp/utils/transportRegistry.h index e7bc364..d13ba6d 100644 --- a/pvAccessApp/utils/transportRegistry.h +++ b/pvAccessApp/utils/transportRegistry.h @@ -1,7 +1,9 @@ -/* - * transportRegistry.h +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ - + #ifndef TRANSPORTREGISTRY_H #define TRANSPORTREGISTRY_H @@ -18,7 +20,8 @@ #include #include -namespace epics { namespace pvAccess { +namespace epics { +namespace pvAccess { class TransportRegistry { public: diff --git a/pvAccessApp/utils/wildcharMatcher.cpp b/pvAccessApp/utils/wildcharMatcher.cpp index 67d8949..95bfa49 100644 --- a/pvAccessApp/utils/wildcharMatcher.cpp +++ b/pvAccessApp/utils/wildcharMatcher.cpp @@ -1,10 +1,9 @@ -/* - * wildcharMatcher.cpp - * - * Created on: Nov 4, 2010 - * Author: Miha Vitorovic +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ - + #include #include @@ -13,7 +12,7 @@ using std::cout; using namespace epics::pvData; namespace epics { - namespace pvAccess { +namespace pvAccess { /** Wildchar matcher debug */ const bool WCM_DEBUG = false; @@ -269,5 +268,5 @@ namespace epics { return parse(pattern, 0, str, 0); } - } +} } diff --git a/pvAccessApp/utils/wildcharMatcher.h b/pvAccessApp/utils/wildcharMatcher.h index 0d63b84..ed856c2 100644 --- a/pvAccessApp/utils/wildcharMatcher.h +++ b/pvAccessApp/utils/wildcharMatcher.h @@ -1,8 +1,7 @@ -/* - * wildcharMatcher.h - * - * Created on: Nov 4, 2010 - * Author: Miha Vitorovic +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvAccessCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. */ #ifndef WILDCHARMATCHER_H_ @@ -11,7 +10,7 @@ #include namespace epics { - namespace pvAccess { +namespace pvAccess { /** * DFA for parsing set strings. DFA was obtained from JFlex using the rule @@ -56,7 +55,7 @@ namespace epics { */ bool match(const epics::pvData::String pattern, const epics::pvData::String str); - } +} } #endif /* WILDCHARMATCHER_H_ */