Initial contribution
This commit is contained in:
parent
7b5cc4fa59
commit
11d9ce37aa
580 changed files with 155133 additions and 162 deletions
24
src/tools/CMakeLists.txt
Normal file
24
src/tools/CMakeLists.txt
Normal file
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
#
|
||||
# This program and the accompanying materials are made available under the
|
||||
# terms of the Eclipse Public License v. 2.0 which is available at
|
||||
# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
# v. 1.0 which is available at
|
||||
# http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
#
|
||||
set(CMAKE_INSTALL_TOOLSDIR "${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/tools")
|
||||
add_subdirectory(pubsub)
|
||||
add_subdirectory(config)
|
||||
add_subdirectory(ddsls)
|
||||
|
||||
# VxWorks build machines use OpenJDK 8, which lack jfxrt.jar. Do not build launcher on that platform.
|
||||
#
|
||||
# TODO Instead of making inclusion dependent on platform name, the condition should instead be on the
|
||||
# jdk vendor (Oracle JDK, not OpenJDK). Find a way to make CMake aware of jdk vendor.
|
||||
#option(BUILD_LAUNCHER "Enable building of launcher." ON)
|
||||
#if(NOT CMAKE_SYSTEM_NAME STREQUAL "VxWorks" AND BUILD_LAUNCHER)
|
||||
# add_subdirectory(launcher)
|
||||
#endif()
|
33
src/tools/config/CMakeLists.txt
Normal file
33
src/tools/config/CMakeLists.txt
Normal file
|
@ -0,0 +1,33 @@
|
|||
#
|
||||
# Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
#
|
||||
# This program and the accompanying materials are made available under the
|
||||
# terms of the Eclipse Public License v. 2.0 which is available at
|
||||
# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
# v. 1.0 which is available at
|
||||
# http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
#
|
||||
find_package(Java 1.8 REQUIRED)
|
||||
include(UseJava)
|
||||
set(CONFJAR_TARGET "${CMAKE_PROJECT_NAME_SMALL}conf")
|
||||
|
||||
set(CMAKE_JAVA_COMPILE_FLAGS "-source" "1.8" "-target" "1.8")
|
||||
|
||||
# Oddly enough, add_jar can't deal with a resource having an absolute path (experienced on Windows), so
|
||||
# generate into the list-dir.
|
||||
configure_file("metaconfig.xml.in" "${CMAKE_CURRENT_LIST_DIR}/metaconfig.xml" @ONLY)
|
||||
|
||||
file(GLOB_RECURSE JAVA_SOURCES LIST_DIRECTORIES true *.java)
|
||||
|
||||
set(RESOURCES metaconfig.xml metaconfig.xsd resources/ptlogoc16.png resources/ptlogoc24.png resources/ptlogoc32.png resources/ptlogoc48.png)
|
||||
add_jar(${CONFJAR_TARGET} ${JAVA_SOURCES} ${RESOURCES} ENTRY_POINT org.eclipse.cyclonedds.config.SpliceConfig)
|
||||
|
||||
#add_test(NAME TestHelloWorld COMMAND ${Java_JAVA_EXECUTABLE} -cp ${_jarFile} HelloWorld)
|
||||
|
||||
install(
|
||||
FILES "${CMAKE_CURRENT_BINARY_DIR}/${CONFJAR_TARGET}.jar"
|
||||
DESTINATION "${CMAKE_INSTALL_TOOLSDIR}"
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
|
||||
COMPONENT dev)
|
1160
src/tools/config/metaconfig.xml.in
Normal file
1160
src/tools/config/metaconfig.xml.in
Normal file
File diff suppressed because it is too large
Load diff
289
src/tools/config/metaconfig.xsd
Normal file
289
src/tools/config/metaconfig.xsd
Normal file
|
@ -0,0 +1,289 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
|
||||
This program and the accompanying materials are made available under the
|
||||
terms of the Eclipse Public License v. 2.0 which is available at
|
||||
http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
v. 1.0 which is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
-->
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
|
||||
<xs:element name="attributeLong">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element minOccurs="0" name="minimum" type="xs:long"/>
|
||||
<xs:element minOccurs="0" name="maximum" type="xs:long"/>
|
||||
<xs:element name="default" type="xs:long"/>
|
||||
</xs:all>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="required" type="xs:boolean" use="required"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="attributeSize">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element minOccurs="0" name="minimum" type="xs:string"/>
|
||||
<xs:element minOccurs="0" name="maximum" type="xs:string"/>
|
||||
<xs:element name="default" type="xs:string"/>
|
||||
</xs:all>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="required" type="xs:boolean" use="required"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="attributeString">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element name="maxLength" type="xs:unsignedInt"/>
|
||||
<xs:element name="default" type="xs:string"/>
|
||||
</xs:all>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="required" type="xs:boolean" use="required"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="attributeBoolean">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element name="default" type="xs:boolean"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="attributeEnum">
|
||||
<xs:complexType>
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element maxOccurs="unbounded" name="value" type="xs:string"/>
|
||||
<xs:element name="default" type="xs:string"/>
|
||||
</xs:choice>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="attributeDouble">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element minOccurs="0" name="minimum" type="xs:double"/>
|
||||
<xs:element minOccurs="0" name="maximum" type="xs:double"/>
|
||||
<xs:element name="default" type="xs:double"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="attributeFloat">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element minOccurs="0" name="minimum" type="xs:float"/>
|
||||
<xs:element minOccurs="0" name="maximum" type="xs:float"/>
|
||||
<xs:element name="default" type="xs:float"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="attributeInt">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element minOccurs="0" name="minimum" type="xs:int"/>
|
||||
<xs:element minOccurs="0" name="maximum" type="xs:int"/>
|
||||
<xs:element name="default" type="xs:int"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="comment" type="xs:string"/>
|
||||
<xs:element name="element">
|
||||
<xs:complexType>
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element ref="attributeString"/>
|
||||
<xs:element ref="leafSize"/>
|
||||
<xs:element ref="leafEmpty"/>
|
||||
<xs:element ref="leafString"/>
|
||||
<xs:element ref="leafEnum"/>
|
||||
<xs:element ref="leafBoolean"/>
|
||||
<xs:element ref="leafInt"/>
|
||||
<xs:element ref="element"/>
|
||||
<xs:element ref="leafFloat"/>
|
||||
</xs:choice>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="minOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
<xs:attribute name="maxOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="leafBoolean">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element name="default" type="xs:boolean"/>
|
||||
</xs:all>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="minOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
<xs:attribute name="maxOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="leafEmpty">
|
||||
<xs:complexType>
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element ref="attributeLong"/>
|
||||
<xs:element ref="attributeString"/>
|
||||
<xs:element ref="attributeBoolean"/>
|
||||
<xs:element ref="attributeDouble"/>
|
||||
<xs:element ref="attributeEnum"/>
|
||||
<xs:element ref="attributeFloat"/>
|
||||
<xs:element ref="attributeInt"/>
|
||||
<xs:element ref="attributeSize"/>
|
||||
</xs:choice>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="minOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
<xs:attribute name="maxOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="leafEnum">
|
||||
<xs:complexType>
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element maxOccurs="unbounded" name="value" type="xs:string"/>
|
||||
<xs:element name="default" type="xs:string"/>
|
||||
</xs:choice>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="minOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
<xs:attribute name="maxOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="leafFloat">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element minOccurs="0" name="minimum" type="xs:decimal"/>
|
||||
<xs:element minOccurs="0" name="maximum" type="xs:decimal"/>
|
||||
<xs:element name="default" type="xs:decimal"/>
|
||||
</xs:all>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="minOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
<xs:attribute name="maxOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="leafDouble">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element minOccurs="0" name="minimum" type="xs:double"/>
|
||||
<xs:element minOccurs="0" name="maximum" type="xs:double"/>
|
||||
<xs:element name="default" type="xs:double"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="leafLong">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element minOccurs="0" name="minimum" type="xs:long"/>
|
||||
<xs:element minOccurs="0" name="maximum" type="xs:long"/>
|
||||
<xs:element name="default" type="xs:long"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="leafSize">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element minOccurs="0" name="minimum" type="xs:string"/>
|
||||
<xs:element minOccurs="0" name="maximum" type="xs:string"/>
|
||||
<xs:element name="default" type="xs:string"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="leafInt">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element minOccurs="0" name="minimum" type="xs:unsignedInt"/>
|
||||
<xs:element minOccurs="0" name="maximum" type="xs:unsignedInt"/>
|
||||
<xs:element name="default" type="xs:unsignedInt"/>
|
||||
</xs:all>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="minOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
<xs:attribute name="maxOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="leafString">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element name="maxLength" type="xs:unsignedInt"/>
|
||||
<xs:element name="default" type="xs:string"/>
|
||||
</xs:all>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="minOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
<xs:attribute name="maxOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="rootElement">
|
||||
<xs:complexType>
|
||||
<xs:all minOccurs="1" maxOccurs="1">
|
||||
<xs:element ref="element"/>
|
||||
</xs:all>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="service">
|
||||
<xs:complexType>
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element ref="attributeLong"/>
|
||||
<xs:element ref="attributeString"/>
|
||||
<xs:element ref="leafInt"/>
|
||||
<xs:element ref="leafFloat"/>
|
||||
<xs:element ref="leafString"/>
|
||||
<xs:element ref="leafEnum"/>
|
||||
<xs:element ref="leafEmpty"/>
|
||||
<xs:element ref="leafSize"/>
|
||||
<xs:element ref="element"/>
|
||||
</xs:choice>
|
||||
<xs:attribute name="type" use="required">
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:NMTOKEN">
|
||||
<xs:enumeration value="CMSOAPService"/>
|
||||
<xs:enumeration value="DurabilityService"/>
|
||||
<xs:enumeration value="NetworkingService"/>
|
||||
<xs:enumeration value="SpliceService"/>
|
||||
<xs:enumeration value="UserClockService"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="minOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
<xs:attribute name="maxOccurrences" type="xs:unsignedInt" use="optional"/>
|
||||
<xs:attribute name="isRootService" type="xs:boolean"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="serviceCommon">
|
||||
<xs:complexType>
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element minOccurs="0" ref="comment"/>
|
||||
<xs:element ref="attributeLong"/>
|
||||
<xs:element ref="attributeString"/>
|
||||
<xs:element ref="leafInt"/>
|
||||
<xs:element ref="leafFloat"/>
|
||||
<xs:element ref="leafString"/>
|
||||
<xs:element ref="leafEnum"/>
|
||||
<xs:element ref="leafEmpty"/>
|
||||
<xs:element ref="leafSize"/>
|
||||
<xs:element ref="element"/>
|
||||
</xs:choice>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="splice_meta_config">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element ref="rootElement"/>
|
||||
<xs:element ref="serviceCommon"/>
|
||||
<xs:element maxOccurs="unbounded" ref="service"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="version" type="xs:decimal" use="required"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.common.controller;
|
||||
|
||||
/**
|
||||
* Represents a result for assignment of a value to a certain field.
|
||||
*
|
||||
* @date Nov 25, 2004
|
||||
*/
|
||||
public class AssignmentResult{
|
||||
private boolean valid;
|
||||
private String errorMessage;
|
||||
|
||||
/**
|
||||
* Constructs a new AssignMentResult.
|
||||
*
|
||||
* @param _success true if validation succeeded, false otherwise.
|
||||
* @param _errorMessage null when validation succeeded, the failure
|
||||
* reason otherwise.
|
||||
*/
|
||||
public AssignmentResult(boolean _success, String _errorMessage){
|
||||
valid = _success;
|
||||
errorMessage = _errorMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to errorMessage.
|
||||
*
|
||||
* @return Returns the errorMessage.
|
||||
*/
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
/**
|
||||
* Provides access to valid.
|
||||
*
|
||||
* @return Returns the valid.
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
}
|
551
src/tools/config/org/eclipse/cyclonedds/common/util/Config.java
Normal file
551
src/tools/config/org/eclipse/cyclonedds/common/util/Config.java
Normal file
|
@ -0,0 +1,551 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
/**
|
||||
* Contains all SPLICE DDS C&M Tooling utilities.
|
||||
*/
|
||||
package org.eclipse.cyclonedds.common.util;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.cyclonedds.common.view.CommonFileChooser;
|
||||
|
||||
/**
|
||||
* Supplies a generic configuration utility for all kinds of applications.
|
||||
* Before using the load or loadDefault function must be called.
|
||||
*
|
||||
* @date Oct 25, 2004
|
||||
*/
|
||||
public class Config {
|
||||
|
||||
/**
|
||||
* The current configuration.
|
||||
*/
|
||||
private Properties config = null;
|
||||
|
||||
/**
|
||||
* The location of the configuration.
|
||||
*/
|
||||
private File configFile = null;
|
||||
|
||||
/**
|
||||
* The validator.
|
||||
*/
|
||||
private ConfigValidator validator = null;
|
||||
|
||||
private CommonFileChooser chooser = null;
|
||||
|
||||
private static volatile Config instance = null;
|
||||
|
||||
private static Color warningColor = null;
|
||||
private static Color errorColor = null;
|
||||
private static Color sensitiveColor = null;
|
||||
private static Color inactiveColor = null;
|
||||
private static Color activeColor = null;
|
||||
private static Color inputColor = null;
|
||||
private static Color incorrectColor = null;
|
||||
|
||||
private Config(){}
|
||||
|
||||
public static Config getInstance(){
|
||||
if(instance == null){
|
||||
instance = new Config();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns the supplied validator to the configuration. It will use this
|
||||
* validator when calling: - load --> call validateValue on each found key.
|
||||
* - loadDefault --> call validateValue on each found key. - getProperty ->
|
||||
* call getDefaultValue when a supplied kay has no value. - setProperty -->
|
||||
* call isValueValid on the supplied key/value combination.
|
||||
*
|
||||
* @param _validator
|
||||
* The validator to assign.
|
||||
*/
|
||||
public void setValidator(ConfigValidator _validator){
|
||||
validator = _validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the current configuration validator.
|
||||
*
|
||||
* @return The current validator or null if none has been assigned.
|
||||
*/
|
||||
public ConfigValidator getValidator(){
|
||||
return validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the current configuration properties.
|
||||
*
|
||||
* @return The current config properties or null if none has been assigned.
|
||||
*/
|
||||
public Properties getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the release information from a file named RELEASEINFO located in
|
||||
* the etc directory of the installation.
|
||||
*
|
||||
* @return true if the release information could be loaded, false otherwise.
|
||||
*/
|
||||
public boolean loadReleaseInfo(){
|
||||
FileInputStream fis = null;
|
||||
if (config == null){
|
||||
config = new Properties ();
|
||||
}
|
||||
boolean result = true;
|
||||
String homeDir = System.getenv("OSPL_HOME");
|
||||
String separator = System.getProperty("file.separator");
|
||||
File releaseFile = new File (homeDir + separator + "etc" + separator + "RELEASEINFO");
|
||||
if(releaseFile.exists()) {
|
||||
try {
|
||||
fis = new FileInputStream(releaseFile);
|
||||
config.load(fis);
|
||||
} catch (FileNotFoundException e) {
|
||||
result = false;
|
||||
} catch (IOException e) {
|
||||
result = false;
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException ie) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we don't have a value for the version property then try
|
||||
// to load the value from the development tree RELEASE file
|
||||
String version = config.getProperty("PACKAGE_VERSION");
|
||||
if (version == null) {
|
||||
releaseFile = new File (homeDir + separator + "release_info" + separator + "RELEASE");
|
||||
if(releaseFile.exists()) {
|
||||
try {
|
||||
fis = new FileInputStream(releaseFile);
|
||||
config.load(fis);
|
||||
} catch (FileNotFoundException e) {
|
||||
result = false;
|
||||
} catch (IOException e) {
|
||||
result = false;
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException ie) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!result){
|
||||
config = null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the default configuration. This located in the home directory of
|
||||
* the user in the '.splice_tooling.properties' file.
|
||||
*
|
||||
* @return true if the default configuration could be loaded, false
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean loadDefault(){
|
||||
String key, value;
|
||||
boolean result = true;
|
||||
String homeDir = System.getProperty("user.home");
|
||||
String separator = System.getProperty("file.separator");
|
||||
config = new Properties();
|
||||
FileInputStream fis = null;
|
||||
|
||||
// Load the release information so that we have the PACKAGE_VERSION property.
|
||||
result = loadReleaseInfo();
|
||||
|
||||
if (result) {
|
||||
String version = config.getProperty("PACKAGE_VERSION");
|
||||
if (version != null) {
|
||||
version = version.replaceAll("\"", "");
|
||||
version = new String ("." + version);
|
||||
} else {
|
||||
version = new String ("");
|
||||
}
|
||||
configFile = new File(homeDir + separator + ".ospl_tooling.properties" + version);
|
||||
} else {
|
||||
configFile = new File(homeDir + separator + ".ospl_tooling.properties");
|
||||
// Reset the result flag.
|
||||
result = true;
|
||||
}
|
||||
|
||||
if(!(configFile.exists())) {
|
||||
try {
|
||||
configFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
result = false;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
fis = new FileInputStream(configFile);
|
||||
config.load(fis);
|
||||
Properties newConfig = new Properties(config);
|
||||
if(validator != null){
|
||||
Iterator<Object> iter = config.keySet().iterator();
|
||||
|
||||
while(iter.hasNext()){
|
||||
key = (String)iter.next();
|
||||
value = config.getProperty(key);
|
||||
value = validator.getValidatedValue(key, value);
|
||||
|
||||
if(value == null){
|
||||
newConfig.remove(key);
|
||||
} else {
|
||||
newConfig.setProperty(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
config = newConfig;
|
||||
} catch (FileNotFoundException e) {
|
||||
result = false;
|
||||
} catch (IOException e) {
|
||||
result = false;
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException ie) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!result){
|
||||
config = null;
|
||||
configFile = null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Loads the configuration from the supplied URI.
|
||||
*
|
||||
* @param uri
|
||||
* The URI to load the configuration from.
|
||||
* @return true if the configuration was successfully loaded, false
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean load(String uri) {
|
||||
String value;
|
||||
boolean result = false;
|
||||
FileInputStream fis = null;
|
||||
|
||||
try {
|
||||
uri = uri.replaceAll(" ", "%20");
|
||||
URI location = new URI(uri);
|
||||
configFile = new File(location);
|
||||
config = new Properties();
|
||||
fis = new FileInputStream(configFile);
|
||||
config.load(fis);
|
||||
Properties newConfig = new Properties();
|
||||
if(validator != null){
|
||||
|
||||
for (Object key : config.keySet()) {
|
||||
value = config.getProperty((String) key);
|
||||
value = validator.getValidatedValue((String) key, value);
|
||||
if (value != null) {
|
||||
newConfig.setProperty((String) key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
config.putAll(newConfig);
|
||||
result = true;
|
||||
} catch (FileNotFoundException e1) {
|
||||
Report.getInstance().writeErrorLog("Configuration file could not be found.");
|
||||
} catch (IOException e1) {
|
||||
Report.getInstance().writeErrorLog("Configuration file could not be read.");
|
||||
} catch (URISyntaxException e) {
|
||||
Report.getInstance().writeErrorLog("Supplied URI not valid.");
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException ie) {
|
||||
Report.getInstance().writeErrorLog("Configuration file could not be read.");
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the value of the supplied property.
|
||||
*
|
||||
* @param key
|
||||
* The name of the property.
|
||||
* @return The value of the property or null if it was not available.
|
||||
*/
|
||||
public String getProperty(String key){
|
||||
String result = null;
|
||||
|
||||
if(config != null){
|
||||
if(config.containsKey(key)){
|
||||
result = config.getProperty(key);
|
||||
} else if(validator != null){
|
||||
result = validator.getDefaultValue(key);
|
||||
|
||||
if(result != null){
|
||||
config.setProperty(key, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns the supplied value to the supplied property.
|
||||
*
|
||||
* @param key
|
||||
* The name of the property.
|
||||
* @param value
|
||||
* The value of the property.
|
||||
* @return true if it could be assigned, false otherwise.
|
||||
*/
|
||||
public boolean setProperty(String key, String value){
|
||||
boolean result = false;
|
||||
|
||||
if(config != null){
|
||||
if(validator != null){
|
||||
result = validator.isValueValid(key, value);
|
||||
|
||||
if(result){
|
||||
config.setProperty(key, value);
|
||||
this.store();
|
||||
}
|
||||
} else {
|
||||
config.setProperty(key, value);
|
||||
this.store();
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isPropertyValid(String key, String value){
|
||||
boolean result = false;
|
||||
|
||||
if((config != null) && (validator != null)){
|
||||
result = validator.isValueValid(key, value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the supplied property from the configuration.
|
||||
*
|
||||
* @param key
|
||||
* The name of the property to remove.
|
||||
* @return true if succeeded, false otherwise.
|
||||
*/
|
||||
public boolean removeProperty(String key){
|
||||
boolean result = false;
|
||||
|
||||
if(config != null){
|
||||
Object value = config.remove(key);
|
||||
|
||||
if(value != null){
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the configuration to screen.
|
||||
*/
|
||||
public void list(){
|
||||
if(config != null){
|
||||
config.list(System.out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the configuration to disk.
|
||||
*
|
||||
* @return true if succeeded, false otherwise.
|
||||
*/
|
||||
public boolean store(){
|
||||
boolean result = false;
|
||||
FileOutputStream fos = null;
|
||||
|
||||
if(config != null){
|
||||
try {
|
||||
fos = new FileOutputStream(configFile);
|
||||
config.store(fos, null);
|
||||
result = true;
|
||||
} catch (IOException e) {
|
||||
Report.getInstance().writeErrorLog("Configuration could not be saved.");
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (IOException ie) {
|
||||
Report.getInstance().writeErrorLog("Configuration could not be saved.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the configuration to the supplied uri.
|
||||
*
|
||||
* @return true if succeeded, false otherwise.
|
||||
*/
|
||||
public boolean store(String uri){
|
||||
boolean result = false;
|
||||
FileOutputStream fos = null;
|
||||
|
||||
if(config != null){
|
||||
try {
|
||||
Report.getInstance().writeInfoLog("Storing configuration to URI: " +
|
||||
configFile.toURI().getScheme() +
|
||||
configFile.toURI().getPath() + ".");
|
||||
uri = uri.replaceAll(" ", "%20");
|
||||
URI outURI = new URI(uri);
|
||||
File outFile = new File(outURI);
|
||||
boolean fileCreated = true;
|
||||
|
||||
if(!(outFile.exists())){
|
||||
fileCreated = outFile.createNewFile();
|
||||
}
|
||||
if (fileCreated) {
|
||||
fos = new FileOutputStream(outFile);
|
||||
config.store(fos, null);
|
||||
} else {
|
||||
Report.getInstance().writeErrorLog("Configuration could not be saved. file could not be created");
|
||||
result = false;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Report.getInstance().writeErrorLog("Configuration could not be saved.");
|
||||
} catch (URISyntaxException e) {
|
||||
Report.getInstance().writeErrorLog("Configuration could not be saved.");
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (IOException ie) {
|
||||
Report.getInstance().writeErrorLog("Configuration could not be saved.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public CommonFileChooser getFileChooser(){
|
||||
if(this.chooser == null){
|
||||
this.chooser = new CommonFileChooser(".");
|
||||
}
|
||||
return this.chooser;
|
||||
}
|
||||
|
||||
public static Color getErrorColor(){
|
||||
if(errorColor == null){
|
||||
int r = Integer.parseInt("a0", 16);
|
||||
int g = Integer.parseInt("20", 16);
|
||||
int b = Integer.parseInt("20", 16);
|
||||
|
||||
r = Integer.parseInt("ff", 16);
|
||||
g = Integer.parseInt("40", 16);
|
||||
b = Integer.parseInt("40", 16);
|
||||
|
||||
errorColor = new Color(r, g, b);
|
||||
}
|
||||
return errorColor;
|
||||
}
|
||||
|
||||
public static Color getWarningColor(){
|
||||
if(warningColor == null){
|
||||
int r = Integer.parseInt("c0", 16);
|
||||
int g = Integer.parseInt("80", 16);
|
||||
int b = Integer.parseInt("00", 16);
|
||||
warningColor = new Color(r, g, b);
|
||||
}
|
||||
return warningColor;
|
||||
}
|
||||
|
||||
public static Color getSensitiveColor(){
|
||||
if(sensitiveColor == null){
|
||||
int r = Integer.parseInt("70", 16);
|
||||
int g = Integer.parseInt("e0", 16);
|
||||
int b = Integer.parseInt("70", 16);
|
||||
sensitiveColor = new Color(r, g, b);
|
||||
}
|
||||
return sensitiveColor;
|
||||
}
|
||||
|
||||
public static Color getInactiveColor(){
|
||||
if(inactiveColor == null){
|
||||
int r = Integer.parseInt("70", 16);
|
||||
int g = Integer.parseInt("70", 16);
|
||||
int b = Integer.parseInt("7a", 16);
|
||||
inactiveColor = new Color(r, g, b);
|
||||
}
|
||||
return inactiveColor;
|
||||
}
|
||||
|
||||
public static Color getActiveColor(){
|
||||
if(activeColor == null){
|
||||
int r = Integer.parseInt("50", 16);
|
||||
int g = Integer.parseInt("90", 16);
|
||||
int b = Integer.parseInt("50", 16);
|
||||
activeColor = new Color(r, g, b);
|
||||
}
|
||||
return activeColor;
|
||||
}
|
||||
|
||||
public static Color getInputColor(){
|
||||
if(inputColor == null){
|
||||
int r = Integer.parseInt("f0", 16);
|
||||
int g = Integer.parseInt("90", 16);
|
||||
int b = Integer.parseInt("00", 16);
|
||||
inputColor = new Color(r, g, b);
|
||||
}
|
||||
return inputColor;
|
||||
}
|
||||
|
||||
public static Color getIncorrectColor(){
|
||||
if(incorrectColor == null){
|
||||
int r = Integer.parseInt("ff", 16);
|
||||
int g = Integer.parseInt("40", 16);
|
||||
int b = Integer.parseInt("40", 16);
|
||||
incorrectColor = new Color(r, g, b);
|
||||
}
|
||||
return incorrectColor;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.common.util;
|
||||
|
||||
public class ConfigModeIntializer {
|
||||
|
||||
public static final String COMMUNITY = "COMMUNITY";
|
||||
public static final String COMMERCIAL = "COMMERCIAL";
|
||||
public static final int COMMUNITY_MODE = 1;
|
||||
public static final int COMMERCIAL_MODE = 2;
|
||||
public static final int COMMUNITY_MODE_FILE_OPEN = 3;
|
||||
public static final int LITE_MODE = 4;
|
||||
public static int CONFIGURATOR_MODE = COMMERCIAL_MODE;
|
||||
|
||||
public static void setMode(int mode) {
|
||||
CONFIGURATOR_MODE = mode;
|
||||
}
|
||||
|
||||
public int getMode() {
|
||||
return CONFIGURATOR_MODE;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.common.util;
|
||||
|
||||
/**
|
||||
* Interface that provides routines for validating configuration.
|
||||
* Implementations of this interface can guarantee that the configuration for
|
||||
* an application will be correct.
|
||||
*
|
||||
* @date Jan 12, 2005
|
||||
*/
|
||||
public interface ConfigValidator {
|
||||
/**
|
||||
* Returns the correct value for the supplied key. This function
|
||||
* checks if the supplied value is valid. If so, return that value. If not
|
||||
* return a valid one. The Config component calls this routine for each
|
||||
* key it finds when loading a configuration file.
|
||||
*
|
||||
* @param key The key in the configuration.
|
||||
* @param value The value as it has been found in the confuration file.
|
||||
* @return A correct value for that key. If null is returned, the Config
|
||||
* component will remove the key from the configuration.
|
||||
*/
|
||||
public String getValidatedValue(String key, String value);
|
||||
|
||||
/**
|
||||
* Returns the default value for the supplied key. This function is called
|
||||
* by the Config component when an application asks for a property that has
|
||||
* not been defined.
|
||||
*
|
||||
* @param key The key where to resolve the default value of.
|
||||
* @return The default value for the supplied key.
|
||||
*/
|
||||
public String getDefaultValue(String key);
|
||||
|
||||
/**
|
||||
* Checks whether the supplied key/value combination is valid. The Config
|
||||
* component calls this function when an application sets a property in the
|
||||
* configuration.
|
||||
*
|
||||
* @param key The key of the property.
|
||||
* @param value The value of the property.
|
||||
* @return If the combination is valid; true and false otherwise.
|
||||
*/
|
||||
public boolean isValueValid(String key, String value);
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.common.util;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
/**
|
||||
* Base class for tooling initializers. Its responsibilities are to initialize
|
||||
* logging facilities according to commandline parameters and to validate
|
||||
* whether the correct Java Vitual Machine version is used.
|
||||
*
|
||||
* @date Sep 1, 2004
|
||||
*/
|
||||
public class Initializer {
|
||||
|
||||
/**
|
||||
* Initializes the application, using the configuration that is supplied as
|
||||
* argument. If the supplied file does not exist or no argument was
|
||||
* supplied, the default is used. The default is:
|
||||
* <USER_HOME>/.splice_tooling.properties.
|
||||
*
|
||||
* @param args
|
||||
* The list of arguments supplied by the user. Only the first
|
||||
* argument is used, the rest will be ignored. The first argument
|
||||
* must supply the location of a java properties file.
|
||||
*/
|
||||
public void initializeConfig(String[] args, ConfigValidator validator){
|
||||
boolean result = false;
|
||||
|
||||
Config.getInstance().setValidator(validator);
|
||||
|
||||
if(args.length > 0){
|
||||
Report.getInstance().writeInfoLog("Reading configuration from " + args[0] + ".");
|
||||
result = Config.getInstance().load(args[0]);
|
||||
|
||||
if(!result){
|
||||
Report.getInstance().writeInfoLog("Applying default configuration.");
|
||||
result = Config.getInstance().loadDefault();
|
||||
}
|
||||
}
|
||||
else{
|
||||
result = Config.getInstance().loadDefault();
|
||||
}
|
||||
|
||||
if(!result){
|
||||
Report.getInstance().writeInfoLog("Default configuration could not be read.");
|
||||
} else {
|
||||
String loggingFileName = Config.getInstance().getProperty("logging");
|
||||
|
||||
if(loggingFileName != null){
|
||||
FileInputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(loggingFileName);
|
||||
LogManager.getLogManager().readConfiguration(is);
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
Report.getInstance().writeInfoLog("Specified logging config file not found. Logging is disabled.");
|
||||
LogManager.getLogManager().reset();
|
||||
}
|
||||
catch (SecurityException e) {
|
||||
Report.getInstance().writeInfoLog("Specified logging config file not valid. Logging is disabled.");
|
||||
LogManager.getLogManager().reset();
|
||||
}
|
||||
catch (IOException e) {
|
||||
Report.getInstance().writeInfoLog("Specified logging config file not valid. Logging is disabled.");
|
||||
LogManager.getLogManager().reset();
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException ie) {
|
||||
Report.getInstance().writeInfoLog("Specified logging config file not valid. Logging is disabled.");
|
||||
LogManager.getLogManager().reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LogManager.getLogManager().reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates whether a compatible Java virtual machine is used.
|
||||
*
|
||||
* The version of Java must be >= 1.4 and should be >= 1.5.0. If the
|
||||
* used version is &st; 1.4, the application exits with an error message. If
|
||||
* 1.4 &st;= version &st; 1.5, false is returned, but the application
|
||||
* proceeds.
|
||||
*
|
||||
* @return true, if java version >= 1.5 and false otherwise.
|
||||
*/
|
||||
public boolean validateJVMVersion(){
|
||||
int token;
|
||||
boolean result = true;
|
||||
|
||||
String version = System.getProperty("java.version");
|
||||
StringTokenizer tokenizer = new StringTokenizer(version, ".");
|
||||
|
||||
if(tokenizer.hasMoreTokens()){
|
||||
token = Integer.parseInt(tokenizer.nextToken());
|
||||
|
||||
if(token < 1){
|
||||
this.printVersionErrorAndExit(version);
|
||||
}
|
||||
|
||||
if(tokenizer.hasMoreTokens()){
|
||||
token = Integer.parseInt(tokenizer.nextToken());
|
||||
|
||||
if(token < 4){
|
||||
this.printVersionErrorAndExit(version);
|
||||
} else if(token == 4){
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
this.printVersionErrorAndExit(version);
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
this.printVersionErrorAndExit(version);
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints JVM version demands as well as the used version and exits the
|
||||
* application.
|
||||
*/
|
||||
private void printVersionErrorAndExit(String version){
|
||||
System.err.println("Your Java version is '" + version + "', but version >= '1.4' is required.\nBailing out...");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a Java version warning.
|
||||
*
|
||||
* @param parent
|
||||
* The GUI parent which must be used as parent for displaying the
|
||||
* message. If the supplied component == null, the version
|
||||
* warning is displayed on standard out (System.out).
|
||||
*/
|
||||
public void showVersionWarning(Component parent){
|
||||
if(parent != null){
|
||||
JOptionPane.showMessageDialog(parent, "You are using Java version " + System.getProperty("java.version") + ",\nbut version >= 1.5.0 is recommended.", "Warning", JOptionPane.WARNING_MESSAGE);
|
||||
} else{
|
||||
System.err.println("You are using Java version " + System.getProperty("java.version")
|
||||
+ ",\nbut version >= 1.5.0 is recommended.");
|
||||
}
|
||||
}
|
||||
}
|
124
src/tools/config/org/eclipse/cyclonedds/common/util/Report.java
Normal file
124
src/tools/config/org/eclipse/cyclonedds/common/util/Report.java
Normal file
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.common.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogManager;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.SimpleFormatter;
|
||||
|
||||
public class Report {
|
||||
|
||||
private static Report reportObject = new Report();
|
||||
static Logger errorLog;
|
||||
static Logger infoLog;
|
||||
|
||||
private String errorLogFile = null;
|
||||
private int errorSize = 0;
|
||||
private int errorCount = 0;
|
||||
private boolean errorAppend = false;
|
||||
|
||||
private String infoLogFile = null;
|
||||
private int infoSize = 0;
|
||||
private int infoCount = 0;
|
||||
private boolean infoAppend = false;
|
||||
|
||||
private Handler errorHandler;
|
||||
private Handler infoHandler;
|
||||
|
||||
private boolean consoleOutput = false;
|
||||
|
||||
/**
|
||||
* A private Constructor prevents any other class from instantiating.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Report() {
|
||||
errorLog = Logger.getAnonymousLogger();
|
||||
infoLog = Logger.getAnonymousLogger();
|
||||
}
|
||||
|
||||
public static Report getInstance() {
|
||||
return reportObject;
|
||||
}
|
||||
|
||||
public void initializeInfo(String infoLogFile, int size, int nrOfLogFiles, boolean append) {
|
||||
this.infoLogFile = infoLogFile;
|
||||
this.infoSize = size;
|
||||
this.infoCount = nrOfLogFiles;
|
||||
this.infoAppend = append;
|
||||
}
|
||||
|
||||
public void initializeError(String errorLogFile, int size, int nrOfLogFiles, boolean append) {
|
||||
this.errorLogFile = errorLogFile;
|
||||
this.errorSize = size;
|
||||
this.errorCount = nrOfLogFiles;
|
||||
this.errorAppend = append;
|
||||
}
|
||||
|
||||
public void initializeConsole() {
|
||||
consoleOutput = true;
|
||||
}
|
||||
|
||||
public void writeInfoLog(String message) {
|
||||
if (!consoleOutput) {
|
||||
if (infoHandler == null && infoLogFile != null) {
|
||||
try {
|
||||
infoHandler = new FileHandler(infoLogFile, infoSize, infoCount, infoAppend);
|
||||
infoHandler.setFormatter(new SimpleFormatter());
|
||||
infoLog.addHandler(infoHandler);
|
||||
LogManager logManager = LogManager.getLogManager();
|
||||
logManager.reset();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Could not redirect error and/or info output.");
|
||||
}
|
||||
|
||||
}
|
||||
infoLog.info(message);
|
||||
} else {
|
||||
System.out.println(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void writeErrorLog(String message) {
|
||||
if (!consoleOutput) {
|
||||
if (errorHandler == null && errorLogFile != null) {
|
||||
try {
|
||||
errorHandler = new FileHandler(errorLogFile, errorSize, errorCount, errorAppend);
|
||||
errorHandler.setFormatter(new SimpleFormatter());
|
||||
errorLog.addHandler(errorHandler);
|
||||
LogManager logManager = LogManager.getLogManager();
|
||||
logManager.reset();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Could not redirect error and/or info output.");
|
||||
}
|
||||
}
|
||||
errorLog.log(Level.SEVERE, message);
|
||||
} else {
|
||||
System.err.println(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void CloseHandlers() {
|
||||
if (errorHandler != null) {
|
||||
errorHandler.close();
|
||||
}
|
||||
if (infoHandler != null) {
|
||||
infoHandler.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.common.view;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @date Apr 14, 2005
|
||||
*/
|
||||
public class CommonFileChooser extends JFileChooser {
|
||||
private static final long serialVersionUID = -1440579455652851165L;
|
||||
private int returnCode;
|
||||
private JDialog dialog = null;
|
||||
|
||||
public CommonFileChooser(String path){
|
||||
super(path);
|
||||
}
|
||||
|
||||
private JDialog getDialog(){
|
||||
if(this.dialog == null){
|
||||
JFrame f = null;
|
||||
this.dialog = new JDialog(f, "", true);
|
||||
Container contentPane = this.dialog.getContentPane();
|
||||
contentPane.setLayout(new BorderLayout());
|
||||
contentPane.add(this, BorderLayout.CENTER);
|
||||
|
||||
this.dialog.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
returnCode = CANCEL_OPTION;
|
||||
dialog.setVisible(false);
|
||||
}
|
||||
});
|
||||
this.dialog.pack();
|
||||
}
|
||||
return this.dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fireActionPerformed(String command) {
|
||||
super.fireActionPerformed(command);
|
||||
|
||||
JDialog myDialog = this.getDialog();
|
||||
|
||||
if(APPROVE_SELECTION.equals(command)){
|
||||
returnCode = APPROVE_OPTION;
|
||||
myDialog.setVisible(false);
|
||||
} else if(CANCEL_SELECTION.equals(command)){
|
||||
returnCode = CANCEL_OPTION;
|
||||
myDialog.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int showDialog(Component parent, String title){
|
||||
JDialog myDialog = this.getDialog();
|
||||
|
||||
if(parent != null){
|
||||
myDialog.setLocationRelativeTo(parent);
|
||||
}
|
||||
if(title != null){
|
||||
myDialog.setTitle(title);
|
||||
}
|
||||
myDialog.setVisible(true);
|
||||
myDialog.toFront();
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,324 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
/**
|
||||
* Contains all SPLICE DDS C&M Tooling common view components.
|
||||
*/
|
||||
package org.eclipse.cyclonedds.common.view;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JButton;
|
||||
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class represents a generic dialog window and is meant to provide a fast and
|
||||
* simple way of constructing dialog windows.
|
||||
*
|
||||
* The window contains a status bar and
|
||||
* 'OK' and 'Cancel' buttons. By providing NameValuePanel objects, the user can
|
||||
* fill the dialog window with as many fields as he wishes.
|
||||
*/
|
||||
public class DialogWindow extends JFrame {
|
||||
private static final long serialVersionUID = -4875672779193998620L;
|
||||
|
||||
/**
|
||||
* The constructor of this object. It initializes the window.
|
||||
*
|
||||
* @param _controller The controller where to sent actions to. 'cancel'
|
||||
* for the Cancel button and _action for the OK button
|
||||
* @param _fields Array of name/value pairs that must be showed in the dialog window.
|
||||
* @param _action The action that the controller expects when the user clicks th OK button.
|
||||
* @param _title The title of the dialog window that will be shown in the top.
|
||||
*/
|
||||
public DialogWindow(ActionListener _controller, NameValuePanel[] _fields, String _action, String _title) {
|
||||
super();
|
||||
controller = _controller;
|
||||
action = _action;
|
||||
fields = _fields;
|
||||
title = _title;
|
||||
fieldNameMapping = new HashMap<String, NameValuePanel>(_fields.length);
|
||||
initialize();
|
||||
}
|
||||
|
||||
DialogWindow(ActionListener _controller, String _action, String _title){
|
||||
super();
|
||||
controller = _controller;
|
||||
action = _action;
|
||||
title = _title;
|
||||
fields = null;
|
||||
fieldNameMapping = new HashMap<String, NameValuePanel>();
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes the dialog window.
|
||||
*/
|
||||
void initialize() {
|
||||
this.setSize(1200, 1600);
|
||||
this.setContentPane(getJContentPane());
|
||||
this.setResizable(false);
|
||||
this.setTitle(title);
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
controller.actionPerformed(
|
||||
new ActionEvent(cancelButton, 0, "cancel"));
|
||||
}
|
||||
});
|
||||
this.pack();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes the root content pane
|
||||
*
|
||||
* @return The created or already existing content pane.
|
||||
*/
|
||||
JPanel getJContentPane() {
|
||||
if (jContentPane == null) {
|
||||
jContentPane = new JPanel();
|
||||
java.awt.GridLayout layGridLayout15 = new java.awt.GridLayout();
|
||||
|
||||
if(fields != null){
|
||||
layGridLayout15.setRows(fields.length);
|
||||
}
|
||||
|
||||
layGridLayout15.setColumns(1);
|
||||
layGridLayout15.setHgap(0);
|
||||
layGridLayout15.setVgap(5);
|
||||
JPanel inputPanel = new JPanel();
|
||||
inputPanel.setLayout(layGridLayout15);
|
||||
jContentPane.setLayout(new java.awt.BorderLayout());
|
||||
|
||||
if(fields != null){
|
||||
for(int i=0; i<fields.length; i++){
|
||||
String label = fields[i].getName();
|
||||
JComponent editor = fields[i].getField();
|
||||
|
||||
if(editor instanceof JTextField){
|
||||
((JTextField)editor).setActionCommand(action);
|
||||
((JTextField)editor).addActionListener(controller);
|
||||
editor.addFocusListener(new FocusListener() {
|
||||
@Override
|
||||
public void focusGained(FocusEvent e) {
|
||||
JTextField source = (JTextField)(e.getSource());
|
||||
source.selectAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusLost(FocusEvent e) {
|
||||
JTextField source = (JTextField)(e.getSource());
|
||||
source.select(0, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
fieldNameMapping.put(label, fields[i]);
|
||||
inputPanel.add(fields[i], null);
|
||||
}
|
||||
}
|
||||
jContentPane.add(inputPanel, java.awt.BorderLayout.NORTH);
|
||||
jContentPane.add(getButtonPanel(), java.awt.BorderLayout.CENTER);
|
||||
jContentPane.add(getStatusPanel(), java.awt.BorderLayout.SOUTH);
|
||||
}
|
||||
return jContentPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes the status panel
|
||||
*
|
||||
* @return The created or already existing status panel.
|
||||
*/
|
||||
StatusPanel getStatusPanel() {
|
||||
if(statusPanel == null) {
|
||||
statusPanel = new StatusPanel(250, "Please provide input.", false, false);
|
||||
}
|
||||
return statusPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes the buttonPanel that contains the OK and Cancel button.
|
||||
*
|
||||
* @return The created or already existing buttonPanel.
|
||||
*/
|
||||
JPanel getButtonPanel() {
|
||||
if(buttonPanel == null) {
|
||||
buttonPanel = new JPanel();
|
||||
FlowLayout layFlowLayout = new FlowLayout(FlowLayout.RIGHT);
|
||||
buttonPanel.setLayout(layFlowLayout);
|
||||
buttonPanel.add(getOkButton(), null);
|
||||
buttonPanel.add(getCancelButton(), null);
|
||||
}
|
||||
return buttonPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes the cancelButton
|
||||
*
|
||||
* @return The created or already existing Cancel button.
|
||||
*/
|
||||
JButton getCancelButton() {
|
||||
if(cancelButton == null) {
|
||||
cancelButton = new JButton();
|
||||
cancelButton.setText("Cancel");
|
||||
cancelButton.setMnemonic('C');
|
||||
cancelButton.setActionCommand("cancel");
|
||||
cancelButton.addActionListener(controller);
|
||||
cancelButton.setPreferredSize(new java.awt.Dimension(100, 20));
|
||||
}
|
||||
return cancelButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes the OK button.
|
||||
*
|
||||
* @return The created or already existing OK button.
|
||||
*/
|
||||
JButton getOkButton() {
|
||||
if(okButton == null) {
|
||||
okButton = new JButton();
|
||||
okButton.setText("Ok");
|
||||
okButton.setMnemonic('O');
|
||||
okButton.setActionCommand(action);
|
||||
okButton.addActionListener(controller);
|
||||
okButton.setPreferredSize(new java.awt.Dimension(100, 20));
|
||||
this.getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
return okButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status message in the status panel of the dialog window.
|
||||
*
|
||||
* @param message The message to show in the status panel.
|
||||
* @param persistent true if the message should be shown until the next
|
||||
* call to this operation, false if it should disappear after a few seconds.
|
||||
*/
|
||||
public void setStatus(String message, boolean persistent){
|
||||
statusPanel.setStatus(message, persistent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to all values in the input fields.
|
||||
*
|
||||
* @return The map of values. The key is the name of the field <fieldName, value>.
|
||||
*/
|
||||
public HashMap<String, Object> getValues() {
|
||||
HashMap<String, Object> values = new HashMap<String, Object>();
|
||||
|
||||
for(int i=0; i<fields.length; i++){
|
||||
values.put(fields[i].getName(), fields[i].getValue());
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the value of a field.
|
||||
*
|
||||
* @param fieldName The fieldName of the field to get the value of.
|
||||
* @return The value of the field.
|
||||
*/
|
||||
public Object getValue(String fieldName){
|
||||
NameValuePanel nv = fieldNameMapping.get(fieldName);
|
||||
|
||||
if(nv == null){
|
||||
return "";
|
||||
}
|
||||
return nv.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if all fields have compatible values in.
|
||||
*
|
||||
* @return true if all fields have a compatible value, false otherwise.
|
||||
*/
|
||||
public boolean isInputValid(){
|
||||
NameValuePanel nvp = null;
|
||||
Object test = null;
|
||||
Collection<NameValuePanel> f = fieldNameMapping.values();
|
||||
Iterator<NameValuePanel> fIter = f.iterator();
|
||||
|
||||
while(fIter.hasNext()){
|
||||
nvp = fIter.next();
|
||||
test = nvp.getValue();
|
||||
if(test == null || test.equals("")){
|
||||
if(!(nvp.isEmptyInputAllowed())){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public NameValuePanel getField(String name){
|
||||
return fieldNameMapping.get(name);
|
||||
}
|
||||
|
||||
public NameValuePanel[] getFields(){
|
||||
return fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* The root pane of the dialog window.
|
||||
*/
|
||||
javax.swing.JPanel jContentPane = null;
|
||||
|
||||
/**
|
||||
* The status panel.
|
||||
*/
|
||||
StatusPanel statusPanel = null;
|
||||
|
||||
/**
|
||||
* The panel where the 'OK' and 'Cancel' buttons are placed on.
|
||||
*/
|
||||
JPanel buttonPanel = null;
|
||||
|
||||
/**
|
||||
* The 'Cancel' button.
|
||||
*/
|
||||
JButton cancelButton = null;
|
||||
|
||||
/**
|
||||
* The 'OK' button.
|
||||
*/
|
||||
JButton okButton = null;
|
||||
|
||||
/**
|
||||
* The controller (mvC), where the action command will be sent to when the
|
||||
* user clicks the OK button.
|
||||
*/
|
||||
ActionListener controller = null;
|
||||
|
||||
/**
|
||||
* The title of the dialog window.
|
||||
*/
|
||||
String title = null;
|
||||
|
||||
/**
|
||||
* The action string that must be sent to the controller
|
||||
* when the 'OK' button is clicked.
|
||||
*/
|
||||
String action = null;
|
||||
|
||||
/**
|
||||
* The name/value pairs that are shown in the window.
|
||||
*/
|
||||
NameValuePanel[] fields = null;
|
||||
|
||||
/**
|
||||
* Fields in the window <String, NameValuePanel>
|
||||
*/
|
||||
HashMap<String, NameValuePanel> fieldNameMapping = null;
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.common.view;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.ToolTipManager;
|
||||
|
||||
/**
|
||||
* Abstract class that is typically extended from by main windows of an
|
||||
* application. It offers a StatusPanel, which is capable of displaying
|
||||
* the current status and implements the ModelListener interface to be able
|
||||
* to be attached to ModelRegister components and receive updates from it. This
|
||||
* class has been defined abstract because only descendants of this class may
|
||||
* exist.
|
||||
*
|
||||
* @date Sep 1, 2004
|
||||
*/
|
||||
public abstract class MainWindow extends JFrame {
|
||||
private static final long serialVersionUID = 5540350112074790669L;
|
||||
protected StatusPanel statusPanel = null;
|
||||
|
||||
/**
|
||||
* This is the default constructor
|
||||
*/
|
||||
public MainWindow() {
|
||||
super();
|
||||
ToolTipManager tm = ToolTipManager.sharedInstance();
|
||||
tm.setInitialDelay(100);
|
||||
this.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
this.setSize(800, 600);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes statusPanel.
|
||||
*
|
||||
* @return The status panel of the window.
|
||||
*/
|
||||
protected StatusPanel getStatusPanel() {
|
||||
if (statusPanel == null) {
|
||||
statusPanel = new StatusPanel(300, "Ready", true, true);
|
||||
}
|
||||
return statusPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the statusPanel and sets the progress.
|
||||
*
|
||||
* @param message The message to show in the statusbar.
|
||||
* @param persistent true if the message must be shown until a new call to
|
||||
* this function, or false when it should automatically be
|
||||
* removed after certain amount of time.
|
||||
* @param busy Sets the progress monitor of the statusbar.
|
||||
*/
|
||||
public void setStatus(String message, boolean persistent, boolean busy){
|
||||
statusPanel.setStatus(message, persistent, busy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the statusPanel.
|
||||
*
|
||||
* @param message The message to show in the statusbar.
|
||||
* @param persistent true if the message must be shown until a new call to
|
||||
* this function, or false when it should automatically be
|
||||
* removed after certain amount of time.
|
||||
*/
|
||||
public void setStatus(String message, boolean persistent){
|
||||
statusPanel.setStatus(message, persistent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the current status.
|
||||
*
|
||||
* @return The currently shown status.
|
||||
*/
|
||||
public String getStatus(){
|
||||
return statusPanel.getStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the view component.
|
||||
*
|
||||
* This is done when a dialog is shown and the user must
|
||||
* provide input before proceeding.
|
||||
*/
|
||||
public void disableView(){
|
||||
this.setEnabled(false);
|
||||
this.setFocusable(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the view component.
|
||||
*/
|
||||
public void enableView(){
|
||||
this.setFocusable(true);
|
||||
this.setEnabled(true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.common.view;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
/**
|
||||
* This class is meant to provide a standard generic input panel that
|
||||
* contains a label and a input field.
|
||||
*
|
||||
* Input fields that are currently supported are:
|
||||
* - textfields
|
||||
* - comboboxes.
|
||||
*/
|
||||
public abstract class NameValuePanel extends JPanel {
|
||||
private static final long serialVersionUID = 8693880375019883969L;
|
||||
|
||||
/**
|
||||
* Creates an input panel with a label and a textfield.
|
||||
* @param _fieldName The name of the field that is also used as label.
|
||||
* @param _emptyInputAllowed Boolean that specifies if empty input is allowed when
|
||||
* submitted.
|
||||
*/
|
||||
public NameValuePanel(
|
||||
String fieldName,
|
||||
Object defaultValue,
|
||||
boolean emptyInputAllowed,
|
||||
Dimension labelDim,
|
||||
Dimension fieldDim)
|
||||
{
|
||||
super();
|
||||
if(labelDim != null){
|
||||
this.labelDim = labelDim;
|
||||
|
||||
if(this.labelDim.height != 20){
|
||||
this.labelDim.height = 20;
|
||||
}
|
||||
} else {
|
||||
this.labelDim = new Dimension(100, 20);
|
||||
}
|
||||
if(fieldDim != null){
|
||||
this.fieldDim = fieldDim;
|
||||
|
||||
if(this.fieldDim.height != 20){
|
||||
this.fieldDim.height = 20;
|
||||
}
|
||||
} else {
|
||||
this.fieldDim = new Dimension(230, 20);
|
||||
}
|
||||
this.fieldName = fieldName;
|
||||
this.emptyInputAllowed = emptyInputAllowed;
|
||||
this.defaultValue = defaultValue;
|
||||
this.initLayout();
|
||||
this.initLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the layout (FlowLayout is used).
|
||||
*/
|
||||
protected void initLayout(){
|
||||
FlowLayout layFlowLayout = new FlowLayout(FlowLayout.LEFT);
|
||||
layFlowLayout.setVgap(0);
|
||||
this.setLayout(layFlowLayout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the label.
|
||||
*
|
||||
* The fieldName is also used as label text.
|
||||
*/
|
||||
protected void initLabel(){
|
||||
JLabel label = new JLabel();
|
||||
label.setText(fieldName);
|
||||
label.setPreferredSize(labelDim);
|
||||
this.add(label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the name of the field.
|
||||
*
|
||||
* @return The name of the field.
|
||||
*/
|
||||
@Override
|
||||
public String getName(){
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the emptyInputIsAllowed boolean.
|
||||
*
|
||||
* @return true if the field may be empty when submitted, false otherwise.
|
||||
*/
|
||||
public boolean isEmptyInputAllowed(){
|
||||
return emptyInputAllowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the editor component for the field value.
|
||||
*
|
||||
* @return The editor component for the field value.
|
||||
*/
|
||||
public JComponent getField(){
|
||||
return field;
|
||||
}
|
||||
|
||||
public abstract Object getValue();
|
||||
|
||||
@Override
|
||||
public abstract void setEnabled(boolean enabled);
|
||||
|
||||
/**
|
||||
* The name of the field.
|
||||
*/
|
||||
protected String fieldName = null;
|
||||
|
||||
/**
|
||||
* The input field.
|
||||
*/
|
||||
protected JComponent field = null;
|
||||
|
||||
/**
|
||||
* The label Dimension.
|
||||
*/
|
||||
protected Dimension labelDim = null;
|
||||
|
||||
/**
|
||||
* The field Dimension.
|
||||
*/
|
||||
protected Dimension fieldDim = null;
|
||||
|
||||
/**
|
||||
* Boolean that specifies if empy input is allowed for this field.
|
||||
*/
|
||||
protected boolean emptyInputAllowed;
|
||||
|
||||
protected Object defaultValue = null;
|
||||
}
|
|
@ -0,0 +1,392 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.common.view;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
|
||||
import org.eclipse.cyclonedds.common.util.Config;
|
||||
|
||||
/**
|
||||
* This class provides a standard statusbar that can be placed in a window at
|
||||
* any place.
|
||||
*/
|
||||
public class StatusPanel extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = -6861447244439379176L;
|
||||
|
||||
/**
|
||||
* Creates a new StatusPanel that can be used to provide information about
|
||||
* the status of the application of a certain action. The StatusPanel
|
||||
* optionally provides a connection light and a progressbar.
|
||||
*
|
||||
* @param width
|
||||
* The width of the panel.
|
||||
* @param _defaultText
|
||||
* The default text of the panel.
|
||||
* @param showConnectionLight
|
||||
* Whether or not to display a connection light.
|
||||
* @param showProgressBar
|
||||
* Whether or not to display a progressbar.
|
||||
*/
|
||||
public StatusPanel(int width, String _defaultText,
|
||||
boolean showConnectionLight, boolean showProgressBar) {
|
||||
super();
|
||||
this.setLayout(new java.awt.BorderLayout());
|
||||
defaultText = _defaultText;
|
||||
|
||||
if (defaultText == null) {
|
||||
defaultText = "";
|
||||
}
|
||||
defaultBg = this.getBackground();
|
||||
status = new JLabel();
|
||||
status.setText(defaultText);
|
||||
status.setToolTipText(defaultText);
|
||||
java.awt.GridLayout layGridLayout2 = new java.awt.GridLayout();
|
||||
layGridLayout2.setRows(1);
|
||||
layGridLayout2.setColumns(1);
|
||||
|
||||
if (showConnectionLight && showProgressBar) {
|
||||
progressBar = new JProgressBar(0, 10);
|
||||
progressBar.setBorderPainted(false);
|
||||
progressBar.setPreferredSize(new java.awt.Dimension(
|
||||
width / 10 + 10, 10));
|
||||
|
||||
JPanel temp = new JPanel();
|
||||
temp.setLayout(new java.awt.BorderLayout());
|
||||
temp.setBorder(javax.swing.BorderFactory
|
||||
.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
|
||||
|
||||
statusPanel = new JPanel();
|
||||
statusPanel.setLayout(layGridLayout2);
|
||||
statusPanel.setPreferredSize(new java.awt.Dimension(width - 20
|
||||
- (width / 10) - 10, 20));
|
||||
statusPanel.setMinimumSize(new java.awt.Dimension(50, 20));
|
||||
statusPanel.add(status);
|
||||
|
||||
temp.add(statusPanel, java.awt.BorderLayout.CENTER);
|
||||
temp.add(progressBar, java.awt.BorderLayout.EAST);
|
||||
|
||||
connectionPanel = new JPanel();
|
||||
connectionPanel.setPreferredSize(new java.awt.Dimension(20, 10));
|
||||
connectionPanel
|
||||
.setBorder(javax.swing.BorderFactory.createCompoundBorder(
|
||||
javax.swing.BorderFactory
|
||||
.createCompoundBorder(
|
||||
javax.swing.BorderFactory
|
||||
.createLineBorder(
|
||||
connectionPanel
|
||||
.getBackground(),
|
||||
2),
|
||||
javax.swing.BorderFactory
|
||||
.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED)),
|
||||
javax.swing.BorderFactory
|
||||
.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)));
|
||||
connectionPanel.setBackground(disconnectedColor);
|
||||
connectionPanel.setToolTipText("Not connected.");
|
||||
|
||||
this.add(temp, java.awt.BorderLayout.CENTER);
|
||||
this.add(connectionPanel, java.awt.BorderLayout.EAST);
|
||||
this.setPreferredSize(new java.awt.Dimension(width, 20));
|
||||
} else if (showProgressBar) {
|
||||
progressBar = new JProgressBar(0, 10);
|
||||
progressBar.setBorderPainted(false);
|
||||
progressBar.setPreferredSize(new java.awt.Dimension(
|
||||
width / 10 + 10, 10));
|
||||
|
||||
statusPanel = new JPanel();
|
||||
statusPanel.setLayout(layGridLayout2);
|
||||
statusPanel.setPreferredSize(new java.awt.Dimension(width
|
||||
- (width / 10) - 10, 20));
|
||||
statusPanel.setMinimumSize(new java.awt.Dimension(50, 20));
|
||||
statusPanel.add(status);
|
||||
|
||||
this.setBorder(javax.swing.BorderFactory
|
||||
.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
|
||||
this.setPreferredSize(new java.awt.Dimension(width, 20));
|
||||
this.add(statusPanel, java.awt.BorderLayout.CENTER);
|
||||
this.add(progressBar, java.awt.BorderLayout.EAST);
|
||||
} else if (showConnectionLight) {
|
||||
statusPanel = new JPanel();
|
||||
statusPanel.setLayout(layGridLayout2);
|
||||
statusPanel.setBorder(javax.swing.BorderFactory
|
||||
.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
|
||||
statusPanel
|
||||
.setPreferredSize(new java.awt.Dimension(width - 20, 20));
|
||||
statusPanel.setMinimumSize(new java.awt.Dimension(50, 20));
|
||||
statusPanel.add(status);
|
||||
|
||||
connectionPanel = new JPanel();
|
||||
connectionPanel.setPreferredSize(new java.awt.Dimension(20, 10));
|
||||
connectionPanel
|
||||
.setBorder(javax.swing.BorderFactory.createCompoundBorder(
|
||||
javax.swing.BorderFactory
|
||||
.createCompoundBorder(
|
||||
javax.swing.BorderFactory
|
||||
.createLineBorder(
|
||||
connectionPanel
|
||||
.getBackground(),
|
||||
2),
|
||||
javax.swing.BorderFactory
|
||||
.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED)),
|
||||
javax.swing.BorderFactory
|
||||
.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)));
|
||||
connectionPanel.setBackground(disconnectedColor);
|
||||
connectionPanel.setToolTipText("Not connected.");
|
||||
|
||||
this.add(statusPanel, java.awt.BorderLayout.CENTER);
|
||||
this.add(connectionPanel, java.awt.BorderLayout.EAST);
|
||||
this.setPreferredSize(new java.awt.Dimension(width, 20));
|
||||
} else {
|
||||
this.setLayout(layGridLayout2);
|
||||
this.setBorder(javax.swing.BorderFactory
|
||||
.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
|
||||
this.setPreferredSize(new java.awt.Dimension(width, 20));
|
||||
this.setMinimumSize(new java.awt.Dimension(100, 20));
|
||||
this.add(status);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the connection light to green when connected and to red if not.
|
||||
*
|
||||
* @param connected
|
||||
* Whether or not the application has a connection.
|
||||
* @param toolTip
|
||||
* The tooltip that must be displayed when the user moves the
|
||||
* mouse over the connection light.
|
||||
*/
|
||||
public synchronized void setConnected(boolean connected, String toolTip) {
|
||||
if (connectionPanel != null) {
|
||||
final boolean con = connected;
|
||||
final String tt = toolTip;
|
||||
|
||||
Runnable runner = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (con) {
|
||||
connectionPanel.setBackground(connectedColor);
|
||||
} else {
|
||||
connectionPanel.setBackground(disconnectedColor);
|
||||
}
|
||||
connectionPanel.setToolTipText(tt);
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(runner);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status message to the supplied message and sets the progressbar
|
||||
* to indeterminate mode or resets it. This is done by calling the
|
||||
* setStatus(String, boolean) method as well as the setBusy method.
|
||||
*
|
||||
* @param message
|
||||
* The message to set.
|
||||
* @param persistent
|
||||
* Whether or not the message should never be removed or not.
|
||||
* @param busy
|
||||
* Whether or not the progressbar must be set in indeterminate
|
||||
* mode or not.
|
||||
*/
|
||||
public synchronized void setStatus(String msg, boolean persistent,
|
||||
boolean busy) {
|
||||
if (msg == null) {
|
||||
msg = "";
|
||||
}
|
||||
final String message = msg;
|
||||
final boolean b = busy;
|
||||
final boolean p = persistent;
|
||||
|
||||
/*
|
||||
* Runnable runner = new Runnable() { public void run(){
|
||||
*/
|
||||
String myMsg = message;
|
||||
|
||||
if ("".equals(message)) {
|
||||
myMsg = defaultText;
|
||||
}
|
||||
if (message.startsWith("Error:")) {
|
||||
if (statusPanel != null) {
|
||||
statusPanel.setBackground(errorColor);
|
||||
|
||||
if (progressBar != null) {
|
||||
progressBar.setBackground(errorColor);
|
||||
}
|
||||
} else {
|
||||
setBackground(errorColor);
|
||||
}
|
||||
myMsg = message.substring(6);
|
||||
} else if (message.startsWith("Warning:")) {
|
||||
if (statusPanel != null) {
|
||||
statusPanel.setBackground(warningColor);
|
||||
|
||||
if (progressBar != null) {
|
||||
progressBar.setBackground(warningColor);
|
||||
}
|
||||
} else {
|
||||
setBackground(warningColor);
|
||||
}
|
||||
myMsg = message.substring(8);
|
||||
} else { // Standard message
|
||||
if (statusPanel != null) {
|
||||
statusPanel.setBackground(defaultBg);
|
||||
|
||||
if (progressBar != null) {
|
||||
progressBar.setBackground(defaultBg);
|
||||
}
|
||||
} else {
|
||||
setBackground(defaultBg);
|
||||
}
|
||||
}
|
||||
status.setText(" " + myMsg);
|
||||
status.setToolTipText(myMsg);
|
||||
setBusy(b);
|
||||
|
||||
synchronized (this) {
|
||||
if (!p) {
|
||||
Timer persistentTimer = new Timer(persistentTime,
|
||||
new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
synchronized (org.eclipse.cyclonedds.common.view.StatusPanel.this) {
|
||||
if (((currentTime - lastMessageTime) < persistentTime)
|
||||
|| (!lastPersistent)) {
|
||||
/*
|
||||
* New message has arrived, ignore
|
||||
* reset.
|
||||
*/
|
||||
} else {
|
||||
setStatus(defaultText, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
persistentTimer.setRepeats(false);
|
||||
lastMessageTime = System.currentTimeMillis();
|
||||
persistentTimer.start();
|
||||
lastPersistent = true;
|
||||
} else {
|
||||
lastPersistent = false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* }
|
||||
*
|
||||
* }; runner.run(); SwingUtilities.invokeLater(runner);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the status message. If the message starts with "Error:" the
|
||||
* background color will become red and the "Error:" part of the string will
|
||||
* not be shown. If the message starts with "Warning:" the background color
|
||||
* will become yellow and the "Warning:" part of the string will not be
|
||||
* displayed.
|
||||
*
|
||||
* @param message
|
||||
* The new status message.
|
||||
* @param persistent
|
||||
* If true, the message will not be changed into the standard
|
||||
* text after a few seconds, but stay there until this function
|
||||
* is called again.
|
||||
*/
|
||||
public synchronized void setStatus(String message, boolean persistent) {
|
||||
this.setStatus(message, persistent, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the progressbar status. When true, the progressbar will go into
|
||||
* inderminate mode and display 'busy...', when false the progressbar will
|
||||
* leave indeterminate mode and display 'ready'
|
||||
*
|
||||
* @param busy
|
||||
* When true, the progressbar will go into inderminate mode
|
||||
*/
|
||||
private synchronized void setBusy(boolean busy) {
|
||||
if (progressBar != null) {
|
||||
if (busy) {
|
||||
progressBar.setBorderPainted(true);
|
||||
progressBar.setStringPainted(true);
|
||||
progressBar.setString("busy..");
|
||||
} else {
|
||||
progressBar.setBorderPainted(false);
|
||||
progressBar.setStringPainted(false);
|
||||
progressBar.setString(null);
|
||||
}
|
||||
progressBar.setIndeterminate(busy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the current status.
|
||||
*
|
||||
* @return The currently displayed status.
|
||||
*/
|
||||
public synchronized String getStatus() {
|
||||
return status.getText();
|
||||
}
|
||||
|
||||
private static final int persistentTime = 4000;
|
||||
|
||||
private long lastMessageTime;
|
||||
|
||||
private boolean lastPersistent = false;
|
||||
|
||||
/**
|
||||
* The current status message.
|
||||
*/
|
||||
private JLabel status = null;
|
||||
|
||||
/**
|
||||
* The default message.
|
||||
*/
|
||||
private String defaultText = null;
|
||||
|
||||
/**
|
||||
* The default background color
|
||||
*/
|
||||
private Color defaultBg = null;
|
||||
|
||||
/**
|
||||
* Panel that holds the connection light. Green if connected, red if not
|
||||
* connected.
|
||||
*/
|
||||
private JPanel connectionPanel = null;
|
||||
|
||||
/**
|
||||
* Progressbar that can be used to provide the user with progress
|
||||
* information.
|
||||
*/
|
||||
private JProgressBar progressBar = null;
|
||||
|
||||
/**
|
||||
* Panel that holds the status label.
|
||||
*/
|
||||
private JPanel statusPanel = null;
|
||||
|
||||
private final Color connectedColor = Config.getActiveColor();
|
||||
|
||||
private final Color errorColor = Config.getErrorColor();
|
||||
|
||||
private final Color warningColor = Config.getWarningColor();
|
||||
|
||||
private final Color disconnectedColor = Config.getErrorColor();
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config;
|
||||
|
||||
import org.eclipse.cyclonedds.common.util.Initializer;
|
||||
import org.eclipse.cyclonedds.common.util.Report;
|
||||
import org.eclipse.cyclonedds.config.swing.ConfigWindow;
|
||||
|
||||
public class SpliceConfig extends Initializer {
|
||||
|
||||
/**
|
||||
* Starts Splice Tuner. This function is the main class of Splice Tuner;
|
||||
* - It checks for the right version of the JVM, this must be 1.5.0.
|
||||
* - It passes on the commandline arguments. Arguments that are supported
|
||||
* are:
|
||||
* -# <java_properties_file>
|
||||
*
|
||||
* @param args These are passed on to the initialize function of the
|
||||
* SpliceTuner object.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
boolean redirect = true;
|
||||
boolean uriSet = false;
|
||||
String[] args2;
|
||||
String uri = null;
|
||||
|
||||
SpliceConfig t = new SpliceConfig();
|
||||
t.validateJVMVersion();
|
||||
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if ("-noredirect".equals(args[i])) {
|
||||
redirect = false;
|
||||
} else if (args[i].toLowerCase().startsWith("-uri=")) {
|
||||
uri = args[i].substring(5); /* '-uri=' is 5 characters */
|
||||
uriSet = true;
|
||||
} else {
|
||||
args2 = new String[1];
|
||||
args2[0] = args[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (redirect) {
|
||||
/*
|
||||
* initialize logging with a max size of 10M with a max history of
|
||||
* 10 runs and do not append
|
||||
*/
|
||||
Report.getInstance().initializeInfo("cycloneddsconf-info.log", 10000000, 10, false);
|
||||
Report.getInstance().initializeError("cycloneddsconf-error.log", 10000000, 10, false);
|
||||
} else {
|
||||
Report.getInstance().initializeConsole();
|
||||
System.out.println("No redirect.");
|
||||
}
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Report.getInstance().CloseHandlers();
|
||||
}
|
||||
});
|
||||
ConfigWindow cw = null;
|
||||
if (uriSet) {
|
||||
cw = new ConfigWindow(uri);
|
||||
} else {
|
||||
cw = new ConfigWindow();
|
||||
}
|
||||
cw.setVisible(true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.data;
|
||||
|
||||
import org.w3c.dom.Attr;
|
||||
|
||||
import org.eclipse.cyclonedds.config.meta.MetaAttribute;
|
||||
|
||||
public class DataAttribute extends DataNode {
|
||||
private DataValue value;
|
||||
|
||||
public DataAttribute(MetaAttribute metadata, Attr node, Object value) throws DataException {
|
||||
super(metadata, node);
|
||||
|
||||
if(!node.getNodeName().equals(metadata.getName())){
|
||||
throw new DataException("Metadata and data do not match.");
|
||||
}
|
||||
this.value = new DataValue(metadata.getValue(), node, value);
|
||||
this.value.setParent(this);
|
||||
this.value.setOwner(this.getOwner());
|
||||
}
|
||||
|
||||
public DataAttribute(MetaAttribute metadata, Attr node) throws DataException {
|
||||
super(metadata, node);
|
||||
|
||||
if(!node.getNodeName().equals(metadata.getName())){
|
||||
throw new DataException("Metadata and data do not match.");
|
||||
}
|
||||
Object defaultValue = metadata.getValue().getDefaultValue();
|
||||
this.value = new DataValue(metadata.getValue(), node, defaultValue);
|
||||
this.value.setParent(this);
|
||||
this.value.setOwner(this.getOwner());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(DataConfiguration owner) {
|
||||
super.setOwner(owner);
|
||||
this.value.setOwner(owner);
|
||||
}
|
||||
|
||||
public DataValue getDataValue(){
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void testSetValue(Object value) throws DataException{
|
||||
this.value.testSetValue(value);
|
||||
}
|
||||
|
||||
public void setValue(Object value) throws DataException{
|
||||
DataValue tmpValue = this.value;
|
||||
this.value.setValue(value);
|
||||
tmpValue.setParent(null);
|
||||
tmpValue.setOwner(null);
|
||||
this.value.setParent(this);
|
||||
this.value.setOwner(this.owner);
|
||||
}
|
||||
|
||||
public Object getValue(){
|
||||
return this.value.getValue();
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.data;
|
||||
|
||||
public interface DataConfigurationListener {
|
||||
public void valueChanged(DataValue data, Object oldValue, Object newValue);
|
||||
|
||||
public void nodeAdded(DataElement parent, DataNode nodeAdded);
|
||||
|
||||
public void nodeRemoved(DataElement parent, DataNode nodeRemoved);
|
||||
|
||||
}
|
|
@ -0,0 +1,220 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cyclonedds.common.util.ConfigModeIntializer;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaAttribute;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaElement;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaNode;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValue;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
|
||||
public class DataElement extends DataNode {
|
||||
private ArrayList<DataNode> children = null;
|
||||
|
||||
public DataElement(MetaElement metadata, Element node) throws DataException {
|
||||
super(metadata, node);
|
||||
|
||||
if(!node.getNodeName().equals(metadata.getName())){
|
||||
throw new DataException("Metadata and data do not match.");
|
||||
}
|
||||
this.children = new ArrayList<DataNode>();
|
||||
}
|
||||
|
||||
protected DataNode addChild(DataNode node, int addToDOM, String value) throws DataException {
|
||||
/*
|
||||
* addToDOM values: 0 = do not add (false) 1 = append (true) 2 = replace
|
||||
* (this is done when the user choose to repair the value)
|
||||
*/
|
||||
int count;
|
||||
MetaNode nodeMeta;
|
||||
|
||||
if(node == null){
|
||||
throw new DataException("Cannot add null child.");
|
||||
} else if(this.children.contains(node)){
|
||||
throw new DataException("Element already contains this child.");
|
||||
} else if(!this.isNodeChildCandidate(node)){
|
||||
throw new DataException("Node cannot be added to this element.");
|
||||
}
|
||||
|
||||
nodeMeta = node.getMetadata();
|
||||
count = 0;
|
||||
|
||||
for(DataNode child: this.children){
|
||||
if(child instanceof DataValue){
|
||||
if(node instanceof DataValue){
|
||||
throw new DataException("Element " +
|
||||
((MetaElement)this.metadata).getName() +
|
||||
" already contains this child: " +
|
||||
((DataValue)node).getValue() + " with value: " +
|
||||
((DataValue)child).getValue());
|
||||
}
|
||||
} else if(child instanceof DataElement){
|
||||
if(node instanceof DataElement){
|
||||
if(child.getMetadata().equals(nodeMeta)){
|
||||
count++;
|
||||
}
|
||||
}
|
||||
} else if(child instanceof DataAttribute){
|
||||
if(node instanceof DataAttribute){
|
||||
if(child.getMetadata().equals(nodeMeta)){
|
||||
throw new DataException("Element already contains attribute: "
|
||||
+ ((MetaAttribute)nodeMeta).getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(nodeMeta instanceof MetaElement){
|
||||
if (nodeMeta.getVersion().equals(ConfigModeIntializer.COMMERCIAL)
|
||||
&& (ConfigModeIntializer.CONFIGURATOR_MODE == ConfigModeIntializer.COMMUNITY_MODE || ConfigModeIntializer.CONFIGURATOR_MODE == ConfigModeIntializer.COMMUNITY_MODE_FILE_OPEN)) {
|
||||
addToDOM = 0;
|
||||
}
|
||||
if(count == ((MetaElement)nodeMeta).getMaxOccurrences()){
|
||||
throw new DataException("Maximum number of occurrences for " +
|
||||
((MetaElement)nodeMeta).getName()+ " reached.");
|
||||
} else if (addToDOM == 1) {
|
||||
((Element) this.node).appendChild(node.getNode());
|
||||
Text textNode = this.owner.getDocument().createTextNode("\n");
|
||||
this.node.appendChild(textNode);
|
||||
} else if (addToDOM == 2) {
|
||||
replaceChild(node.getNode(), value);
|
||||
Text textNode = this.owner.getDocument().createTextNode("\n");
|
||||
this.node.appendChild(textNode);
|
||||
}
|
||||
} else if(nodeMeta instanceof MetaAttribute){
|
||||
if (nodeMeta.getVersion().equals(ConfigModeIntializer.COMMERCIAL)
|
||||
&& (ConfigModeIntializer.CONFIGURATOR_MODE == ConfigModeIntializer.COMMUNITY_MODE || ConfigModeIntializer.CONFIGURATOR_MODE == ConfigModeIntializer.COMMUNITY_MODE_FILE_OPEN)) {
|
||||
addToDOM = 0;
|
||||
}
|
||||
if (addToDOM == 1) {
|
||||
((Element)this.node).setAttributeNode((Attr)node.getNode());
|
||||
}
|
||||
} else if(nodeMeta instanceof MetaValue){
|
||||
if (addToDOM == 1) {
|
||||
((Element)this.node).appendChild(node.getNode());
|
||||
assert this.owner != null;
|
||||
assert this.owner.getDocument() != null;
|
||||
} else if (addToDOM == 2) {
|
||||
replaceChild(node.getNode(), value);
|
||||
Text textNode = this.owner.getDocument().createTextNode("\n");
|
||||
this.node.appendChild(textNode);
|
||||
}
|
||||
}
|
||||
this.children.add(node);
|
||||
node.setParent(this);
|
||||
node.setOwner(this.owner);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
public void replaceChild(Node node, String value) {
|
||||
NodeList nodeList = ((Element) this.node).getChildNodes();
|
||||
boolean finished = false;
|
||||
for (int i = 0, len = nodeList.getLength(); i < len && !finished; i++) {
|
||||
Node n = nodeList.item(i);
|
||||
if (n.getNodeValue().equals(value)) {
|
||||
((Element) this.node).replaceChild(node, n);
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(DataConfiguration owner) {
|
||||
super.setOwner(owner);
|
||||
|
||||
for(DataNode child: this.children){
|
||||
child.setOwner(owner);
|
||||
}
|
||||
}
|
||||
|
||||
public DataNode addChild(DataNode node) throws DataException{
|
||||
return addChild(node, 1, null);
|
||||
}
|
||||
|
||||
public void removeChild(DataNode node) throws DataException{
|
||||
int count;
|
||||
MetaNode nodeMeta;
|
||||
|
||||
if(node == null){
|
||||
throw new DataException("Cannot remove null child.");
|
||||
} else if(!(this.children.contains(node))){
|
||||
throw new DataException("Element does not contain this child.");
|
||||
}
|
||||
nodeMeta = node.getMetadata();
|
||||
count = 0;
|
||||
|
||||
for(DataNode child: this.children){
|
||||
if(child.getMetadata().equals(nodeMeta)){
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if(nodeMeta instanceof MetaElement){
|
||||
if(count == ((MetaElement)nodeMeta).getMinOccurrences()){
|
||||
throw new DataException("Minimum number of occurrences for " +
|
||||
((MetaElement)nodeMeta).getName()+ " reached.");
|
||||
} else if (ConfigModeIntializer.CONFIGURATOR_MODE == ConfigModeIntializer.COMMERCIAL_MODE) {
|
||||
((Element) this.node).removeChild(node.getNode());
|
||||
} else {
|
||||
if (!nodeMeta.getVersion().equals(
|
||||
ConfigModeIntializer.COMMERCIAL)) {
|
||||
if (!node.getOwner().getCommercialServices()
|
||||
.contains(node.getNode())) {
|
||||
((Element) this.node).removeChild(node.getNode());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(nodeMeta instanceof MetaAttribute){
|
||||
if(((MetaAttribute)nodeMeta).isRequired()){
|
||||
throw new DataException("Cannot remove required attribute " +
|
||||
((MetaAttribute)nodeMeta).getName()+ ".");
|
||||
} else if (ConfigModeIntializer.CONFIGURATOR_MODE == ConfigModeIntializer.COMMERCIAL_MODE) {
|
||||
((Element) this.node)
|
||||
.removeAttributeNode((Attr) node.getNode());
|
||||
} else {
|
||||
if (!nodeMeta.getVersion().equals(
|
||||
ConfigModeIntializer.COMMERCIAL)) {
|
||||
((Element)this.node).removeAttributeNode((Attr)node.getNode());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
((Element)this.node).removeChild(node.getNode());
|
||||
}
|
||||
this.children.remove(node);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public DataNode[] getChildren(){
|
||||
return this.children.toArray(new DataNode[this.children.size()]);
|
||||
}
|
||||
|
||||
private boolean isNodeChildCandidate(DataNode node){
|
||||
MetaNode nodeMeta = node.getMetadata();
|
||||
MetaNode[] metaNodes = ((MetaElement)this.metadata).getChildren();
|
||||
|
||||
for(MetaNode mn: metaNodes){
|
||||
if(mn.equals(nodeMeta)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.data;
|
||||
|
||||
public class DataException extends Exception {
|
||||
private static final long serialVersionUID = 7787444897071114498L;
|
||||
|
||||
public DataException(String message){
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.data;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.eclipse.cyclonedds.config.meta.MetaNode;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public abstract class DataNode {
|
||||
protected MetaNode metadata;
|
||||
protected Node node;
|
||||
protected DataNode parent;
|
||||
protected DataConfiguration owner;
|
||||
private HashSet<DataNode> dependencies = null;
|
||||
|
||||
public DataNode(MetaNode metadata, Node node) throws DataException {
|
||||
if(metadata == null){
|
||||
throw new DataException("Invalid metadata.");
|
||||
} else if(node == null){
|
||||
throw new DataException("Invalid data.");
|
||||
}
|
||||
this.metadata = metadata;
|
||||
this.node = node;
|
||||
this.parent = null;
|
||||
this.owner = null;
|
||||
}
|
||||
|
||||
public void addDependency(DataNode dv) {
|
||||
if (dependencies == null) {
|
||||
dependencies = new HashSet<DataNode>();
|
||||
}
|
||||
dependencies.add(dv);
|
||||
}
|
||||
|
||||
public HashSet<DataNode> getDependencies() {
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
public MetaNode getMetadata() {
|
||||
return this.metadata;
|
||||
}
|
||||
|
||||
public Node getNode() {
|
||||
return this.node;
|
||||
}
|
||||
|
||||
public DataConfiguration getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
public void setOwner(DataConfiguration owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
protected void setParent(DataNode node){
|
||||
this.parent = node;
|
||||
}
|
||||
|
||||
public DataNode getParent(){
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,296 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.data;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.eclipse.cyclonedds.config.meta.MetaConfiguration;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValue;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValueBoolean;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValueDouble;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValueEnum;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValueFloat;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValueInt;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValueLong;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValueNatural;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValueSize;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValueString;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
public class DataValue extends DataNode {
|
||||
private Object value;
|
||||
private HashSet<DataValue> DVdependencies = null;
|
||||
|
||||
public DataValue(MetaValue metadata, Attr parent, Object value) throws DataException {
|
||||
super(metadata, parent);
|
||||
this.setValue(value);
|
||||
}
|
||||
|
||||
public DataValue(MetaValue metadata, Text text) throws DataException {
|
||||
super(metadata, text);
|
||||
this.setValue(this.node.getNodeValue());
|
||||
}
|
||||
|
||||
public Object getValue(){
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void addDataValueDependency(DataValue dv) {
|
||||
if (DVdependencies == null) {
|
||||
DVdependencies = new HashSet<DataValue>();
|
||||
}
|
||||
DVdependencies.add(dv);
|
||||
}
|
||||
|
||||
public HashSet<DataValue> getDataValueDependencies() {
|
||||
return DVdependencies;
|
||||
}
|
||||
|
||||
public void testSetValue(Object value) throws DataException {
|
||||
try{
|
||||
if (!isEnvironmentVar(value)) {
|
||||
if(this.metadata instanceof MetaValueBoolean){
|
||||
if(value instanceof String){
|
||||
this.value = Boolean.parseBoolean((String)value);
|
||||
} else if(!(value instanceof Boolean)){
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
} else if(this.metadata instanceof MetaValueDouble){
|
||||
Double tempValue;
|
||||
MetaValueNatural mv = (MetaValueNatural)this.metadata;
|
||||
|
||||
if(value instanceof String){
|
||||
tempValue = Double.parseDouble((String)value);
|
||||
} else if(!(value instanceof Double)){
|
||||
throw new NumberFormatException();
|
||||
} else {
|
||||
tempValue = (Double)value;
|
||||
}
|
||||
Object min = mv.getMinValue();
|
||||
Object max = mv.getMaxValue();
|
||||
|
||||
if(tempValue.compareTo((Double)min) < 0){
|
||||
throw new DataException("<" + this.node.getParentNode().getNodeName() + "> Value: " + tempValue
|
||||
+ "<" + min);
|
||||
} else if(tempValue.compareTo((Double)max) > 0){
|
||||
throw new DataException("<" + this.node.getParentNode().getNodeName() + "> Value: " + tempValue
|
||||
+ ">" + max);
|
||||
}
|
||||
} else if(this.metadata instanceof MetaValueEnum){
|
||||
if(value instanceof String){
|
||||
String tmp;
|
||||
String[] values = ((MetaValueEnum)this.metadata).getPosValues();
|
||||
boolean valid = false;
|
||||
|
||||
for(int i=0; i<values.length && !valid; i++){
|
||||
tmp = values[i];
|
||||
|
||||
if(tmp.equalsIgnoreCase((String)value)){
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!valid){
|
||||
throw new DataException("Illegal Enum value found: " + value);
|
||||
}
|
||||
} else {
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
} else if(this.metadata instanceof MetaValueFloat){
|
||||
Float tempValue;
|
||||
MetaValueNatural mv = (MetaValueNatural)this.metadata;
|
||||
|
||||
if(value instanceof String){
|
||||
tempValue = Float.parseFloat((String)value);
|
||||
} else if(!(value instanceof Float)){
|
||||
throw new NumberFormatException();
|
||||
} else {
|
||||
tempValue = (Float)value;
|
||||
}
|
||||
Object min = mv.getMinValue();
|
||||
Object max = mv.getMaxValue();
|
||||
|
||||
if(tempValue.compareTo((Float)min) < 0){
|
||||
throw new DataException("<" + this.node.getParentNode().getNodeName() + "> Value: " + tempValue
|
||||
+ " < " + min);
|
||||
} else if(tempValue.compareTo((Float)max) > 0){
|
||||
throw new DataException("<" + this.node.getParentNode().getNodeName() + "> Value: " + tempValue
|
||||
+ " > " + max);
|
||||
}
|
||||
} else if(this.metadata instanceof MetaValueInt){
|
||||
Integer tempValue;
|
||||
MetaValueNatural mv = (MetaValueNatural)this.metadata;
|
||||
|
||||
if(value instanceof String){
|
||||
tempValue = Integer.parseInt((String)value);
|
||||
} else if(!(value instanceof Integer)){
|
||||
throw new NumberFormatException();
|
||||
} else {
|
||||
tempValue = (Integer)value;
|
||||
}
|
||||
Object min = mv.getMinValue();
|
||||
Object max = mv.getMaxValue();
|
||||
|
||||
if(tempValue.compareTo((Integer)min) < 0){
|
||||
throw new DataException("<" + this.node.getParentNode().getNodeName() + "> Value: " + tempValue
|
||||
+ "<" + min);
|
||||
} else if(tempValue.compareTo((Integer)max) > 0){
|
||||
throw new DataException("<" + this.node.getParentNode().getNodeName() + "> Value: " + tempValue
|
||||
+ ">" + max);
|
||||
}
|
||||
} else if(this.metadata instanceof MetaValueLong){
|
||||
Long tempValue;
|
||||
MetaValueNatural mv = (MetaValueNatural)this.metadata;
|
||||
|
||||
if(value instanceof String){
|
||||
tempValue = Long.parseLong((String)value);
|
||||
} else if(!(value instanceof Long)){
|
||||
throw new NumberFormatException();
|
||||
} else {
|
||||
tempValue = (Long)value;
|
||||
}
|
||||
Object min = mv.getMinValue();
|
||||
Object max = mv.getMaxValue();
|
||||
|
||||
if(tempValue.compareTo((Long)min) < 0){
|
||||
throw new DataException("<" + this.node.getParentNode().getNodeName() + "> Value: " + tempValue
|
||||
+ "<" + min);
|
||||
} else if(tempValue.compareTo((Long)max) > 0){
|
||||
throw new DataException("<" + this.node.getParentNode().getNodeName() + "> Value: " + tempValue
|
||||
+ ">" + max);
|
||||
}
|
||||
} else if(this.metadata instanceof MetaValueSize){
|
||||
Long tempValue;
|
||||
MetaValueNatural mv = (MetaValueNatural)this.metadata;
|
||||
|
||||
if(value instanceof String){
|
||||
tempValue = MetaConfiguration.createLongValuefromSizeValue((String)value);
|
||||
} else if(!(value instanceof Long)){
|
||||
throw new NumberFormatException();
|
||||
} else {
|
||||
tempValue = (Long)value;
|
||||
}
|
||||
Object min = mv.getMinValue();
|
||||
Object max = mv.getMaxValue();
|
||||
|
||||
if(tempValue.compareTo((Long)min) < 0){
|
||||
throw new DataException("<" + this.node.getParentNode().getNodeName() + "> Value: " + tempValue
|
||||
+ "<" + min);
|
||||
} else if(tempValue.compareTo((Long)max) > 0){
|
||||
throw new DataException("<" + this.node.getParentNode().getNodeName() + "> Value: " + tempValue
|
||||
+ ">" + max);
|
||||
}
|
||||
} else if(this.metadata instanceof MetaValueString){
|
||||
if(value instanceof String){
|
||||
String strValue = (String)value;
|
||||
|
||||
if(strValue.startsWith("${") && strValue.endsWith("}")){
|
||||
/*Environment variable, this is ok*/
|
||||
} else {
|
||||
int length = strValue.length();
|
||||
int maxLength = ((MetaValueString)this.metadata).getMaxLength();
|
||||
|
||||
if((maxLength != 0) && (length > maxLength)){
|
||||
throw new DataException("<" + this.node.getParentNode().getNodeName() + "> String length: "
|
||||
+ length + ">" + maxLength);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* check if we got a domain service name element of service
|
||||
* tag name element
|
||||
*/
|
||||
if (this.getOwner() != null && this.getOwner().getServiceNames().contains(this)) {
|
||||
if (!this.getValue().equals(value)) {
|
||||
for (DataValue dv : this.getOwner().getServiceNames()) {
|
||||
if (dv.getValue().equals(value)) {
|
||||
throw new DataException("Name [" + value + "] is already used by another service");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(value == null){
|
||||
throw new DataException("Null pointer string");
|
||||
} else {
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
} else {
|
||||
throw new DataException("Found unknown metadata." +
|
||||
this.metadata.getClass().toString().substring(
|
||||
this.metadata.getClass().toString().lastIndexOf(
|
||||
'.') + 10));
|
||||
}
|
||||
}
|
||||
} catch(NumberFormatException nfe){
|
||||
if(value == null){
|
||||
throw new DataException("Found null pointer for data.");
|
||||
}
|
||||
throw new DataException("Expected '"
|
||||
+ this.metadata
|
||||
.getClass()
|
||||
.toString()
|
||||
.substring(
|
||||
this.metadata.getClass().toString()
|
||||
.lastIndexOf('.') + 10)
|
||||
+ "', but found '"
|
||||
+ value.getClass()
|
||||
.toString()
|
||||
.substring(
|
||||
value.getClass().toString()
|
||||
.lastIndexOf('.') + 1) + "'.");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEnvironmentVar(Object value) {
|
||||
boolean result = false;
|
||||
if (value instanceof String && ((String) value).startsWith("${") && ((String) value).endsWith("}")) {
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setValue(Object value) throws DataException {
|
||||
this.testSetValue(value);
|
||||
|
||||
this.value = value;
|
||||
/*testSetValue succeeded*/
|
||||
if(this.node instanceof Attr){
|
||||
((Attr)this.node).setValue(this.value.toString());
|
||||
} else if(this.node instanceof Text){
|
||||
((Text)this.node).replaceWholeText(this.value.toString());
|
||||
}
|
||||
|
||||
if (DVdependencies != null) {
|
||||
for (DataValue dv : DVdependencies) {
|
||||
Object oldValue = dv.getValue();
|
||||
dv.value = value;
|
||||
/* testSetValue succeeded */
|
||||
if (dv.node instanceof Attr) {
|
||||
((Attr) dv.node).setValue(dv.value.toString());
|
||||
} else if (dv.node instanceof Text) {
|
||||
((Text) dv.node).replaceWholeText(dv.value.toString());
|
||||
}
|
||||
dv.getOwner().notifyValueChanged(dv, oldValue, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void resetValue(){
|
||||
try {
|
||||
this.setValue(((MetaValue)this.metadata).getDefaultValue());
|
||||
} catch (DataException e) {
|
||||
assert false: "Default value cannot be applied.";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
public class MetaAttribute extends MetaNode {
|
||||
private String name;
|
||||
private boolean required;
|
||||
private MetaValue value;
|
||||
|
||||
public MetaAttribute(String doc, String name, boolean required,
|
||||
MetaValue value, String version, String dimension) {
|
||||
super(doc, version, dimension);
|
||||
this.name = name;
|
||||
this.required = required;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean isRequired(){
|
||||
return this.required;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public MetaValue getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(MetaValue value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object){
|
||||
MetaAttribute ma;
|
||||
boolean result;
|
||||
|
||||
if(object instanceof MetaAttribute){
|
||||
ma = (MetaAttribute)object;
|
||||
|
||||
if(this.name.equals(ma.getName())){
|
||||
if(this.required == ma.isRequired()){
|
||||
if(this.value.equals(ma.getValue())){
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int var_gen_code;
|
||||
int hash = 13;
|
||||
var_gen_code = required ? 1 : 0;
|
||||
var_gen_code += (null == value ? 0 : value.hashCode());
|
||||
var_gen_code += (null == name ? 0 : name.hashCode());
|
||||
hash = 31 * hash + var_gen_code;
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
String result = "";
|
||||
result += "\nAttribute\n";
|
||||
result += "-Name: " + this.name + "\n";
|
||||
result += "-Required: " + this.required + "\n";
|
||||
result += "-Version: " + this.version + "\n";
|
||||
result += "-Value: " + value.toString();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MetaElement extends MetaNode {
|
||||
private String name;
|
||||
private int minOccurrences;
|
||||
private int maxOccurrences;
|
||||
private ArrayList<MetaNode> children;
|
||||
|
||||
public MetaElement(String doc, String name, int minOccurrences,
|
||||
int maxOccurrences, ArrayList<MetaNode> children, String version,
|
||||
String dimension) {
|
||||
super(doc, version, dimension);
|
||||
this.name = name;
|
||||
this.minOccurrences = minOccurrences;
|
||||
this.maxOccurrences = maxOccurrences;
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public int getMaxOccurrences() {
|
||||
return this.maxOccurrences;
|
||||
}
|
||||
|
||||
public int getMinOccurrences() {
|
||||
return this.minOccurrences;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean addChild(MetaNode child){
|
||||
return this.children.add(child);
|
||||
}
|
||||
|
||||
public boolean removeChild(MetaNode child){
|
||||
return this.children.remove(child);
|
||||
}
|
||||
|
||||
public MetaNode[] getChildren(){
|
||||
return this.children.toArray(new MetaNode[this.children.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object){
|
||||
boolean result;
|
||||
MetaElement me;
|
||||
|
||||
if(object instanceof MetaElement){
|
||||
me = (MetaElement)object;
|
||||
|
||||
if(this.name.equals(me.getName())){
|
||||
MetaNode[] meChildren = me.getChildren();
|
||||
MetaNode[] children = this.getChildren();
|
||||
|
||||
if(this.maxOccurrences != me.getMaxOccurrences()){
|
||||
result = false;
|
||||
} else if(this.minOccurrences != me.getMinOccurrences()){
|
||||
result = false;
|
||||
} else if(meChildren.length != children.length){
|
||||
result = false;
|
||||
} else {
|
||||
result = true;
|
||||
|
||||
for(int i=0; i<children.length && result; i++){
|
||||
if(!(meChildren[i].equals(children[i]))){
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int var_gen_code;
|
||||
int hash = 13;
|
||||
var_gen_code = minOccurrences;
|
||||
var_gen_code += maxOccurrences;
|
||||
var_gen_code += (null == children ? 0 : children.hashCode());
|
||||
var_gen_code += (null == name ? 0 : name.hashCode());
|
||||
hash = 31 * hash + var_gen_code;
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("\nElement\n");
|
||||
buf.append("-Name: " + this.name + "\n");
|
||||
buf.append("-Version: " + this.version + "\n");
|
||||
buf.append("-MinOcccurrences: " + this.minOccurrences + "\n");
|
||||
buf.append("-MaxOcccurrences: " + this.maxOccurrences + "\n");
|
||||
if(this.children.size() > 0){
|
||||
buf.append("-Children: ");
|
||||
for(MetaNode child: children){
|
||||
buf.append(child.toString().replaceAll("\n", "\n\t"));
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public boolean hasElementChildren(){
|
||||
for(MetaNode mn: this.getChildren()){
|
||||
if(mn instanceof MetaElement){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasValueChildren(){
|
||||
for(MetaNode mn: this.getChildren()){
|
||||
if(mn instanceof MetaValue){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
public class MetaException extends Exception {
|
||||
private static final long serialVersionUID = 4459748108068852410L;
|
||||
private MetaExceptionType type;
|
||||
|
||||
public MetaException(String message, MetaExceptionType type) {
|
||||
super(message);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public MetaException(String message) {
|
||||
super(message);
|
||||
this.type = MetaExceptionType.META_ERROR;
|
||||
}
|
||||
|
||||
public MetaExceptionType getType() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
public enum MetaExceptionType {
|
||||
META_ERROR, META_UNSUPPORTED, META_CONFIG_PARSE_ERROR
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
public abstract class MetaNode {
|
||||
String doc;
|
||||
String version;
|
||||
String dimension;
|
||||
|
||||
public MetaNode(String doc, String version, String dimension) {
|
||||
this.doc = doc;
|
||||
this.version = version;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
public String getDoc() {
|
||||
return doc;
|
||||
}
|
||||
|
||||
public void setDoc(String doc) {
|
||||
this.doc = doc;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public String getDimension() {
|
||||
return this.dimension;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
import org.eclipse.cyclonedds.common.util.ConfigModeIntializer;
|
||||
|
||||
public abstract class MetaValue extends MetaNode {
|
||||
Object defaultValue;
|
||||
|
||||
public MetaValue(String doc, Object defaultValue, String dimension) {
|
||||
super(doc, ConfigModeIntializer.COMMUNITY, dimension);
|
||||
this.defaultValue = defaultValue;
|
||||
|
||||
}
|
||||
|
||||
public Object getDefaultValue() {
|
||||
return this.defaultValue;
|
||||
}
|
||||
|
||||
public abstract boolean setDefaultValue(Object defaultValue);
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "Value (" + defaultValue.getClass().toString().substring(defaultValue.getClass().toString().lastIndexOf('.') + 1) + ") DefaultValue: " + defaultValue.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object){
|
||||
boolean result;
|
||||
MetaValue mv;
|
||||
|
||||
if(object instanceof MetaValue){
|
||||
mv = (MetaValue)object;
|
||||
if((this.defaultValue == null) || (mv.getDefaultValue() == null)){
|
||||
if(this.defaultValue != mv.getDefaultValue()){
|
||||
result = false;
|
||||
} else {
|
||||
result = true;
|
||||
}
|
||||
} else if(this.defaultValue.equals(mv.getDefaultValue())){
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int var_gen_code;
|
||||
int hash = 13;
|
||||
var_gen_code = (null == defaultValue ? 0 : defaultValue.hashCode());
|
||||
hash = 31 * hash + var_gen_code;
|
||||
return hash;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
public class MetaValueBoolean extends MetaValue {
|
||||
|
||||
public MetaValueBoolean(String doc, Boolean defaultValue, String dimension) {
|
||||
super(doc, defaultValue, dimension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDefaultValue(Object defaultValue) {
|
||||
boolean result = false;
|
||||
|
||||
if(defaultValue instanceof Boolean){
|
||||
this.defaultValue = defaultValue;
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
public class MetaValueDouble extends MetaValueNatural {
|
||||
public MetaValueDouble(String doc, Double defaultValue, Double maxValue,
|
||||
Double minValue, String dimension) {
|
||||
super(doc, defaultValue, maxValue, minValue, dimension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMaxValue(Object maxValue) {
|
||||
boolean result;
|
||||
|
||||
if(maxValue instanceof Double){
|
||||
this.maxValue = maxValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMinValue(Object minValue) {
|
||||
boolean result;
|
||||
|
||||
if(minValue instanceof Double){
|
||||
this.minValue = minValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDefaultValue(Object defaultValue) {
|
||||
boolean result;
|
||||
|
||||
if(defaultValue instanceof Double){
|
||||
this.defaultValue = defaultValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MetaValueEnum extends MetaValue {
|
||||
private ArrayList<String> posValues;
|
||||
|
||||
public MetaValueEnum(String doc, String defaultValue,
|
||||
ArrayList<String> posValues, String dimension) {
|
||||
super(doc, defaultValue, dimension);
|
||||
assert(defaultValue != null);
|
||||
|
||||
this.posValues = new ArrayList<String>();
|
||||
|
||||
if(posValues != null){
|
||||
this.posValues.addAll(posValues);
|
||||
}
|
||||
|
||||
if(!this.posValues.contains(defaultValue)){
|
||||
this.posValues.add(defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getPosValues() {
|
||||
return this.posValues.toArray(new String[this.posValues.size()]);
|
||||
}
|
||||
|
||||
public boolean setPosValues(ArrayList<String> posValues) {
|
||||
boolean result;
|
||||
|
||||
if((posValues != null) && (posValues.size() > 0)){
|
||||
this.posValues.clear();
|
||||
this.posValues.addAll(posValues);
|
||||
|
||||
if(!posValues.contains(defaultValue)){
|
||||
this.defaultValue = this.posValues.get(0);
|
||||
}
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean addPosValue(String value){
|
||||
return this.posValues.add(value);
|
||||
}
|
||||
|
||||
public boolean removePosValue(String value){
|
||||
boolean result;
|
||||
|
||||
if(!defaultValue.equals(value)){
|
||||
result = this.posValues.remove(value);
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDefaultValue(Object defaultValue) {
|
||||
boolean result = false;
|
||||
|
||||
if(defaultValue instanceof String){
|
||||
this.defaultValue = defaultValue;
|
||||
|
||||
if(!this.posValues.contains(defaultValue)){
|
||||
result = this.addPosValue((String)defaultValue);
|
||||
}
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int var_gen_code;
|
||||
int hash = 13;
|
||||
var_gen_code = (null == defaultValue ? 0 : defaultValue.hashCode());
|
||||
var_gen_code += (null == posValues ? 0 : posValues.hashCode());
|
||||
hash = 31 * hash + var_gen_code;
|
||||
return hash;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
public class MetaValueFloat extends MetaValueNatural {
|
||||
public MetaValueFloat(String doc, Float defaultValue, Float maxValue,
|
||||
Float minValue, String dimension) {
|
||||
super(doc, defaultValue, maxValue, minValue, dimension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMaxValue(Object maxValue) {
|
||||
boolean result;
|
||||
|
||||
if(maxValue instanceof Float){
|
||||
this.maxValue = maxValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMinValue(Object minValue) {
|
||||
boolean result;
|
||||
|
||||
if(minValue instanceof Float){
|
||||
this.minValue = minValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDefaultValue(Object defaultValue) {
|
||||
boolean result;
|
||||
|
||||
if(defaultValue instanceof Float){
|
||||
this.defaultValue = defaultValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
public class MetaValueInt extends MetaValueNatural {
|
||||
|
||||
public MetaValueInt(String doc, Integer defaultValue, Integer maxValue,
|
||||
Integer minValue, String dimension) {
|
||||
super(doc, defaultValue, maxValue, minValue, dimension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMaxValue(Object maxValue) {
|
||||
boolean result;
|
||||
|
||||
if(maxValue instanceof Integer){
|
||||
this.maxValue = maxValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMinValue(Object minValue) {
|
||||
boolean result;
|
||||
|
||||
if(minValue instanceof Integer){
|
||||
this.minValue = minValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDefaultValue(Object defaultValue) {
|
||||
boolean result;
|
||||
|
||||
if(defaultValue instanceof Integer){
|
||||
this.defaultValue = defaultValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
public class MetaValueLong extends MetaValueNatural {
|
||||
public MetaValueLong(String doc, Long defaultValue, Long maxValue,
|
||||
Long minValue, String dimension) {
|
||||
super(doc, defaultValue, maxValue, minValue, dimension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMaxValue(Object maxValue) {
|
||||
boolean result;
|
||||
|
||||
if(maxValue instanceof Long){
|
||||
this.maxValue = maxValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMinValue(Object minValue) {
|
||||
boolean result;
|
||||
|
||||
if(minValue instanceof Long){
|
||||
this.minValue = minValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDefaultValue(Object defaultValue) {
|
||||
boolean result;
|
||||
|
||||
if(defaultValue instanceof Long){
|
||||
this.defaultValue = defaultValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
public abstract class MetaValueNatural extends MetaValue {
|
||||
Object maxValue;
|
||||
Object minValue;
|
||||
|
||||
public MetaValueNatural(String doc, Object defaultValue, Object maxValue,
|
||||
Object minValue, String dimension) {
|
||||
super(doc, defaultValue, dimension);
|
||||
this.minValue = minValue;
|
||||
this.maxValue = maxValue;
|
||||
}
|
||||
|
||||
public Object getMaxValue() {
|
||||
return this.maxValue;
|
||||
}
|
||||
|
||||
public Object getMinValue() {
|
||||
return this.minValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object){
|
||||
MetaValueNatural mn;
|
||||
boolean result = super.equals(object);
|
||||
|
||||
if(result){
|
||||
if(object instanceof MetaValueNatural){
|
||||
mn = (MetaValueNatural)object;
|
||||
|
||||
if((mn.getMaxValue() == null) && (this.maxValue != null)){
|
||||
result = false;
|
||||
} else if((mn.getMaxValue() != null) && (this.maxValue == null)){
|
||||
result = false;
|
||||
} else if( ((mn.getMaxValue() == null) && (this.maxValue == null)) ||
|
||||
((mn.getMaxValue().equals(this.maxValue))))
|
||||
{
|
||||
if((mn.getMinValue() == null) && (this.minValue != null)){
|
||||
result = false;
|
||||
} else if((mn.getMinValue() != null) && (this.minValue == null)){
|
||||
result = false;
|
||||
} else if( ((mn.getMinValue() == null) && (this.minValue == null)) ||
|
||||
((mn.getMinValue().equals(this.minValue))))
|
||||
{
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int var_gen_code;
|
||||
int hash = 13;
|
||||
var_gen_code = (null == maxValue ? 0 : maxValue.hashCode());
|
||||
var_gen_code += (null == minValue ? 0 : minValue.hashCode());
|
||||
hash = 31 * hash + var_gen_code;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public abstract boolean setMaxValue(Object maxValue);
|
||||
|
||||
public abstract boolean setMinValue(Object minValue);
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
String result = super.toString();
|
||||
|
||||
result += ", MaxValue: " + maxValue.toString() + ", MinValue: " + minValue.toString();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
public class MetaValueSize extends MetaValueNatural {
|
||||
public MetaValueSize(String doc, Long defaultValue, Long maxValue,
|
||||
Long minValue, String dimension) {
|
||||
super(doc, defaultValue, maxValue, minValue, dimension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMaxValue(Object maxValue) {
|
||||
boolean result;
|
||||
|
||||
if(maxValue instanceof Long){
|
||||
this.maxValue = maxValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMinValue(Object minValue) {
|
||||
boolean result;
|
||||
|
||||
if(minValue instanceof Long){
|
||||
this.minValue = minValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDefaultValue(Object defaultValue) {
|
||||
boolean result;
|
||||
|
||||
if(defaultValue instanceof Long){
|
||||
this.defaultValue = defaultValue;
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.meta;
|
||||
|
||||
public class MetaValueString extends MetaValue {
|
||||
private int maxLength;
|
||||
|
||||
public MetaValueString(String doc, String defaultValue, int maxLength,
|
||||
String dimension) {
|
||||
super(doc, defaultValue, dimension);
|
||||
this.maxLength = maxLength;
|
||||
}
|
||||
|
||||
public int getMaxLength() {
|
||||
return this.maxLength;
|
||||
}
|
||||
|
||||
public void setMaxLength(int maxLength) {
|
||||
this.maxLength = maxLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDefaultValue(Object defaultValue) {
|
||||
boolean result = false;
|
||||
|
||||
if(defaultValue instanceof String){
|
||||
this.defaultValue = defaultValue;
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int var_gen_code;
|
||||
int hash = 13;
|
||||
var_gen_code = (null == defaultValue ? 0 : defaultValue.hashCode());
|
||||
var_gen_code += maxLength;
|
||||
hash = 31 * hash + var_gen_code;
|
||||
return hash;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.TransferHandler;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class ConfigTransferHandler extends TransferHandler {
|
||||
private final ConfigWindow view;
|
||||
|
||||
public ConfigTransferHandler(ConfigWindow view){
|
||||
this.view = view;
|
||||
}
|
||||
@Override
|
||||
public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
|
||||
for(DataFlavor flavor: transferFlavors){
|
||||
if(flavor.equals(DataFlavor.javaFileListFlavor)){
|
||||
view.setStatus("Drag here to open " +
|
||||
flavor.getHumanPresentableName() + " file.", false);
|
||||
return true;
|
||||
} else if(flavor.equals(DataFlavor.stringFlavor)){
|
||||
view.setStatus("Drag here to open " +
|
||||
flavor.getHumanPresentableName() + " file.", false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
view.setStatus("Warning: Unsupported type.", false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean importData(JComponent comp, Transferable t) {
|
||||
if (!canImport(comp, t.getTransferDataFlavors())) {
|
||||
view.setStatus("Warning: Unsupported type", false);
|
||||
return false;
|
||||
}
|
||||
try{
|
||||
if(t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)){
|
||||
@SuppressWarnings("unchecked")
|
||||
List<File> files = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
|
||||
|
||||
if(files.size() == 1){
|
||||
File file = files.get(0);
|
||||
view.getController().handleOpen(file);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if(t.isDataFlavorSupported(DataFlavor.stringFlavor)){
|
||||
String str = (String) t.getTransferData(DataFlavor.stringFlavor);
|
||||
|
||||
if(str.startsWith("file:/")){
|
||||
File f = new File(new URI(str));
|
||||
view.getController().handleOpen(f);
|
||||
} else {
|
||||
view.setStatus("Warning: Unsupported file.", false);
|
||||
}
|
||||
} else {
|
||||
view.setStatus("Warning: Unsupported drag-and-drop type", false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
view.setStatus("Warning: " + e.getMessage(), false);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import org.eclipse.cyclonedds.config.data.DataAttribute;
|
||||
import org.eclipse.cyclonedds.config.data.DataElement;
|
||||
import org.eclipse.cyclonedds.config.data.DataNode;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaAttribute;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaElement;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaNode;
|
||||
|
||||
public class ConfigUtil {
|
||||
public static String getExtendedDataElementString(DataElement element){
|
||||
String firstAttrChild;
|
||||
DataNode[] children;
|
||||
String name;
|
||||
String result = null;
|
||||
|
||||
if(element != null){
|
||||
children = element.getChildren();
|
||||
firstAttrChild = null;
|
||||
|
||||
for(int j=0; (j<children.length) && (firstAttrChild == null); j++){
|
||||
if(children[j] instanceof DataAttribute){
|
||||
name = ((MetaAttribute)children[j].getMetadata()).getName();
|
||||
|
||||
if("name".equalsIgnoreCase(name)){
|
||||
firstAttrChild = "[" + ((MetaAttribute)children[j].getMetadata()).getName() + "=";
|
||||
firstAttrChild += ((DataAttribute)children[j]).getValue() + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int j=0; (j<children.length) && (firstAttrChild == null); j++){
|
||||
if(children[j] instanceof DataAttribute){
|
||||
firstAttrChild = "[" + ((MetaAttribute)children[j].getMetadata()).getName() + "=";
|
||||
firstAttrChild += ((DataAttribute)children[j]).getValue() + "]";
|
||||
}
|
||||
}
|
||||
if(firstAttrChild == null){
|
||||
firstAttrChild = "";
|
||||
}
|
||||
result = ((MetaElement)element.getMetadata()).getName() + firstAttrChild;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getDataElementString(DataElement element){
|
||||
String result = null;
|
||||
|
||||
if(element != null){
|
||||
result = ((MetaElement)element.getMetadata()).getName();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getExtendedMetaElementString(MetaElement element){
|
||||
String firstAttrChild;
|
||||
MetaNode[] children;
|
||||
String result = null;
|
||||
|
||||
if(element != null){
|
||||
children = element.getChildren();
|
||||
firstAttrChild = null;
|
||||
|
||||
for(int j=0; (j<children.length) && (firstAttrChild == null); j++){
|
||||
if(children[j] instanceof MetaAttribute){
|
||||
firstAttrChild = "[" + ((MetaAttribute)children[j]).getName() + "]";
|
||||
}
|
||||
}
|
||||
if(firstAttrChild == null){
|
||||
firstAttrChild = "";
|
||||
}
|
||||
result = element.getName() + firstAttrChild;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getMetaElementString(MetaElement element){
|
||||
String result = null;
|
||||
|
||||
if(element != null){
|
||||
result = element.getName();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,667 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Event;
|
||||
import java.awt.Image;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.eclipse.cyclonedds.common.util.ConfigModeIntializer;
|
||||
import org.eclipse.cyclonedds.common.view.MainWindow;
|
||||
import org.eclipse.cyclonedds.common.view.StatusPanel;
|
||||
import org.eclipse.cyclonedds.config.data.DataConfiguration;
|
||||
import org.eclipse.cyclonedds.config.data.DataConfigurationListener;
|
||||
import org.eclipse.cyclonedds.config.data.DataElement;
|
||||
import org.eclipse.cyclonedds.config.data.DataNode;
|
||||
import org.eclipse.cyclonedds.config.data.DataValue;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaElement;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaNode;
|
||||
|
||||
public class ConfigWindow extends MainWindow implements DataConfigurationListener {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanel jContentPane = null;
|
||||
private ConfigWindowController controller = null;
|
||||
private JMenuBar configMenuBar = null;
|
||||
private JTabbedPane mainTabbedPane = null;
|
||||
private JMenu fileMenu = null;
|
||||
private JMenu editMenu = null;
|
||||
private JMenu addServiceMenu = null;
|
||||
private JMenu removeServiceMenu = null;
|
||||
private JMenuItem newItem = null;
|
||||
private JMenuItem openItem = null;
|
||||
private JMenuItem saveItem = null;
|
||||
private JMenuItem closeItem = null;
|
||||
private JMenuItem saveAsItem = null;
|
||||
private JMenuItem exitItem = null;
|
||||
private JMenuItem printItem = null;
|
||||
private JMenu helpMenu = null;
|
||||
private JMenuItem helpContentsItem = null;
|
||||
private DataConfiguration config = null;
|
||||
private List<Image> appLogos = null;
|
||||
|
||||
|
||||
private DataNodePopup popupSupport = null;
|
||||
private ConfigTransferHandler transferHandler = null;
|
||||
|
||||
private String windowTitle = "Configurator";
|
||||
public static final String OSPL_WINDOW_TITLE = "Vortex OpenSplice Configurator";
|
||||
public static final String LITE_WINDOW_TITLE = "Vortex DDS Configurator";
|
||||
|
||||
public static final String OSPL_SERVICE_LABEL = "Service";
|
||||
public static final String LITE_SERVICE_LABEL = "Component";
|
||||
|
||||
public static String SERVICE_LABEL;
|
||||
public static String SERVICE_TEXT;
|
||||
|
||||
/**
|
||||
* This is the default constructor
|
||||
*/
|
||||
public ConfigWindow() {
|
||||
super();
|
||||
initialize();
|
||||
}
|
||||
|
||||
public ConfigWindow(String uri) {
|
||||
super();
|
||||
initialize();
|
||||
controller.handleOpenFromUri(uri);
|
||||
}
|
||||
|
||||
public DataConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void setDataConfiguration(DataConfiguration config){
|
||||
DataElement[] services;
|
||||
|
||||
if(this.config != null){
|
||||
this.config.removeDataConfigurationListener(this);
|
||||
int count = mainTabbedPane.getComponentCount();
|
||||
|
||||
for(int i=0; i < count; i++){
|
||||
mainTabbedPane.remove(0);
|
||||
}
|
||||
}
|
||||
this.config = config;
|
||||
|
||||
if(this.config != null){
|
||||
this.config.addDataConfigurationListener(this);
|
||||
services = config.getServices();
|
||||
|
||||
for(int i=0; i < services.length; i++){
|
||||
ServicePanel servicePanel = new ServicePanel(services[i], this.statusPanel);
|
||||
servicePanel.setTransferHandler(transferHandler);
|
||||
mainTabbedPane.addTab(
|
||||
ConfigUtil.getExtendedDataElementString(services[i]),
|
||||
servicePanel);
|
||||
}
|
||||
}
|
||||
this.updateMenus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nodeAdded(DataElement parent, DataNode nodeAdded) {
|
||||
this.updateMenus();
|
||||
|
||||
if(parent.equals(this.config.getRootElement())){
|
||||
if(nodeAdded instanceof DataElement){
|
||||
final DataElement service = (DataElement)nodeAdded;
|
||||
|
||||
Runnable worker = new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
ServicePanel servicePanel = new ServicePanel(service, statusPanel);
|
||||
servicePanel.setTransferHandler(transferHandler);
|
||||
mainTabbedPane.addTab(
|
||||
ConfigUtil.getExtendedDataElementString(service),
|
||||
servicePanel);
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(worker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nodeRemoved(DataElement parent, DataNode nodeRemoved) {
|
||||
this.updateMenus();
|
||||
|
||||
if(parent.equals(this.config.getRootElement())){
|
||||
if(nodeRemoved instanceof DataElement){
|
||||
final DataElement service = (DataElement)nodeRemoved;
|
||||
|
||||
Runnable worker = new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
ServicePanel servicePanel;
|
||||
boolean found = false;
|
||||
|
||||
for(int i=0; (i<mainTabbedPane.getTabCount()) && (!found); i++){
|
||||
servicePanel = (ServicePanel)mainTabbedPane.getComponentAt(i);
|
||||
|
||||
if(servicePanel.getService().equals(service)){
|
||||
mainTabbedPane.removeTabAt(i);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(worker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueChanged(DataValue data, Object oldValue, Object newValue) {
|
||||
ServicePanel servicePanel;
|
||||
|
||||
for(int i=0; i<this.mainTabbedPane.getTabCount(); i++){
|
||||
servicePanel = (ServicePanel)this.mainTabbedPane.getComponentAt(i);
|
||||
this.mainTabbedPane.setTitleAt(i,
|
||||
ConfigUtil.getExtendedDataElementString(
|
||||
servicePanel.getService()));
|
||||
}
|
||||
this.updateMenus();
|
||||
}
|
||||
|
||||
public DataConfiguration getDataConfiguration(){
|
||||
return this.config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableView(){
|
||||
ServicePanel sp;
|
||||
|
||||
this.setEnabled(false);
|
||||
this.setFocusable(false);
|
||||
|
||||
for(int i=0; i<this.mainTabbedPane.getComponentCount(); i++){
|
||||
sp = (ServicePanel)this.mainTabbedPane.getComponentAt(i);
|
||||
sp.getConfigurationTable().getEditor().stopCellEditing();
|
||||
}
|
||||
}
|
||||
|
||||
public void setActionsEnabled(boolean enabled){
|
||||
ServicePanel sp;
|
||||
if(enabled){
|
||||
this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
} else {
|
||||
this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
||||
}
|
||||
for(int i=0; i<this.mainTabbedPane.getComponentCount(); i++){
|
||||
sp = (ServicePanel)this.mainTabbedPane.getComponentAt(i);
|
||||
sp.setEnabled(enabled);
|
||||
}
|
||||
this.updateMenus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the view component.
|
||||
*/
|
||||
@Override
|
||||
public void enableView(){
|
||||
this.setFocusable(true);
|
||||
this.setEnabled(true);
|
||||
this.toFront();
|
||||
}
|
||||
|
||||
public ConfigWindowController getController(){
|
||||
return this.controller;
|
||||
}
|
||||
|
||||
public void setWindowTitle (int configMode) {
|
||||
if (configMode == ConfigModeIntializer.LITE_MODE) {
|
||||
this.windowTitle = LITE_WINDOW_TITLE;
|
||||
} else {
|
||||
this.windowTitle = OSPL_WINDOW_TITLE;
|
||||
}
|
||||
super.setTitle(this.windowTitle);
|
||||
}
|
||||
|
||||
private void updateMenus(){
|
||||
this.getAddServiceMenu().removeAll();
|
||||
this.getRemoveServiceMenu().removeAll();
|
||||
|
||||
if(this.config != null){
|
||||
if(this.config.isUpToDate()){
|
||||
this.getSaveItem().setEnabled(false);
|
||||
} else {
|
||||
this.getSaveItem().setEnabled(true);
|
||||
}
|
||||
this.getSaveAsItem().setEnabled(true);
|
||||
this.getPrintItem().setEnabled(true);
|
||||
this.getCloseItem().setEnabled(true);
|
||||
this.getAddServiceMenu().setEnabled(true);
|
||||
this.getRemoveServiceMenu().setEnabled(true);
|
||||
|
||||
MetaNode[] mn = ((MetaElement)config.getRootElement().getMetadata()).getChildren();
|
||||
|
||||
for(MetaNode m: mn){
|
||||
if(m instanceof MetaElement){
|
||||
this.getAddServiceMenu().add(this.getAddServiceItem((MetaElement)m));
|
||||
}
|
||||
}
|
||||
for(DataElement e: config.getServices()){
|
||||
this.getRemoveServiceMenu().add(this.getRemoveServiceItem(e));
|
||||
}
|
||||
} else {
|
||||
this.getSaveItem().setEnabled(false);
|
||||
this.getSaveAsItem().setEnabled(false);
|
||||
this.getPrintItem().setEnabled(false);
|
||||
this.getCloseItem().setEnabled(false);
|
||||
this.getAddServiceMenu().setEnabled(false);
|
||||
this.getRemoveServiceMenu().setEnabled(false);
|
||||
}
|
||||
this.updateTitle();
|
||||
}
|
||||
|
||||
private void updateTitle(){
|
||||
File f;
|
||||
String title;
|
||||
if(this.config != null){
|
||||
f = config.getFile();
|
||||
|
||||
if(f != null){
|
||||
title = this.windowTitle + " | " + f.getAbsolutePath();
|
||||
} else {
|
||||
title = this.windowTitle + " | <NoName>";
|
||||
}
|
||||
} else {
|
||||
title = this.windowTitle;
|
||||
}
|
||||
this.setTitle(title);
|
||||
}
|
||||
|
||||
private DataNodeMenuItem getAddServiceItem(MetaElement service){
|
||||
int curOcc = 0;
|
||||
DataNodeMenuItem item = new DataNodeMenuItem(
|
||||
service.getName(),
|
||||
this.config.getRootElement(), service);
|
||||
|
||||
for(DataElement s: config.getServices()){
|
||||
if(s.getMetadata().equals(service)){
|
||||
curOcc++;
|
||||
}
|
||||
}
|
||||
if(curOcc < service.getMaxOccurrences()){
|
||||
item.setEnabled(true);
|
||||
} else {
|
||||
item.setEnabled(false);
|
||||
}
|
||||
item.setActionCommand("addService");
|
||||
item.addActionListener(this.popupSupport);
|
||||
return item;
|
||||
}
|
||||
|
||||
private DataNodeMenuItem getRemoveServiceItem(DataElement service){
|
||||
int curOcc = 0;
|
||||
MetaElement metaService = (MetaElement)service.getMetadata();
|
||||
DataNodeMenuItem item = new DataNodeMenuItem(
|
||||
ConfigUtil.getExtendedDataElementString(service),
|
||||
service, null);
|
||||
|
||||
for(DataElement s: config.getServices()){
|
||||
if(s.getMetadata().equals(metaService)){
|
||||
curOcc++;
|
||||
}
|
||||
}
|
||||
if(curOcc > metaService.getMinOccurrences()){
|
||||
item.setEnabled(true);
|
||||
} else {
|
||||
item.setEnabled(false);
|
||||
}
|
||||
item.setActionCommand("removeService");
|
||||
item.addActionListener(this.popupSupport);
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes this
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private void initialize() {
|
||||
this.setSize(800, 600);
|
||||
this.controller = new ConfigWindowController(this);
|
||||
// setServiceLabel relies on the
|
||||
// ConfigModeIntializer.CONFIGURATOR_MODE variable which
|
||||
// has been set during construction of ConfigWndowController
|
||||
this.setServiceLabel();
|
||||
this.popupSupport = new DataNodePopup();
|
||||
this.transferHandler = new ConfigTransferHandler(this);
|
||||
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
this.setJMenuBar(getConfigMenuBar());
|
||||
this.setLocationRelativeTo(this.getParent());
|
||||
this.setContentPane(getJContentPane());
|
||||
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
controller.actionPerformed(
|
||||
new ActionEvent(exitItem, 0, "exit"));
|
||||
}
|
||||
});
|
||||
this.updateMenus();
|
||||
this.setAppLogo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the proper service label to be used throughout the configurator UI.
|
||||
* Ospl uses the label "Service" while Lite uses the label "Component"
|
||||
* (since the concept of service does not really exist)
|
||||
*
|
||||
*/
|
||||
private void setServiceLabel(){
|
||||
if (ConfigModeIntializer.CONFIGURATOR_MODE != ConfigModeIntializer.LITE_MODE){
|
||||
SERVICE_LABEL = OSPL_SERVICE_LABEL;
|
||||
SERVICE_TEXT = OSPL_SERVICE_LABEL.toLowerCase();
|
||||
} else {
|
||||
SERVICE_LABEL = LITE_SERVICE_LABEL;
|
||||
SERVICE_TEXT = LITE_SERVICE_LABEL.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes jContentPane
|
||||
*
|
||||
* @return javax.swing.JPanel
|
||||
*/
|
||||
private JPanel getJContentPane() {
|
||||
if (jContentPane == null) {
|
||||
jContentPane = new JPanel();
|
||||
jContentPane.setLayout(new BorderLayout());
|
||||
jContentPane.add(getMainTabbedPane(), BorderLayout.CENTER);
|
||||
jContentPane.add(getStatusPanel(), BorderLayout.SOUTH);
|
||||
}
|
||||
return jContentPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes statusPanel.
|
||||
*
|
||||
* @return The status panel of the window.
|
||||
*/
|
||||
@Override
|
||||
protected StatusPanel getStatusPanel() {
|
||||
if (statusPanel == null) {
|
||||
statusPanel = new StatusPanel(300, "Ready", false, true);
|
||||
}
|
||||
return statusPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes configMenuBar
|
||||
*
|
||||
* @return javax.swing.JMenuBar
|
||||
*/
|
||||
private JMenuBar getConfigMenuBar() {
|
||||
if (configMenuBar == null) {
|
||||
configMenuBar = new JMenuBar();
|
||||
configMenuBar.add(getFileMenu());
|
||||
configMenuBar.add(getEditMenu());
|
||||
configMenuBar.add(getHelpMenu());
|
||||
}
|
||||
return configMenuBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes mainTabbedPane
|
||||
*
|
||||
* @return javax.swing.JTabbedPane
|
||||
*/
|
||||
private JTabbedPane getMainTabbedPane() {
|
||||
if (mainTabbedPane == null) {
|
||||
mainTabbedPane = new JTabbedPane();
|
||||
mainTabbedPane.setTransferHandler(this.transferHandler);
|
||||
}
|
||||
return mainTabbedPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes fileMenu
|
||||
*
|
||||
* @return javax.swing.JMenu
|
||||
*/
|
||||
private JMenu getFileMenu() {
|
||||
if (fileMenu == null) {
|
||||
fileMenu = new JMenu();
|
||||
fileMenu.setText("File");
|
||||
fileMenu.setMnemonic(KeyEvent.VK_F);
|
||||
fileMenu.add(getNewItem());
|
||||
fileMenu.add(getOpenItem());
|
||||
fileMenu.add(getCloseItem());
|
||||
fileMenu.addSeparator();
|
||||
fileMenu.add(getSaveItem());
|
||||
fileMenu.add(getSaveAsItem());
|
||||
fileMenu.addSeparator();
|
||||
fileMenu.add(getPrintItem());
|
||||
fileMenu.addSeparator();
|
||||
fileMenu.add(getExitItem());
|
||||
}
|
||||
return fileMenu;
|
||||
}
|
||||
|
||||
private JMenu getEditMenu(){
|
||||
if (editMenu == null){
|
||||
editMenu = new JMenu();
|
||||
editMenu.setText("Edit");
|
||||
editMenu.setMnemonic(KeyEvent.VK_E);
|
||||
editMenu.add(getAddServiceMenu());
|
||||
editMenu.add(getRemoveServiceMenu());
|
||||
}
|
||||
return editMenu;
|
||||
}
|
||||
|
||||
private JMenu getHelpMenu(){
|
||||
if (helpMenu == null){
|
||||
helpMenu = new JMenu();
|
||||
helpMenu.setText("Help");
|
||||
helpMenu.setMnemonic(KeyEvent.VK_H);
|
||||
helpMenu.add(getHelpContentsItem());
|
||||
}
|
||||
return helpMenu;
|
||||
}
|
||||
|
||||
private JMenuItem getHelpContentsItem(){
|
||||
if (helpContentsItem == null){
|
||||
helpContentsItem = new JMenuItem();
|
||||
helpContentsItem.setText("Help Contents");
|
||||
helpContentsItem.setMnemonic(KeyEvent.VK_C);
|
||||
helpContentsItem.setActionCommand("help");
|
||||
helpContentsItem.addActionListener(getController());
|
||||
helpContentsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, Event.CTRL_MASK, false));
|
||||
}
|
||||
return helpContentsItem;
|
||||
}
|
||||
|
||||
private JMenu getAddServiceMenu(){
|
||||
if (addServiceMenu == null){
|
||||
addServiceMenu = new JMenu();
|
||||
addServiceMenu.setText("Add " + SERVICE_LABEL);
|
||||
addServiceMenu.setMnemonic(KeyEvent.VK_A);
|
||||
}
|
||||
return addServiceMenu;
|
||||
}
|
||||
|
||||
private JMenu getRemoveServiceMenu(){
|
||||
if (removeServiceMenu == null){
|
||||
removeServiceMenu = new JMenu();
|
||||
removeServiceMenu.setText("Remove " + SERVICE_LABEL);
|
||||
removeServiceMenu.setMnemonic(KeyEvent.VK_R);
|
||||
}
|
||||
return removeServiceMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes newItem
|
||||
*
|
||||
* @return javax.swing.JMenuItem
|
||||
*/
|
||||
private JMenuItem getNewItem() {
|
||||
if (newItem == null) {
|
||||
newItem = new JMenuItem();
|
||||
newItem.setText("New...");
|
||||
newItem.setMnemonic(KeyEvent.VK_N);
|
||||
newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK, false));
|
||||
newItem.setActionCommand("new");
|
||||
newItem.addActionListener(controller);
|
||||
}
|
||||
return newItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes openItem
|
||||
*
|
||||
* @return javax.swing.JMenuItem
|
||||
*/
|
||||
private JMenuItem getOpenItem() {
|
||||
if (openItem == null) {
|
||||
openItem = new JMenuItem();
|
||||
openItem.setText("Open...");
|
||||
openItem.setMnemonic(KeyEvent.VK_O);
|
||||
openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK, false));
|
||||
openItem.setActionCommand("open");
|
||||
openItem.addActionListener(controller);
|
||||
}
|
||||
return openItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes saveItem
|
||||
*
|
||||
* @return javax.swing.JMenuItem
|
||||
*/
|
||||
private JMenuItem getSaveItem() {
|
||||
if (saveItem == null) {
|
||||
saveItem = new JMenuItem();
|
||||
saveItem.setText("Save");
|
||||
saveItem.setMnemonic(KeyEvent.VK_S);
|
||||
saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK, false));
|
||||
saveItem.setActionCommand("save");
|
||||
saveItem.addActionListener(controller);
|
||||
}
|
||||
return saveItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes closeItem
|
||||
*
|
||||
* @return javax.swing.JMenuItem
|
||||
*/
|
||||
private JMenuItem getCloseItem() {
|
||||
if (closeItem == null) {
|
||||
closeItem = new JMenuItem();
|
||||
closeItem.setText("Close");
|
||||
closeItem.setMnemonic(KeyEvent.VK_C);
|
||||
closeItem.setActionCommand("close");
|
||||
closeItem.addActionListener(controller);
|
||||
}
|
||||
return closeItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes saveAsItem
|
||||
*
|
||||
* @return javax.swing.JMenuItem
|
||||
*/
|
||||
private JMenuItem getSaveAsItem() {
|
||||
if (saveAsItem == null) {
|
||||
saveAsItem = new JMenuItem();
|
||||
saveAsItem.setText("Save As...");
|
||||
saveAsItem.setMnemonic(KeyEvent.VK_A);
|
||||
saveAsItem.setActionCommand("save_as");
|
||||
saveAsItem.addActionListener(controller);
|
||||
}
|
||||
return saveAsItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes exitItem
|
||||
*
|
||||
* @return javax.swing.JMenuItem
|
||||
*/
|
||||
private JMenuItem getExitItem() {
|
||||
if (exitItem == null) {
|
||||
exitItem = new JMenuItem();
|
||||
exitItem.setText("Exit");
|
||||
exitItem.setMnemonic(KeyEvent.VK_X);
|
||||
exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, Event.ALT_MASK, false));
|
||||
exitItem.setActionCommand("exit");
|
||||
exitItem.addActionListener(controller);
|
||||
}
|
||||
return exitItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes printItem
|
||||
*
|
||||
* @return javax.swing.JMenuItem
|
||||
*/
|
||||
private JMenuItem getPrintItem() {
|
||||
if (printItem == null) {
|
||||
printItem = new JMenuItem();
|
||||
printItem.setText("Print...");
|
||||
printItem.setMnemonic(KeyEvent.VK_P);
|
||||
printItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK, false));
|
||||
printItem.setActionCommand("print");
|
||||
printItem.addActionListener(controller);
|
||||
}
|
||||
return printItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Logo image to be used in Configurator's window and taskbar button.
|
||||
*/
|
||||
private void setAppLogo() {
|
||||
if (appLogos == null) {
|
||||
try {
|
||||
List<URL> imgUrls = new ArrayList<URL>(4);
|
||||
// Expected location of the icons in tuner jar
|
||||
URL url = getClass().getResource("/resources/ptlogoc16.png");
|
||||
imgUrls.add(url != null ? url : getClass().getResource("/ptlogoc16.png"));
|
||||
url = getClass().getResource("/resources/ptlogoc24.png");
|
||||
imgUrls.add(url != null ? url : getClass().getResource("/ptlogoc24.png"));
|
||||
url = getClass().getResource("/resources/ptlogoc32.png");
|
||||
imgUrls.add(url != null ? url : getClass().getResource("/ptlogoc32.png"));
|
||||
url = getClass().getResource("/resources/ptlogoc48.png");
|
||||
imgUrls.add(url != null ? url : getClass().getResource("/ptlogoc48.png"));
|
||||
|
||||
appLogos = new ArrayList<Image>(4);
|
||||
for (URL imgUrl : imgUrls) {
|
||||
if (imgUrl != null) {
|
||||
appLogos.add(Toolkit.getDefaultToolkit().getImage(imgUrl));
|
||||
}
|
||||
}
|
||||
this.setIconImages(appLogos);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,658 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.print.PrinterJob;
|
||||
import java.io.File;
|
||||
|
||||
import javax.print.attribute.HashPrintRequestAttributeSet;
|
||||
import javax.print.attribute.PrintRequestAttributeSet;
|
||||
import javax.print.attribute.standard.Copies;
|
||||
import javax.print.attribute.standard.MediaSizeName;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import org.eclipse.cyclonedds.common.util.ConfigModeIntializer;
|
||||
import org.eclipse.cyclonedds.common.util.Report;
|
||||
import org.eclipse.cyclonedds.config.data.DataConfiguration;
|
||||
import org.eclipse.cyclonedds.config.data.DataException;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaConfiguration;
|
||||
|
||||
public class ConfigWindowController implements ActionListener {
|
||||
|
||||
|
||||
private final ConfigWindow view;
|
||||
private HelpWindow helpView;
|
||||
private boolean closeInProgress;
|
||||
private boolean exitInProgress;
|
||||
private boolean newInProgress;
|
||||
private boolean openInProgress;
|
||||
private File curFile;
|
||||
private final JFileChooser openFileChooser;
|
||||
private final JFileChooser saveFileChooser;
|
||||
|
||||
public ConfigWindowController(ConfigWindow view){
|
||||
this.view = view;
|
||||
this.closeInProgress = false;
|
||||
this.exitInProgress = false;
|
||||
this.newInProgress = false;
|
||||
this.openInProgress = false;
|
||||
this.openFileChooser = new JFileChooser();
|
||||
this.saveFileChooser = new JFileChooser();
|
||||
this.curFile = null;
|
||||
this.helpView = null;
|
||||
|
||||
// Initialize the MetaConfiguration. This is done so the Configurator can know for
|
||||
// which product its meant for, according to the meta config file.
|
||||
MetaConfiguration.getInstance();
|
||||
view.setWindowTitle(ConfigModeIntializer.CONFIGURATOR_MODE);
|
||||
|
||||
String osplHome = System.getenv("OSPL_HOME");
|
||||
File f = null;
|
||||
String fileSep = System.getProperty("file.separator");
|
||||
|
||||
if(osplHome == null){
|
||||
f = new File(System.getProperty("user.dir") + fileSep);
|
||||
} else {
|
||||
f = new File(osplHome + fileSep + "etc" + fileSep + "config" + fileSep);
|
||||
|
||||
if((!f.exists()) || (!f.isDirectory())){
|
||||
f = new File(osplHome + fileSep + "etc" + fileSep);
|
||||
|
||||
if((!f.exists()) || (!f.isDirectory())){
|
||||
f = new File(System.getProperty("user.dir") + fileSep);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.openFileChooser.setCurrentDirectory(f);
|
||||
this.openFileChooser.setDialogTitle("Open configuration");
|
||||
this.openFileChooser.setMultiSelectionEnabled(false);
|
||||
this.openFileChooser.setFileFilter(new ConfigChooseFilter());
|
||||
this.openFileChooser.setAcceptAllFileFilterUsed(false);
|
||||
this.openFileChooser.setApproveButtonText("Open");
|
||||
|
||||
this.saveFileChooser.setCurrentDirectory(f);
|
||||
this.saveFileChooser.setDialogTitle("Save configuration");
|
||||
this.saveFileChooser.setMultiSelectionEnabled(false);
|
||||
this.saveFileChooser.setFileFilter(new ConfigChooseFilter());
|
||||
this.saveFileChooser.setAcceptAllFileFilterUsed(false);
|
||||
this.saveFileChooser.setApproveButtonText("Save");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String command = e.getActionCommand();
|
||||
|
||||
try{
|
||||
if("exit".equals(command)){
|
||||
this.exitInProgress = true;
|
||||
this.handleConditionalSave();
|
||||
} else if("close".equals(command)){
|
||||
this.closeInProgress = true;
|
||||
this.handleConditionalSave();
|
||||
} else if("save".equals(command)){
|
||||
this.handleSave(false);
|
||||
} else if("save_as".equals(command)){
|
||||
this.handleSave(true);
|
||||
} else if("new".equals(command)){
|
||||
this.newInProgress = true;
|
||||
this.handleConditionalSave();
|
||||
} else if("open".equals(command)){
|
||||
this.openInProgress = true;
|
||||
this.handleConditionalSave();
|
||||
} else if("print".equals(command)){
|
||||
this.handlePrint();
|
||||
} else if("help".equals(command)){
|
||||
this.handleHelp();
|
||||
} else if("cancel".equals(command)){
|
||||
this.handleCancel();
|
||||
} else {
|
||||
this.handleSetStatus("Warning: Command '" + command + "' not implemented.", false, false);
|
||||
}
|
||||
} catch(Exception ex){
|
||||
this.handleSetStatus("Error: " + ex.getMessage(), false, false);
|
||||
this.printStackTrace(ex);
|
||||
this.handleSetEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleConditionalSave(){
|
||||
DataConfiguration config = view.getDataConfiguration();
|
||||
|
||||
if(config == null){
|
||||
this.handleNextAction();
|
||||
} else if(config.isUpToDate()){
|
||||
this.handleNextAction();
|
||||
} else {
|
||||
int answer = JOptionPane.showConfirmDialog(
|
||||
this.view,
|
||||
"Configuration has changed. Save changes?",
|
||||
"Close configuration",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION);
|
||||
|
||||
if(answer == JOptionPane.YES_OPTION){
|
||||
this.handleSave(false);
|
||||
} else if(answer == JOptionPane.NO_OPTION){
|
||||
this.handleNextAction();
|
||||
} else {
|
||||
this.handleCancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePrint(){
|
||||
final DataConfiguration config = view.getDataConfiguration();
|
||||
|
||||
if(config == null){
|
||||
this.handleSetStatus("No configuration to print.", false);
|
||||
} else {
|
||||
this.handleSetStatus("Printing configuration...", true);
|
||||
this.handleSetEnabled(false);
|
||||
|
||||
Runnable worker = new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
try {
|
||||
PrinterJob pjob = PrinterJob.getPrinterJob();
|
||||
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
|
||||
aset.add(MediaSizeName.ISO_A4);
|
||||
aset.add(new Copies(1));
|
||||
boolean doPrint = pjob.printDialog(aset);
|
||||
|
||||
if(doPrint){
|
||||
/*
|
||||
if(currentDialog != null){
|
||||
currentDialog.setStatus(null, true);
|
||||
}
|
||||
DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
|
||||
Doc doc = new SimpleDoc(config.toString(), flavor, null);
|
||||
DocPrintJob docPrintJob = pjob.getPrintService().createPrintJob();
|
||||
docPrintJob.print(doc, aset);
|
||||
handleSetStatus("Configuration printed.", true);
|
||||
*/
|
||||
view.setStatus("Warning: Printing not supported yet.", false);
|
||||
handleSetEnabled(true);
|
||||
} else {
|
||||
handleCancel();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
view.setStatus("Error:" + e.getMessage(), false);
|
||||
handleSetEnabled(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(worker);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleExit(){
|
||||
this.exitInProgress = false;
|
||||
view.dispose();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void handleOpen(File file){
|
||||
this.curFile = file;
|
||||
this.openInProgress = true;
|
||||
this.handleConditionalSave();
|
||||
}
|
||||
|
||||
private void handleOpen(){
|
||||
openInProgress = false;
|
||||
File file = null;
|
||||
|
||||
if(this.curFile != null){
|
||||
file = this.curFile;
|
||||
} else {
|
||||
int returnVal = this.openFileChooser.showOpenDialog(this.view);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
file = this.openFileChooser.getSelectedFile();
|
||||
} else {
|
||||
this.handleSetStatus("No file opened", false, false);
|
||||
this.handleNextAction();
|
||||
}
|
||||
}
|
||||
|
||||
if(file != null){
|
||||
final File f = file;
|
||||
this.handleSetEnabled(false);
|
||||
view.setStatus("Opening configuration from " + f.getAbsolutePath() + "...", true, true);
|
||||
view.repaint();
|
||||
|
||||
Runnable worker = new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
view.setDataConfiguration(null);
|
||||
DataConfiguration config = null;
|
||||
|
||||
try {
|
||||
if (ConfigModeIntializer.CONFIGURATOR_MODE != ConfigModeIntializer.COMMERCIAL_MODE &&
|
||||
ConfigModeIntializer.CONFIGURATOR_MODE != ConfigModeIntializer.LITE_MODE) {
|
||||
ConfigModeIntializer.setMode(ConfigModeIntializer.COMMUNITY_MODE_FILE_OPEN);
|
||||
}
|
||||
|
||||
config = new DataConfiguration(f, false);
|
||||
} catch (DataException e) {
|
||||
Report.getInstance().writeInfoLog("ConfigWindowController handleOpen\n" + e.getMessage());
|
||||
if (ConfigModeIntializer.CONFIGURATOR_MODE != ConfigModeIntializer.LITE_MODE) {
|
||||
if (ConfigModeIntializer.CONFIGURATOR_MODE != ConfigModeIntializer.COMMERCIAL_MODE) {
|
||||
ConfigModeIntializer.setMode(ConfigModeIntializer.COMMUNITY_MODE);
|
||||
}
|
||||
|
||||
int answer = JOptionPane.showConfirmDialog(
|
||||
view,
|
||||
"The configuration is not valid.\nReason: " +
|
||||
e.getMessage() +
|
||||
"\nTry automatic repairing?",
|
||||
"Invalid configuration",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
|
||||
if(answer == JOptionPane.YES_OPTION){
|
||||
try {
|
||||
config = new DataConfiguration(f, true);
|
||||
|
||||
view.setStatus("Configuration repaired successfully.", false);
|
||||
} catch (DataException e1) {
|
||||
JOptionPane.showMessageDialog(view,
|
||||
"Configuration could not be repaired.\nReason: '" +
|
||||
e.getMessage() + "'"
|
||||
, "Error", JOptionPane.ERROR_MESSAGE);
|
||||
handleSetStatus("Configuration could not be repaired.", false);
|
||||
handleNextAction();
|
||||
}
|
||||
} else if(answer == JOptionPane.NO_OPTION){
|
||||
handleSetStatus("Configuration not opened.", false);
|
||||
handleNextAction();
|
||||
}
|
||||
} else {
|
||||
JOptionPane.showConfirmDialog(
|
||||
view,
|
||||
"The configuration is not valid.\nReason: " +
|
||||
e.getMessage(),
|
||||
"Invalid configuration",
|
||||
JOptionPane.PLAIN_MESSAGE);
|
||||
}
|
||||
}
|
||||
if(config != null){
|
||||
view.setDataConfiguration(config);
|
||||
view.setStatus("Configuration opened.", false);
|
||||
} else {
|
||||
view.setStatus("Configuration could not be opened.", false);
|
||||
}
|
||||
handleNextAction();
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(worker);
|
||||
}
|
||||
this.curFile = null;
|
||||
}
|
||||
|
||||
public void handleOpenFromUri(String uri) {
|
||||
openInProgress = false;
|
||||
File file = null;
|
||||
|
||||
if (uri.startsWith("file://")) {
|
||||
/* strip off file:// */
|
||||
uri = uri.substring(7);
|
||||
}
|
||||
file = new File(uri);
|
||||
|
||||
final File f = file;
|
||||
this.handleSetEnabled(false);
|
||||
view.setStatus("Opening configuration from " + f.getAbsolutePath()
|
||||
+ "...", true, true);
|
||||
view.repaint();
|
||||
|
||||
Runnable worker = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
view.setDataConfiguration(null);
|
||||
DataConfiguration config = null;
|
||||
|
||||
try {
|
||||
if (ConfigModeIntializer.CONFIGURATOR_MODE != ConfigModeIntializer.COMMERCIAL_MODE &&
|
||||
ConfigModeIntializer.CONFIGURATOR_MODE != ConfigModeIntializer.LITE_MODE) {
|
||||
ConfigModeIntializer
|
||||
.setMode(ConfigModeIntializer.COMMUNITY_MODE_FILE_OPEN);
|
||||
}
|
||||
|
||||
config = new DataConfiguration(f, false);
|
||||
} catch (DataException e) {
|
||||
Report.getInstance().writeInfoLog(
|
||||
"ConfigWindowController handleOpen\n"
|
||||
+ e.getMessage());
|
||||
if (ConfigModeIntializer.CONFIGURATOR_MODE != ConfigModeIntializer.COMMERCIAL_MODE &&
|
||||
ConfigModeIntializer.CONFIGURATOR_MODE != ConfigModeIntializer.LITE_MODE) {
|
||||
ConfigModeIntializer
|
||||
.setMode(ConfigModeIntializer.COMMUNITY_MODE);
|
||||
}
|
||||
|
||||
int answer = JOptionPane.showConfirmDialog(
|
||||
view,
|
||||
"The configuration is not valid.\nReason: "
|
||||
+ e.getMessage()
|
||||
+ "\nTry automatic repairing?",
|
||||
"Invalid configuration", JOptionPane.YES_NO_OPTION);
|
||||
|
||||
if (answer == JOptionPane.YES_OPTION) {
|
||||
try {
|
||||
config = new DataConfiguration(f, true);
|
||||
view.setStatus(
|
||||
"Configuration repaired successfully.",
|
||||
false);
|
||||
} catch (DataException e1) {
|
||||
JOptionPane.showMessageDialog(view,
|
||||
"Configuration could not be repaired.\nReason: '"
|
||||
+ e.getMessage() + "'", "Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
handleSetStatus(
|
||||
"Configuration could not be repaired.",
|
||||
false);
|
||||
handleNextAction();
|
||||
}
|
||||
} else if (answer == JOptionPane.NO_OPTION) {
|
||||
handleSetStatus("Configuration not opened.", false);
|
||||
handleNextAction();
|
||||
}
|
||||
}
|
||||
if (config != null) {
|
||||
view.setDataConfiguration(config);
|
||||
view.setStatus("Configuration opened.", false);
|
||||
handleNextAction();
|
||||
}
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(worker);
|
||||
this.curFile = null;
|
||||
}
|
||||
|
||||
private void handleSave(boolean alwaysAskFile){
|
||||
int returnVal;
|
||||
File file;
|
||||
int answer;
|
||||
String path;
|
||||
boolean proceed = false;
|
||||
|
||||
final DataConfiguration config = view.getDataConfiguration();
|
||||
|
||||
if(config == null){
|
||||
this.handleCancel("Warning: No configuration to save.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.handleSetEnabled(false);
|
||||
|
||||
if((!alwaysAskFile) && (config.getFile() != null)){
|
||||
this.handleSetStatus("Saving configuration to: " + config.getFile().getAbsolutePath() + "...", true);
|
||||
|
||||
Runnable worker = new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
try {
|
||||
config.store(true);
|
||||
view.setStatus("Configuration saved.", false, false);
|
||||
handleNextAction();
|
||||
} catch (DataException e) {
|
||||
handleSetStatus("Error: Cannot save configuration to: " +
|
||||
config.getFile().getAbsolutePath(),
|
||||
false);
|
||||
handleNextAction();
|
||||
}
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(worker);
|
||||
} else {
|
||||
try{
|
||||
do {
|
||||
answer = JOptionPane.CANCEL_OPTION;
|
||||
saveFileChooser.setSelectedFile(config.getFile());
|
||||
returnVal = this.saveFileChooser.showSaveDialog(this.view);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
file = this.saveFileChooser.getSelectedFile();
|
||||
path = file.getAbsolutePath();
|
||||
|
||||
if(!path.endsWith(ConfigChooseFilter.CONFIG_SUFFIX)){
|
||||
path = path + ConfigChooseFilter.CONFIG_SUFFIX;
|
||||
file = new File(path);
|
||||
}
|
||||
|
||||
this.handleSetStatus("Saving configuration to: " + file.getAbsolutePath() + "...", true);
|
||||
|
||||
if(file.equals(config.getFile())){
|
||||
proceed = true;
|
||||
} else if (file.exists()){
|
||||
answer = JOptionPane.showConfirmDialog(
|
||||
this.view,
|
||||
"The file '" + path + "' already exists. Overwrite?",
|
||||
"File already exists",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION);
|
||||
|
||||
if(answer == JOptionPane.YES_OPTION){
|
||||
proceed = true;
|
||||
config.setFile(file);
|
||||
} else if(answer == JOptionPane.NO_OPTION){
|
||||
proceed = false;
|
||||
} else {
|
||||
proceed = false;
|
||||
this.handleNextAction();
|
||||
}
|
||||
} else {
|
||||
config.setFile(file);
|
||||
proceed = true;
|
||||
}
|
||||
} else {
|
||||
proceed = false;
|
||||
this.handleNextAction();
|
||||
}
|
||||
} while(answer == JOptionPane.NO_OPTION);
|
||||
|
||||
if(proceed){
|
||||
this.handleSetStatus("Saving configuration to: " + config.getFile().getAbsolutePath() + "...", true);
|
||||
|
||||
Runnable worker = new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
try {
|
||||
config.store(true);
|
||||
view.setStatus("Configuration saved.", false, false);
|
||||
handleNextAction();
|
||||
} catch (DataException e) {
|
||||
view.setStatus("Error:" + e.getMessage(), false);
|
||||
handleSetEnabled(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(worker);
|
||||
}
|
||||
} catch (DataException e) {
|
||||
this.handleSetStatus("Error: " + e.getMessage(), false);
|
||||
handleSetEnabled(true);
|
||||
} catch(Exception exc){
|
||||
this.handleSetStatus("Error: " + exc.getMessage(), false);
|
||||
handleSetEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleHelp(){
|
||||
if(helpView != null){
|
||||
helpView.toFront();
|
||||
} else {
|
||||
view.setStatus("Opening help for configuration...", true, true);
|
||||
this.handleSetEnabled(false);
|
||||
|
||||
Runnable worker = new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
MetaConfiguration metaConfig = MetaConfiguration.getInstance();
|
||||
if (metaConfig != null) {
|
||||
helpView = new HelpWindow(metaConfig);
|
||||
helpView.setLocationRelativeTo(view);
|
||||
view.setStatus("Help pane openened.", false, false);
|
||||
handleSetEnabled(true);
|
||||
helpView.addWindowListener(new WindowAdapter(){
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
helpView = null;
|
||||
}
|
||||
});
|
||||
helpView.setVisible(true);
|
||||
helpView.toFront();
|
||||
} else {
|
||||
view.setStatus("Failed to open the configuration help", true, false);
|
||||
}
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(worker);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleNew(){
|
||||
view.setStatus("Creating new configuration...", true, true);
|
||||
this.handleSetEnabled(false);
|
||||
|
||||
Runnable worker = new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
view.setDataConfiguration(null);
|
||||
newInProgress = false;
|
||||
if (ConfigModeIntializer.CONFIGURATOR_MODE == ConfigModeIntializer.COMMUNITY_MODE_FILE_OPEN) {
|
||||
ConfigModeIntializer.setMode(ConfigModeIntializer.COMMUNITY_MODE);
|
||||
}
|
||||
try {
|
||||
DataConfiguration config = new DataConfiguration();
|
||||
view.setDataConfiguration(config);
|
||||
view.setStatus("New configuration created.", false, false);
|
||||
} catch (DataException e) {
|
||||
|
||||
view.setStatus("Error: Could not create new configuration.", false, false);
|
||||
}
|
||||
handleSetEnabled(true);
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(worker);
|
||||
}
|
||||
|
||||
private void handleClose(){
|
||||
view.setStatus("Closing configuration...", true, true);
|
||||
this.handleSetEnabled(false);
|
||||
|
||||
Runnable worker = new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
view.setDataConfiguration(null);
|
||||
closeInProgress = false;
|
||||
view.setStatus("Configuration closed.", false);
|
||||
handleSetEnabled(true);
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(worker);
|
||||
}
|
||||
|
||||
private void handleNextAction(){
|
||||
if(closeInProgress){
|
||||
handleClose();
|
||||
} else if(exitInProgress){
|
||||
exitInProgress = false;
|
||||
handleExit();
|
||||
} else if(newInProgress){
|
||||
handleNew();
|
||||
} else if(openInProgress){
|
||||
handleOpen();
|
||||
} else {
|
||||
handleSetEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleCancel(){
|
||||
view.setStatus("Action cancelled.", false);
|
||||
this.handleSetEnabled(true);
|
||||
}
|
||||
|
||||
private void handleCancel(String message){
|
||||
view.setStatus(message, false);
|
||||
this.handleSetEnabled(true);
|
||||
}
|
||||
|
||||
private void handleSetEnabled(boolean enabled){
|
||||
if(enabled){
|
||||
this.view.enableView();
|
||||
} else {
|
||||
this.view.disableView();
|
||||
}
|
||||
this.view.setActionsEnabled(enabled);
|
||||
}
|
||||
|
||||
private void handleSetStatus(String message, boolean persistent, boolean busy){
|
||||
this.view.setStatus(message, persistent, busy);
|
||||
|
||||
}
|
||||
|
||||
private void handleSetStatus(String message, boolean persistent){
|
||||
this.view.setStatus(message, persistent, false);
|
||||
}
|
||||
|
||||
private void printStackTrace(Exception exception){
|
||||
StackTraceElement[] elements = exception.getStackTrace();
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("The following exception occurred: \n");
|
||||
|
||||
for(int i=0; i<elements.length; i++){
|
||||
buf.append(elements[i].getFileName() + ", " +
|
||||
elements[i].getMethodName() + ", " +
|
||||
elements[i].getLineNumber() + "\n");
|
||||
}
|
||||
String error = buf.toString();
|
||||
Report.getInstance().writeErrorLog(error);
|
||||
}
|
||||
|
||||
private static class ConfigChooseFilter extends FileFilter{
|
||||
private static String description = null;
|
||||
public static final String CONFIG_SUFFIX = ".xml";
|
||||
|
||||
public ConfigChooseFilter(){
|
||||
if (ConfigModeIntializer.CONFIGURATOR_MODE == ConfigModeIntializer.LITE_MODE) {
|
||||
ConfigChooseFilter.description = "Cyclone DDS config files (*" +
|
||||
ConfigChooseFilter.CONFIG_SUFFIX + ")";
|
||||
} else {
|
||||
ConfigChooseFilter.description = "OpenSplice config files (*" +
|
||||
ConfigChooseFilter.CONFIG_SUFFIX + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(f.getName().endsWith(ConfigChooseFilter.CONFIG_SUFFIX)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return ConfigChooseFilter.description;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JTable;
|
||||
|
||||
import org.eclipse.cyclonedds.common.view.StatusPanel;
|
||||
import org.eclipse.cyclonedds.config.data.DataElement;
|
||||
import org.eclipse.cyclonedds.config.data.DataNode;
|
||||
|
||||
public class DataElementTable extends JTable implements DataNodePopupSupport {
|
||||
private static final long serialVersionUID = 3904871676109190600L;
|
||||
private final DataElementTableCellRenderer renderer;
|
||||
private final DataElementTableModel model;
|
||||
private final DataElementTableModelEditor editor;
|
||||
private DataNodePopup popupController;
|
||||
private final StatusPanel status;
|
||||
|
||||
public DataElementTable(DataNodePopup popup, DataElement element, StatusPanel status){
|
||||
super();
|
||||
this.model = new DataElementTableModel();
|
||||
this.editor = new DataElementTableModelEditor(model);
|
||||
this.renderer = new DataElementTableCellRenderer(model);
|
||||
this.editor.setStatusListener(status);
|
||||
this.model.setElement(element);
|
||||
this.status = status;
|
||||
this.setModel(model);
|
||||
this.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
||||
this.getTableHeader().setReorderingAllowed(false);
|
||||
this.setSurrendersFocusOnKeystroke(true);
|
||||
this.getColumnModel().getColumn(1).setCellEditor(editor);
|
||||
this.getColumnModel().getColumn(1).setCellRenderer(renderer);
|
||||
|
||||
if(popup == null){
|
||||
this.popupController = new DataNodePopup();
|
||||
} else {
|
||||
this.popupController = popup;
|
||||
}
|
||||
this.popupController.registerPopupSupport(this);
|
||||
}
|
||||
|
||||
public void setStatusListener(StatusPanel status){
|
||||
this.editor.setStatusListener(status);
|
||||
}
|
||||
|
||||
public DataNode getDataNodeAt(int row){
|
||||
this.getSelectionModel().setSelectionInterval(row, row);
|
||||
return this.model.getNodeAt(row);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataNode getDataNodeAt(int x, int y) {
|
||||
int row = this.rowAtPoint(new Point(x, y));
|
||||
return this.getDataNodeAt(row);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showPopup(JPopupMenu popup, int x, int y) {
|
||||
popup.show(this, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatus(String message, boolean persistent, boolean busy) {
|
||||
if(this.status != null){
|
||||
this.status.setStatus(message, persistent, busy);
|
||||
}
|
||||
}
|
||||
|
||||
public DataElementTableModelEditor getEditor() {
|
||||
return this.editor;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
|
||||
import org.eclipse.cyclonedds.common.util.ConfigModeIntializer;
|
||||
import org.eclipse.cyclonedds.config.data.DataNode;
|
||||
|
||||
public class DataElementTableCellRenderer extends DefaultTableCellRenderer {
|
||||
private static final long serialVersionUID = 8091366819992773074L;
|
||||
private DataElementTableModel tableModel = null;
|
||||
|
||||
public DataElementTableCellRenderer(DataElementTableModel tableModel){
|
||||
this.tableModel = tableModel;
|
||||
Logger.getLogger("org.eclipse.cyclonedds.config.swing");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table,
|
||||
Object value,
|
||||
boolean isSelected,
|
||||
boolean hasFocus,
|
||||
int row,
|
||||
int column){
|
||||
Component comp = super.getTableCellRendererComponent (table,
|
||||
value, isSelected, hasFocus, row, column);
|
||||
DataNode node = tableModel.getNodeAt(row);
|
||||
node = node.getParent();
|
||||
table.setToolTipText(null);
|
||||
|
||||
if (ConfigModeIntializer.CONFIGURATOR_MODE != ConfigModeIntializer.COMMERCIAL_MODE) {
|
||||
if (node.getMetadata().getVersion().equals(ConfigModeIntializer.COMMERCIAL)) {
|
||||
if (ConfigModeIntializer.CONFIGURATOR_MODE != ConfigModeIntializer.COMMUNITY_MODE_FILE_OPEN) {
|
||||
comp.setBackground (Color.LIGHT_GRAY);
|
||||
comp.setForeground (Color.GRAY);
|
||||
table.setToolTipText("This element is not part of the community edition");
|
||||
} else {
|
||||
comp.setBackground (Color.RED);
|
||||
comp.setForeground (Color.BLACK);
|
||||
table.setToolTipText("This element is found in the configuration file but not part of the community edition");
|
||||
}
|
||||
} else {
|
||||
comp.setBackground (Color.WHITE);
|
||||
comp.setForeground (Color.BLACK);
|
||||
table.setToolTipText(null);
|
||||
}
|
||||
} else {
|
||||
comp.setBackground (Color.WHITE);
|
||||
comp.setForeground (Color.BLACK);
|
||||
table.setToolTipText(null);
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,199 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import org.eclipse.cyclonedds.common.util.ConfigModeIntializer;
|
||||
import org.eclipse.cyclonedds.config.data.DataAttribute;
|
||||
import org.eclipse.cyclonedds.config.data.DataConfiguration;
|
||||
import org.eclipse.cyclonedds.config.data.DataConfigurationListener;
|
||||
import org.eclipse.cyclonedds.config.data.DataElement;
|
||||
import org.eclipse.cyclonedds.config.data.DataNode;
|
||||
import org.eclipse.cyclonedds.config.data.DataValue;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaAttribute;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaElement;
|
||||
|
||||
public class DataElementTableModel extends DefaultTableModel implements DataConfigurationListener {
|
||||
private static final long serialVersionUID = -217503219724923467L;
|
||||
private DataElement element;
|
||||
private ArrayList<DataNode> nodes;
|
||||
private DataConfiguration configuration;
|
||||
|
||||
public DataElementTableModel(){
|
||||
super();
|
||||
this.element = null;
|
||||
this.configuration = null;
|
||||
this.nodes = new ArrayList<DataNode>();
|
||||
this.addColumn("Name");
|
||||
this.addColumn("Value");
|
||||
|
||||
}
|
||||
|
||||
public void setElement(DataElement element){
|
||||
if(this.element != null){
|
||||
this.clear();
|
||||
}
|
||||
if(element != null){
|
||||
this.element = element;
|
||||
this.initElement();
|
||||
|
||||
if(!this.element.getOwner().equals(this.configuration)){
|
||||
if(this.configuration != null){
|
||||
this.configuration.removeDataConfigurationListener(this);
|
||||
}
|
||||
this.configuration = this.element.getOwner();
|
||||
this.configuration.addDataConfigurationListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nodeAdded(DataElement parent, DataNode nodeAdded) {
|
||||
DataNode parentParent;
|
||||
|
||||
if(parent.equals(this.element)){
|
||||
this.clear();
|
||||
this.initElement();
|
||||
} else {
|
||||
parentParent = parent.getParent();
|
||||
|
||||
if(this.element.equals(parentParent)){
|
||||
this.clear();
|
||||
this.initElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nodeRemoved(DataElement parent, DataNode nodeRemoved) {
|
||||
if(nodeRemoved.equals(this.element)){
|
||||
this.setElement(null);
|
||||
} else if(this.nodes.contains(nodeRemoved)){
|
||||
this.clear();
|
||||
this.initElement();
|
||||
} else if(this.containsNodeAsParent(nodeRemoved)){
|
||||
this.clear();
|
||||
this.initElement();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean containsNodeAsParent(DataNode node){
|
||||
for(DataNode n: this.nodes){
|
||||
if(n.getParent().equals(node)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueChanged(DataValue data, Object oldValue, Object newValue) {
|
||||
final int index = this.nodes.indexOf(data);
|
||||
final Object v = newValue;
|
||||
|
||||
if(index != -1){
|
||||
/*System.out.println("Value changed: data: " + data + ", oldValue: " + oldValue + " newValue: " + newValue + "(row=" + index +", col=1)");*/
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
setValueAt(v, index, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public DataNode getNodeAt(int index){
|
||||
DataNode result;
|
||||
|
||||
if(this.nodes.size() >= (index-1)){
|
||||
result = this.nodes.get(index);
|
||||
} else {
|
||||
result = null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
boolean result;
|
||||
|
||||
if(column == 1 && ConfigModeIntializer.CONFIGURATOR_MODE == ConfigModeIntializer.COMMERCIAL_MODE) {
|
||||
result = true;
|
||||
} else if (column == 1 && !element.getMetadata().getVersion().equals(ConfigModeIntializer.COMMERCIAL)) {
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void initElement(){
|
||||
String elName;
|
||||
Object[] values = new Object[2];
|
||||
|
||||
for(DataNode dn: this.element.getChildren()){
|
||||
if(dn instanceof DataAttribute){
|
||||
values[0] = "@" + ((MetaAttribute)dn.getMetadata()).getName();
|
||||
values[1] = ((DataAttribute)dn).getValue();
|
||||
this.nodes.add(((DataAttribute)dn).getDataValue());
|
||||
this.addRow(values);
|
||||
}
|
||||
}
|
||||
for(DataNode dn: this.element.getChildren()){
|
||||
if(dn instanceof DataValue){
|
||||
values[0] = "";
|
||||
values[1] = ((DataValue)dn).getValue();
|
||||
this.nodes.add(dn);
|
||||
this.addRow(values);
|
||||
}
|
||||
}
|
||||
for(DataNode dn: this.element.getChildren()){
|
||||
if(dn instanceof DataElement){
|
||||
if(!((MetaElement)dn.getMetadata()).hasElementChildren() &&
|
||||
((MetaElement)dn.getMetadata()).hasValueChildren())
|
||||
{
|
||||
elName = ((MetaElement)dn.getMetadata()).getName();
|
||||
|
||||
for(DataNode elNode: ((DataElement)dn).getChildren()){
|
||||
if(elNode instanceof DataValue){
|
||||
values[0] = elName;
|
||||
values[1] = ((DataValue)elNode).getValue();
|
||||
this.nodes.add(elNode);
|
||||
this.addRow(values);
|
||||
} else if(elNode instanceof DataAttribute){
|
||||
values[0] = elName + "[@" + ((MetaAttribute)elNode.getMetadata()).getName() + "]";
|
||||
values[1] = ((DataAttribute)elNode).getValue();
|
||||
this.nodes.add(((DataAttribute)elNode).getDataValue());
|
||||
this.addRow(values);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void clear(){
|
||||
int rows = super.getRowCount();
|
||||
|
||||
for(int i=0; i<rows; i++){
|
||||
super.removeRow(0);
|
||||
}
|
||||
this.nodes.clear();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,224 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
|
||||
import javax.swing.AbstractCellEditor;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
|
||||
import org.eclipse.cyclonedds.common.controller.AssignmentResult;
|
||||
import org.eclipse.cyclonedds.common.util.Config;
|
||||
import org.eclipse.cyclonedds.common.view.StatusPanel;
|
||||
import org.eclipse.cyclonedds.config.data.DataException;
|
||||
import org.eclipse.cyclonedds.config.data.DataValue;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValue;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValueBoolean;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValueEnum;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValueNatural;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValueString;
|
||||
|
||||
public class DataElementTableModelEditor extends AbstractCellEditor implements TableCellEditor, ActionListener, KeyListener {
|
||||
private static final long serialVersionUID = 805706250918260825L;
|
||||
private Object curValue = null;
|
||||
private StatusPanel status;
|
||||
private final Color editColor = Config.getInputColor();
|
||||
private final Color errorColor = Config.getIncorrectColor();
|
||||
private int editRow, editColumn;
|
||||
private Component curEditor = null;
|
||||
private DataElementTableModel tableModel = null;
|
||||
private DataValue editNode;
|
||||
private MetaValue editType;
|
||||
|
||||
public DataElementTableModelEditor(DataElementTableModel tableModel){
|
||||
this.tableModel = tableModel;
|
||||
}
|
||||
|
||||
public void setStatusListener(StatusPanel status){
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelCellEditing(){
|
||||
super.cancelCellEditing();
|
||||
curEditor = null;
|
||||
|
||||
if(status != null){
|
||||
status.setStatus("Editing cancelled", false, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopCellEditing(){
|
||||
boolean result = true;
|
||||
|
||||
if(curEditor != null){
|
||||
result = this.assign().isValid();
|
||||
|
||||
if(result){
|
||||
result = super.stopCellEditing();
|
||||
curEditor = null;
|
||||
} else {
|
||||
this.cancelCellEditing();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCellEditorValue() {
|
||||
return curValue;
|
||||
}
|
||||
|
||||
public boolean isEditing(){
|
||||
assert (editRow != -1) && (editColumn != -1): "Value of editRow || editColumn == null";
|
||||
return (curEditor != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
|
||||
Component result = null;
|
||||
|
||||
editRow = row;
|
||||
editColumn = column;
|
||||
curValue = value;
|
||||
editNode = (DataValue)tableModel.getNodeAt(editRow);
|
||||
if (editNode != null) {
|
||||
editType = (MetaValue)editNode.getMetadata();
|
||||
}
|
||||
|
||||
if(editType instanceof MetaValueBoolean){
|
||||
String[] values = { "true", "false" };
|
||||
JComboBox<String> combo = new JComboBox<String>(values);
|
||||
result = combo;
|
||||
combo.setSelectedItem(curValue);
|
||||
combo.addActionListener(this);
|
||||
} else if(editType instanceof MetaValueEnum){
|
||||
JComboBox<String> combo = new JComboBox<String>();
|
||||
result = combo;
|
||||
|
||||
for(String posValue: ((MetaValueEnum)editType).getPosValues()){
|
||||
combo.addItem(posValue);
|
||||
}
|
||||
combo.setSelectedItem(curValue);
|
||||
combo.addActionListener(this);
|
||||
} else {
|
||||
result = new JTextField(curValue.toString());
|
||||
}
|
||||
curEditor = result;
|
||||
curEditor.setBackground(editColor);
|
||||
curEditor.addKeyListener(this);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(e.getSource().equals(curEditor)){
|
||||
this.assign();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if(curEditor != null){
|
||||
if(e.getSource() instanceof JTextField){
|
||||
AssignmentResult test = this.testAssignment();
|
||||
|
||||
if(test.isValid()){
|
||||
curEditor.setBackground(editColor);
|
||||
|
||||
if(status != null){
|
||||
status.setStatus("Current input valid.", false, false);
|
||||
}
|
||||
} else {
|
||||
curEditor.setBackground(errorColor);
|
||||
|
||||
if(status != null){
|
||||
status.setStatus("Error: " + test.getErrorMessage(), false, false);
|
||||
}
|
||||
}
|
||||
} else if(e.getSource() instanceof JComboBox){
|
||||
/*Do nothing.*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {}
|
||||
|
||||
public AssignmentResult testAssignment(){
|
||||
AssignmentResult result = new AssignmentResult(true, null);
|
||||
String value;
|
||||
|
||||
if(curEditor != null){
|
||||
try {
|
||||
if((editType instanceof MetaValueNatural) || (editType instanceof MetaValueString)) {
|
||||
JTextField source = (JTextField)curEditor;
|
||||
value = source.getText();
|
||||
editNode.testSetValue(value);
|
||||
} else {
|
||||
// No validation required.
|
||||
}
|
||||
} catch(DataException ne){
|
||||
result = new AssignmentResult(false, "Invalid input: " + (ne.getMessage()).toLowerCase());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private AssignmentResult assign(){
|
||||
Object value = null;
|
||||
AssignmentResult test = this.testAssignment();
|
||||
|
||||
if(test.isValid()){
|
||||
if(status != null){
|
||||
status.setStatus("Input valid.", false, false);
|
||||
}
|
||||
|
||||
if(curEditor instanceof JTextField){
|
||||
value = ((JTextField)curEditor).getText();
|
||||
} else if(curEditor instanceof JComboBox){
|
||||
value = ((JComboBox) curEditor).getSelectedItem();
|
||||
}
|
||||
try {
|
||||
if(!editNode.getValue().equals(value)){
|
||||
assert editNode.getOwner() != null: "Owner == null (" + editNode.getMetadata() + ")";
|
||||
editNode.getOwner().setValue(editNode, value);
|
||||
|
||||
}
|
||||
} catch (DataException e) {
|
||||
assert false: "this.testAssignment does not work properly";
|
||||
}
|
||||
curEditor.removeKeyListener(this);
|
||||
curEditor = null;
|
||||
editNode = null;
|
||||
editType = null;
|
||||
fireEditingStopped();
|
||||
} else if(status != null){
|
||||
status.setStatus("Error: Invalid input " + test.getErrorMessage().toLowerCase(), false, false);
|
||||
}
|
||||
return test;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,223 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.font.FontRenderContext;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeCellRenderer;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeCellRenderer;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
|
||||
import org.eclipse.cyclonedds.common.view.StatusPanel;
|
||||
import org.eclipse.cyclonedds.config.data.DataConfigurationListener;
|
||||
import org.eclipse.cyclonedds.config.data.DataElement;
|
||||
import org.eclipse.cyclonedds.config.data.DataNode;
|
||||
import org.eclipse.cyclonedds.config.data.DataValue;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaElement;
|
||||
|
||||
public class DataElementTree extends JTree
|
||||
implements DataConfigurationListener, TreeCellRenderer, DataNodePopupSupport
|
||||
{
|
||||
private static final long serialVersionUID = 5103341138480897742L;
|
||||
private final DataElement rootElement;
|
||||
private final DefaultMutableTreeNode rootNode;
|
||||
private final DefaultTreeModel model;
|
||||
private final DefaultTreeCellRenderer initialRenderer;
|
||||
private DataNodePopup popupController;
|
||||
private final StatusPanel status;
|
||||
|
||||
public DataElementTree(DataElement rootElement, DataNodePopup popup, StatusPanel status){
|
||||
super();
|
||||
this.initialRenderer = new DefaultTreeCellRenderer();
|
||||
this.setCellRenderer(this);
|
||||
this.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||
this.setEditable(false);
|
||||
this.setRootVisible(true);
|
||||
this.setShowsRootHandles(true);
|
||||
this.rootElement = rootElement;
|
||||
this.status = status;
|
||||
this.rootElement.getOwner().addDataConfigurationListener(this);
|
||||
this.rootNode = new DefaultMutableTreeNode(this.rootElement);
|
||||
this.model = ((DefaultTreeModel)this.treeModel);
|
||||
this.model.setRoot(this.rootNode);
|
||||
this.initElement(this.rootNode, this.rootElement);
|
||||
if(this.rootNode.getChildCount() > 0){
|
||||
this.scrollPathToVisible(
|
||||
new TreePath(
|
||||
((DefaultMutableTreeNode)this.rootNode.getFirstChild()).getPath()));
|
||||
}
|
||||
this.setSelectionPath(new TreePath(this.rootNode.getPath()));
|
||||
|
||||
if(popup == null){
|
||||
this.popupController = new DataNodePopup();
|
||||
} else {
|
||||
this.popupController = popup;
|
||||
}
|
||||
this.popupController.registerPopupSupport(this);
|
||||
}
|
||||
|
||||
private void initElement(DefaultMutableTreeNode parent, DataElement element){
|
||||
DefaultMutableTreeNode node;
|
||||
|
||||
for(DataNode child: element.getChildren()){
|
||||
if(child instanceof DataElement){
|
||||
if(((MetaElement)child.getMetadata()).hasElementChildren()){
|
||||
node = new DefaultMutableTreeNode(child);
|
||||
this.model.insertNodeInto(node, parent, parent.getChildCount());
|
||||
this.initElement(node, (DataElement)child);
|
||||
} else if(!((MetaElement)child.getMetadata()).hasValueChildren()){
|
||||
node = new DefaultMutableTreeNode(child);
|
||||
this.model.insertNodeInto(node, parent, parent.getChildCount());
|
||||
this.initElement(node, (DataElement)child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nodeAdded(DataElement parent, DataNode nodeAdded) {
|
||||
DefaultMutableTreeNode parentNode, childNode;
|
||||
|
||||
if(nodeAdded instanceof DataElement){
|
||||
parentNode = this.lookupNode(this.rootNode, parent);
|
||||
|
||||
if(parentNode != null){
|
||||
if(((MetaElement)nodeAdded.getMetadata()).hasElementChildren()){
|
||||
childNode = new DefaultMutableTreeNode(nodeAdded);
|
||||
this.model.insertNodeInto(childNode, parentNode, parentNode.getChildCount());
|
||||
this.scrollPathToVisible(new TreePath(childNode.getPath()));
|
||||
this.initElement(childNode, (DataElement)nodeAdded);
|
||||
} else if(!((MetaElement)nodeAdded.getMetadata()).hasValueChildren()){
|
||||
childNode = new DefaultMutableTreeNode(nodeAdded);
|
||||
this.model.insertNodeInto(childNode, parentNode, parentNode.getChildCount());
|
||||
this.scrollPathToVisible(new TreePath(childNode.getPath()));
|
||||
this.initElement(childNode, (DataElement)nodeAdded);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nodeRemoved(DataElement parent, DataNode nodeRemoved) {
|
||||
DefaultMutableTreeNode node;
|
||||
|
||||
if(nodeRemoved instanceof DataElement){
|
||||
node = this.lookupNode(this.rootNode, (DataElement)nodeRemoved);
|
||||
|
||||
if(node != null){
|
||||
if(node.getParent() != null){
|
||||
this.setSelectionPath(new TreePath(((DefaultMutableTreeNode)node.getParent()).getPath()));
|
||||
}
|
||||
if(node.getParent() != null){
|
||||
this.model.removeNodeFromParent(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueChanged(DataValue data, Object oldValue, Object newValue) {
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
private DefaultMutableTreeNode lookupNode(DefaultMutableTreeNode node, DataElement element){
|
||||
DefaultMutableTreeNode result = null;
|
||||
|
||||
if(node.getUserObject().equals(element)){
|
||||
result = node;
|
||||
} else {
|
||||
for(int i=0; (i<node.getChildCount()) && (result == null); i++){
|
||||
result = this.lookupNode((DefaultMutableTreeNode)node.getChildAt(i), element);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
|
||||
Component result = null;
|
||||
JLabel temp;
|
||||
Object nodeValue;
|
||||
|
||||
if(value instanceof DefaultMutableTreeNode){
|
||||
nodeValue = ((DefaultMutableTreeNode)value).getUserObject();
|
||||
|
||||
if(nodeValue instanceof DataElement){
|
||||
temp = new JLabel(ConfigUtil.getExtendedDataElementString((DataElement)nodeValue));
|
||||
|
||||
if(selected){
|
||||
temp.setForeground(UIManager.getColor("Tree.selectionForeground"));
|
||||
temp.setBackground(UIManager.getColor("Tree.selectionBackground"));
|
||||
temp.setOpaque(true);
|
||||
} else {
|
||||
temp.setForeground(UIManager.getColor("Tree.textForeground"));
|
||||
temp.setBackground(UIManager.getColor("Tree.textBackground"));
|
||||
}
|
||||
temp.setFont(temp.getFont().deriveFont(Font.BOLD));
|
||||
Dimension dim = temp.getPreferredSize();
|
||||
|
||||
if(dim != null){
|
||||
FontRenderContext frc = new FontRenderContext(temp.getFont().getTransform(), false, false);
|
||||
double width = temp.getFont().getStringBounds(temp.getText(), frc).getWidth();
|
||||
dim.width = (int)width + 3;
|
||||
temp.setPreferredSize(dim);
|
||||
temp.setMinimumSize(dim);
|
||||
|
||||
}
|
||||
temp.setComponentOrientation(this.getComponentOrientation());
|
||||
|
||||
result = temp;
|
||||
}
|
||||
}
|
||||
|
||||
if(result == null){
|
||||
result = initialRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataNode getDataNodeAt(int x, int y) {
|
||||
DataNode retVal = null;
|
||||
TreePath path = this.getClosestPathForLocation(x, y);
|
||||
|
||||
if (path != null) {
|
||||
this.setSelectionPath(path);
|
||||
retVal = (DataElement)((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject();
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showPopup(JPopupMenu popup, int x, int y) {
|
||||
popup.show(this, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatus(String message, boolean persistent, boolean busy) {
|
||||
if(this.status != null){
|
||||
this.status.setStatus(message, persistent, busy);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
import org.eclipse.cyclonedds.config.data.DataNode;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaNode;
|
||||
|
||||
public class DataNodeMenuItem extends JMenuItem {
|
||||
private static final long serialVersionUID = -5909316541978936911L;
|
||||
private DataNode data;
|
||||
private MetaNode childMeta;
|
||||
private DataNodePopupSupport source;
|
||||
|
||||
public DataNodeMenuItem(String name, DataNode data, MetaNode childMeta){
|
||||
super(name);
|
||||
this.data = data;
|
||||
this.childMeta = childMeta;
|
||||
this.source = null;
|
||||
}
|
||||
|
||||
public DataNodeMenuItem(String name, DataNode data, MetaNode childMeta, DataNodePopupSupport source){
|
||||
super(name);
|
||||
this.data = data;
|
||||
this.childMeta = childMeta;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public DataNode getData(){
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public MetaNode getChildMeta(){
|
||||
return this.childMeta;
|
||||
}
|
||||
|
||||
public DataNodePopupSupport getSource(){
|
||||
return this.source;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,440 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
|
||||
import org.eclipse.cyclonedds.common.util.Report;
|
||||
import org.eclipse.cyclonedds.config.data.DataAttribute;
|
||||
import org.eclipse.cyclonedds.config.data.DataElement;
|
||||
import org.eclipse.cyclonedds.config.data.DataException;
|
||||
import org.eclipse.cyclonedds.config.data.DataNode;
|
||||
import org.eclipse.cyclonedds.config.data.DataValue;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaAttribute;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaElement;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaNode;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaValue;
|
||||
import org.eclipse.cyclonedds.common.util.ConfigModeIntializer;
|
||||
|
||||
public class DataNodePopup implements MouseListener, ActionListener {
|
||||
|
||||
private final Set<DataNodePopupSupport> popupSupport;
|
||||
|
||||
public DataNodePopup() {
|
||||
this.popupSupport = Collections.synchronizedSet(new HashSet<DataNodePopupSupport>());
|
||||
}
|
||||
|
||||
public void unregisterPopupSupport(DataNodePopupSupport support){
|
||||
synchronized(this.popupSupport){
|
||||
if(this.popupSupport.contains(support)){
|
||||
support.removeMouseListener(this);
|
||||
this.popupSupport.remove(support);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void registerPopupSupport(DataNodePopupSupport support){
|
||||
synchronized(this.popupSupport){
|
||||
if(!this.popupSupport.contains(support)){
|
||||
support.addMouseListener(this);
|
||||
this.popupSupport.add(support);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyStatus(String message, boolean persistent, boolean busy){
|
||||
synchronized(this.popupSupport){
|
||||
for(DataNodePopupSupport dp: this.popupSupport){
|
||||
dp.setStatus(message, persistent, busy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int countOccurrences(DataElement parent, MetaNode metaChild){
|
||||
int occurrences = 0;
|
||||
|
||||
for(DataNode child: parent.getChildren()){
|
||||
if(metaChild.equals(child.getMetadata())){
|
||||
occurrences++;
|
||||
}
|
||||
}
|
||||
return occurrences;
|
||||
}
|
||||
|
||||
private JPopupMenu getPopup(DataNodePopupSupport source, DataNode dn){
|
||||
DataNode parent;
|
||||
DataElement parentParent;
|
||||
DataNodeMenuItem reset, remove, add;
|
||||
MetaNode metaParent, meta;
|
||||
JMenu addMenu;
|
||||
int min, max, current;
|
||||
|
||||
JPopupMenu result = new JPopupMenu("Actions");
|
||||
|
||||
if (dn != null) {
|
||||
parent = dn.getParent();
|
||||
meta = dn.getMetadata();
|
||||
} else {
|
||||
parent = null;
|
||||
meta = null;
|
||||
}
|
||||
|
||||
if(parent != null){
|
||||
metaParent = parent.getMetadata();
|
||||
} else {
|
||||
metaParent = null;
|
||||
}
|
||||
addMenu = null;
|
||||
reset = null;
|
||||
remove = null;
|
||||
|
||||
if(dn instanceof DataValue){
|
||||
assert metaParent!=null: "Parent element == null";
|
||||
reset = new DataNodeMenuItem("Reset to default", dn, null);
|
||||
remove = new DataNodeMenuItem("Remove", parent, null);
|
||||
|
||||
if(parent instanceof DataElement){
|
||||
addMenu = new JMenu("Add");
|
||||
|
||||
for(MetaNode child: ((MetaElement)metaParent).getChildren()){
|
||||
if(child instanceof MetaAttribute){
|
||||
current = this.countOccurrences((DataElement)parent, child);
|
||||
add = new DataNodeMenuItem(((MetaAttribute)child).getName(), parent, child);
|
||||
|
||||
if(current == 1){
|
||||
add.setEnabled(false);
|
||||
} else {
|
||||
add.setEnabled(true);
|
||||
}
|
||||
add.setActionCommand("add");
|
||||
add.addActionListener(this);
|
||||
addMenu.add(add);
|
||||
}
|
||||
}
|
||||
|
||||
parentParent = (DataElement)parent.getParent();
|
||||
|
||||
if(parentParent != null){
|
||||
current = this.countOccurrences((DataElement)parent.getParent(), parent.getMetadata());
|
||||
min = ((MetaElement)metaParent).getMinOccurrences();
|
||||
if (ConfigModeIntializer.CONFIGURATOR_MODE != ConfigModeIntializer.COMMERCIAL_MODE && metaParent.getVersion().equals(ConfigModeIntializer.COMMERCIAL)) {
|
||||
reset.setEnabled(false);
|
||||
}
|
||||
|
||||
if(min == 0){
|
||||
remove.setEnabled(true);
|
||||
} else if(current > min){
|
||||
remove.setEnabled(true);
|
||||
} else {
|
||||
remove.setEnabled(false);
|
||||
}
|
||||
}
|
||||
} else if(parent instanceof DataAttribute){
|
||||
metaParent = parent.getMetadata();
|
||||
if (ConfigModeIntializer.CONFIGURATOR_MODE != ConfigModeIntializer.COMMERCIAL_MODE && metaParent.getVersion().equals(ConfigModeIntializer.COMMERCIAL)) {
|
||||
reset.setEnabled(false);
|
||||
}
|
||||
|
||||
if(((MetaAttribute)metaParent).isRequired()){
|
||||
remove.setEnabled(false);
|
||||
}
|
||||
result.add(remove);
|
||||
} else {
|
||||
assert false: "Unexpected parent type found: " + (parent==null ? parent: parent.getClass());
|
||||
}
|
||||
} else if(dn instanceof DataElement){
|
||||
addMenu = new JMenu("Add");
|
||||
remove = new DataNodeMenuItem("Remove", dn, null);
|
||||
|
||||
min = ((MetaElement)meta).getMinOccurrences();
|
||||
current = this.countOccurrences((DataElement)dn.getParent(), meta);
|
||||
|
||||
if(min < current){
|
||||
remove.setEnabled(true);
|
||||
} else {
|
||||
remove.setEnabled(false);
|
||||
}
|
||||
|
||||
for(MetaNode child: ((MetaElement)meta).getChildren()){
|
||||
current = this.countOccurrences((DataElement)dn, child);
|
||||
|
||||
if(child instanceof MetaElement){
|
||||
add = new DataNodeMenuItem(((MetaElement)child).getName(), dn, child);
|
||||
max = ((MetaElement)child).getMaxOccurrences();
|
||||
|
||||
if((max == 0) || (current < max)){
|
||||
add.setEnabled(true);
|
||||
} else {
|
||||
add.setEnabled(false);
|
||||
}
|
||||
|
||||
} else if(child instanceof MetaAttribute){
|
||||
add = new DataNodeMenuItem(((MetaAttribute)child).getName(), dn, child);
|
||||
|
||||
if(current == 1){
|
||||
add.setEnabled(false);
|
||||
} else {
|
||||
add.setEnabled(true);
|
||||
}
|
||||
} else {
|
||||
add = new DataNodeMenuItem("<NoName>", dn, child);
|
||||
|
||||
if(current == 1){
|
||||
add.setEnabled(false);
|
||||
} else {
|
||||
add.setEnabled(true);
|
||||
}
|
||||
}
|
||||
add.setActionCommand("add");
|
||||
add.addActionListener(this);
|
||||
addMenu.add(add);
|
||||
}
|
||||
|
||||
}
|
||||
if(addMenu != null){
|
||||
if (addMenu.getItemCount() == 0){
|
||||
addMenu.setEnabled(false);
|
||||
}
|
||||
result.add(addMenu);
|
||||
|
||||
}
|
||||
if(remove != null){
|
||||
remove.setActionCommand("remove");
|
||||
remove.addActionListener(this);
|
||||
result.add(remove);
|
||||
}
|
||||
|
||||
if(reset != null){
|
||||
result.addSeparator();
|
||||
reset.setActionCommand("reset");
|
||||
reset.addActionListener(this);
|
||||
result.add(reset);
|
||||
} else {
|
||||
//result.addSeparator();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
DataNodeMenuItem item;
|
||||
DataNode dataNode;
|
||||
MetaNode metaNode;
|
||||
DataElement dataDomain = null;
|
||||
Object source = e.getSource();
|
||||
String command = e.getActionCommand();
|
||||
|
||||
try{
|
||||
if(source instanceof DataNodeMenuItem){
|
||||
item = (DataNodeMenuItem)source;
|
||||
if("remove".equals(command)){
|
||||
dataNode = item.getData();
|
||||
boolean remove = false;
|
||||
if (dataNode.getOwner().isServiceElement(dataNode)) {
|
||||
int value = JOptionPane.showConfirmDialog(null,
|
||||
"Are you sure you want to remove this " + ConfigWindow.SERVICE_TEXT + "?", "Remove " + ConfigWindow.SERVICE_TEXT + " confirmation",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if (value == JOptionPane.NO_OPTION) {
|
||||
remove = true;
|
||||
}
|
||||
}
|
||||
if (!remove && dataNode.getDependencies() != null) {
|
||||
for (DataNode dn : dataNode.getDependencies()) {
|
||||
if(dn instanceof DataElement){
|
||||
if (dn.getOwner().isServiceElement(dn)) {
|
||||
int value = JOptionPane.showConfirmDialog(null,
|
||||
"Are you sure you want to remove this " + ConfigWindow.SERVICE_TEXT + "?",
|
||||
"Remove " + ConfigWindow.SERVICE_TEXT + " confirmation", JOptionPane.YES_NO_OPTION);
|
||||
if (value == JOptionPane.NO_OPTION) {
|
||||
remove = true;
|
||||
}
|
||||
}
|
||||
if (!remove) {
|
||||
dn.getOwner().removeNode(dn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!remove) {
|
||||
dataNode.getOwner().removeNode(dataNode);
|
||||
}
|
||||
} else if ("removeService".equals(command)) {
|
||||
boolean remove = false;
|
||||
int value = JOptionPane.showConfirmDialog(null,
|
||||
"Are you sure you want to remove this " + ConfigWindow.SERVICE_TEXT + "?",
|
||||
"Remove " + ConfigWindow.SERVICE_TEXT + " confirmation", JOptionPane.YES_NO_OPTION);
|
||||
if (value == JOptionPane.NO_OPTION) {
|
||||
remove = true;
|
||||
}
|
||||
if (!remove) {
|
||||
dataNode = item.getData();
|
||||
dataDomain = dataNode.getOwner().findServiceDataElement(dataNode.getOwner().getRootElement(),
|
||||
"Service", (DataElement) dataNode);
|
||||
if (dataDomain != null) {
|
||||
dataDomain.getOwner().removeNode(dataDomain);
|
||||
} else {
|
||||
this.notifyStatus("Error: failed to remove the " + ConfigWindow.SERVICE_TEXT + " ", false, false);
|
||||
}
|
||||
dataNode.getOwner().removeNode(dataNode);
|
||||
}
|
||||
} else if ("add".equals(command)) {
|
||||
dataNode = item.getData();
|
||||
metaNode = item.getChildMeta();
|
||||
if (dataNode.getOwner().isServiceElement(dataNode)
|
||||
&& ((MetaElement) metaNode).getName().equals("Service")) {
|
||||
HashMap<String, MetaNode> service = new HashMap<String, MetaNode>();
|
||||
for (MetaNode mn : ((MetaElement) dataNode.getOwner().getRootElement().getMetadata())
|
||||
.getChildren()) {
|
||||
if (!((MetaElement) mn).getName().equals("Domain")) {
|
||||
service.put(((MetaElement) mn).getName(), mn);
|
||||
}
|
||||
}
|
||||
String[] serviceNames = service.keySet().toArray(new String[service.keySet().size()]);
|
||||
String name = (String) JOptionPane.showInputDialog(null, "Please select a service to add.",
|
||||
"Service selection", JOptionPane.QUESTION_MESSAGE, null, serviceNames, serviceNames[0]);
|
||||
if (name != null) {
|
||||
addService(dataNode.getOwner().getRootElement(), service.get(name));
|
||||
}
|
||||
} else {
|
||||
if (dataNode instanceof DataElement) {
|
||||
dataNode.getOwner().addNode((DataElement) dataNode, metaNode);
|
||||
} else {
|
||||
this.notifyStatus("Error: Unexpected type of parent found: '" + dataNode.getClass() + "'.",
|
||||
false, false);
|
||||
}
|
||||
}
|
||||
} else if ("addService".equals(command)) {
|
||||
addService(item.getData(), item.getChildMeta());
|
||||
} else if("reset".equals(command)){
|
||||
dataNode = item.getData();
|
||||
dataNode.getOwner().setValue((DataValue)dataNode, ((MetaValue)dataNode.getMetadata()).getDefaultValue());
|
||||
} else {
|
||||
this.notifyStatus("Warning: Action for command '" + command + "' not implemented.", false, false);
|
||||
}
|
||||
}
|
||||
} catch(DataException de){
|
||||
Report.getInstance().writeErrorLog("DataNodePopup actionPerformed" + de.getMessage());
|
||||
this.notifyStatus("Error: " + de.getMessage(), false, false);
|
||||
StackTraceElement[] elements = de.getStackTrace();
|
||||
String error = "";
|
||||
|
||||
for(int i=0; i<elements.length; i++){
|
||||
error += elements[i].getFileName() + ", " +
|
||||
elements[i].getMethodName() + ", "
|
||||
+ elements[i].getLineNumber() + "\n";
|
||||
if(i==0){
|
||||
error = elements[i].getFileName() + ", " +
|
||||
elements[i].getMethodName() + ", " + elements[i].getLineNumber();
|
||||
}
|
||||
}
|
||||
Report.getInstance().writeErrorLog("DataNodePopup actionPerformed\n DataException occurred:\n" + error);
|
||||
} catch(Exception ex){
|
||||
StackTraceElement[] elements = ex.getStackTrace();
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
for(int i=0; i<elements.length; i++){
|
||||
buf.append(elements[i].getFileName() + ", " +
|
||||
elements[i].getMethodName() + ", "
|
||||
+ elements[i].getLineNumber() + "\n");
|
||||
}
|
||||
String error = buf.toString();
|
||||
Report.getInstance().writeErrorLog(
|
||||
"DataNodePopup actionPerformed\n Unhandled exception occurred:\n" + error);
|
||||
this.notifyStatus("Error: " + error, false, false);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
DataNode dn;
|
||||
DataNodePopupSupport support;
|
||||
Object source = e.getSource();
|
||||
|
||||
synchronized(popupSupport){
|
||||
if(popupSupport.contains(source)){
|
||||
if((e.getClickCount() == 1)) {
|
||||
if(e.getButton() == MouseEvent.BUTTON3) {
|
||||
support = (DataNodePopupSupport)source;
|
||||
if (support != null) {
|
||||
dn = support.getDataNodeAt(e.getX(), e.getY());
|
||||
support.showPopup(this.getPopup(support, dn), e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addService(DataNode dataNode, MetaNode metaNode) throws DataException {
|
||||
if (dataNode instanceof DataElement) {
|
||||
if (ConfigModeIntializer.CONFIGURATOR_MODE != ConfigModeIntializer.LITE_MODE){
|
||||
String serviceName = null;
|
||||
|
||||
String suggestedName = dataNode.getOwner().getMetaAttributeValue((MetaElement) metaNode, "name");
|
||||
/*
|
||||
* generate a new name if there is already a service with the
|
||||
* default name
|
||||
*/
|
||||
if (dataNode.getOwner().containsServiceName(suggestedName)) {
|
||||
String tmp = suggestedName + "_1";
|
||||
for (int i = 1; dataNode.getOwner().containsServiceName(tmp); i++) {
|
||||
tmp = suggestedName + "_" + i;
|
||||
}
|
||||
suggestedName = tmp;
|
||||
}
|
||||
|
||||
serviceName = (String) JOptionPane.showInputDialog(null, "Please enter a service name:",
|
||||
"Set the service name", JOptionPane.QUESTION_MESSAGE, null, null, suggestedName);
|
||||
|
||||
if (serviceName != null) {
|
||||
if (!dataNode.getOwner().containsServiceName(serviceName)) {
|
||||
/* get the newly created service element */
|
||||
dataNode = dataNode.getOwner().addNodeWithDependency((DataElement) dataNode, metaNode);
|
||||
dataNode.getOwner().createDomainServiceForSerivce(dataNode, metaNode, serviceName);
|
||||
} else {
|
||||
this.notifyStatus("Error: Servicename is already in use", false, false);
|
||||
}
|
||||
} else {
|
||||
this.notifyStatus("Error: Please fill in a servicename", false, false);
|
||||
}
|
||||
} else {
|
||||
/* get the newly created service element */
|
||||
dataNode.getOwner().addNode((DataElement) dataNode, metaNode);
|
||||
}
|
||||
} else {
|
||||
this.notifyStatus("Error: Unexpected type of parent found: '" + dataNode.getClass() + "'.", false, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
import javax.swing.JPopupMenu;
|
||||
import org.eclipse.cyclonedds.config.data.DataNode;
|
||||
|
||||
public interface DataNodePopupSupport {
|
||||
public DataNode getDataNodeAt(int x, int y);
|
||||
|
||||
public void showPopup(JPopupMenu popup, int x, int y);
|
||||
|
||||
public void setStatus(String message, boolean persistent, boolean busy);
|
||||
|
||||
public void addMouseListener(MouseListener listener);
|
||||
|
||||
public void removeMouseListener(MouseListener listener);
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.WindowConstants;
|
||||
import javax.swing.JSplitPane;
|
||||
|
||||
import org.eclipse.cyclonedds.common.util.ConfigModeIntializer;
|
||||
import org.eclipse.cyclonedds.common.view.StatusPanel;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaConfiguration;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
|
||||
public class HelpWindow extends JFrame implements TreeSelectionListener {
|
||||
private static final long serialVersionUID = 11222322324L;
|
||||
private JPanel jContentPane = null;
|
||||
private JSplitPane eastWestSplitPane = null;
|
||||
private StatusPanel statusPanel = null;
|
||||
private MetaConfiguration metaConfiguration = null;
|
||||
private MetaElementTree elementTree = null;
|
||||
private JScrollPane elementTreeScrollPane = null;
|
||||
private JScrollPane docScrollPane = null;
|
||||
private MetaNodeDocPane docPane = null;
|
||||
|
||||
public static final String OSPL_HELP_WINDOW_TITLE = "Vortex OpenSplice Configurator | Help";
|
||||
public static final String LITE_HELP_WINDOW_TITLE = "Vortex DDS Configurator | Help";
|
||||
|
||||
/**
|
||||
* This is the default constructor
|
||||
*/
|
||||
public HelpWindow(MetaConfiguration metaConfiguration) {
|
||||
super();
|
||||
this.metaConfiguration = metaConfiguration;
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes this
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private void initialize() {
|
||||
this.setSize(640, 480);
|
||||
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
this.setContentPane(getJContentPane());
|
||||
setWindowTitle(ConfigModeIntializer.CONFIGURATOR_MODE);
|
||||
getElementTree().getSelectionModel().addTreeSelectionListener(this);
|
||||
getDocPane().setNode(getElementTree().getSelectedMetaElement());
|
||||
}
|
||||
|
||||
public void setWindowTitle (int configMode) {
|
||||
String windowTitle = "Configurator | Help";
|
||||
if (configMode == ConfigModeIntializer.LITE_MODE) {
|
||||
windowTitle = LITE_HELP_WINDOW_TITLE;
|
||||
} else {
|
||||
windowTitle = OSPL_HELP_WINDOW_TITLE;
|
||||
}
|
||||
this.setTitle(windowTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes jContentPane
|
||||
*
|
||||
* @return javax.swing.JPanel
|
||||
*/
|
||||
private JPanel getJContentPane() {
|
||||
if (jContentPane == null) {
|
||||
jContentPane = new JPanel();
|
||||
jContentPane.setLayout(new BorderLayout());
|
||||
jContentPane.add(getEastWestSplitPane(), BorderLayout.CENTER);
|
||||
jContentPane.add(getStatusPanel(), BorderLayout.SOUTH);
|
||||
}
|
||||
return jContentPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes eastWestSplitPane
|
||||
*
|
||||
* @return javax.swing.JSplitPane
|
||||
*/
|
||||
private JSplitPane getEastWestSplitPane() {
|
||||
if (eastWestSplitPane == null) {
|
||||
eastWestSplitPane = new JSplitPane();
|
||||
eastWestSplitPane.setDividerSize(5);
|
||||
eastWestSplitPane.setDividerLocation(250);
|
||||
eastWestSplitPane.setLeftComponent(getElementTreeScrollPane());
|
||||
eastWestSplitPane.setRightComponent(getDocScrollPane());
|
||||
}
|
||||
return eastWestSplitPane;
|
||||
}
|
||||
|
||||
private StatusPanel getStatusPanel(){
|
||||
if(this.statusPanel == null){
|
||||
this.statusPanel = new StatusPanel(800, "", false, false);
|
||||
}
|
||||
return this.statusPanel;
|
||||
}
|
||||
|
||||
private MetaElementTree getElementTree(){
|
||||
if(this.elementTree == null){
|
||||
this.elementTree = new MetaElementTree(metaConfiguration.getRootElement(), getStatusPanel());
|
||||
}
|
||||
return this.elementTree;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes elementTreeScrollPane
|
||||
*
|
||||
* @return javax.swing.JScrollPane
|
||||
*/
|
||||
private JScrollPane getElementTreeScrollPane() {
|
||||
if (elementTreeScrollPane == null) {
|
||||
elementTreeScrollPane = new JScrollPane();
|
||||
elementTreeScrollPane.setViewportView(getElementTree());
|
||||
}
|
||||
return elementTreeScrollPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes docScrollPane
|
||||
*
|
||||
* @return javax.swing.JScrollPane
|
||||
*/
|
||||
private JScrollPane getDocScrollPane() {
|
||||
if (docScrollPane == null) {
|
||||
docScrollPane = new JScrollPane();
|
||||
docScrollPane.setViewportView(getDocPane());
|
||||
}
|
||||
return docScrollPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes codPane
|
||||
*
|
||||
* @return javax.swing.JEditorPane
|
||||
*/
|
||||
private MetaNodeDocPane getDocPane() {
|
||||
if (docPane == null) {
|
||||
docPane = new MetaNodeDocPane();
|
||||
}
|
||||
return docPane;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
getDocPane().setNode(getElementTree().getSelectedMetaElement());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeCellRenderer;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeCellRenderer;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
|
||||
import org.eclipse.cyclonedds.common.view.StatusPanel;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaElement;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaNode;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class MetaElementTree extends JTree implements TreeCellRenderer, TreeSelectionListener{
|
||||
private final DefaultMutableTreeNode rootNode;
|
||||
private final MetaElement rootElement;
|
||||
private final DefaultTreeModel model;
|
||||
private final DefaultTreeCellRenderer initialRenderer;
|
||||
private final StatusPanel status;
|
||||
|
||||
public MetaElementTree(MetaElement rootElement, StatusPanel status){
|
||||
super();
|
||||
this.initialRenderer = new DefaultTreeCellRenderer();
|
||||
this.rootElement = rootElement;
|
||||
this.status = status;
|
||||
this.rootNode = new DefaultMutableTreeNode(this.rootElement);
|
||||
this.model = ((DefaultTreeModel)this.treeModel);
|
||||
this.model.setRoot(this.rootNode);
|
||||
this.setCellRenderer(this);
|
||||
this.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||
this.setEditable(false);
|
||||
this.setRootVisible(true);
|
||||
this.setShowsRootHandles(true);
|
||||
this.initElement(this.rootNode, this.rootElement);
|
||||
|
||||
if(this.rootNode.getChildCount() > 0){
|
||||
this.scrollPathToVisible(
|
||||
new TreePath(
|
||||
((DefaultMutableTreeNode)this.rootNode.getFirstChild()).getPath()));
|
||||
}
|
||||
this.getSelectionModel().addTreeSelectionListener(this);
|
||||
this.setSelectionPath(new TreePath(this.rootNode.getPath()));
|
||||
}
|
||||
|
||||
private void initElement(DefaultMutableTreeNode parent, MetaElement element){
|
||||
DefaultMutableTreeNode node;
|
||||
|
||||
for(MetaNode child: element.getChildren()){
|
||||
if(child instanceof MetaElement){
|
||||
node = new DefaultMutableTreeNode(child);
|
||||
this.model.insertNodeInto(node, parent, parent.getChildCount());
|
||||
this.initElement(node, (MetaElement)child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
|
||||
Component result = null;
|
||||
JLabel temp;
|
||||
Object nodeValue;
|
||||
|
||||
if(value instanceof DefaultMutableTreeNode){
|
||||
nodeValue = ((DefaultMutableTreeNode)value).getUserObject();
|
||||
|
||||
if(nodeValue instanceof MetaElement){
|
||||
temp = new JLabel(ConfigUtil.getMetaElementString((MetaElement)nodeValue));
|
||||
|
||||
if(selected){
|
||||
temp.setForeground(UIManager.getColor("Tree.selectionForeground"));
|
||||
temp.setBackground(UIManager.getColor("Tree.selectionBackground"));
|
||||
temp.setOpaque(true);
|
||||
} else {
|
||||
temp.setForeground(UIManager.getColor("Tree.textForeground"));
|
||||
temp.setBackground(UIManager.getColor("Tree.textBackground"));
|
||||
}
|
||||
//temp.setFont(temp.getFont().deriveFont(Font.PLAIN));
|
||||
temp.setFont(temp.getFont().deriveFont(Font.BOLD));
|
||||
result = temp;
|
||||
}
|
||||
}
|
||||
|
||||
if(result == null){
|
||||
result = initialRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public MetaElement getSelectedMetaElement(){
|
||||
MetaElement result = null;
|
||||
TreePath path = this.getSelectionPath();
|
||||
|
||||
if(path != null){
|
||||
result = (MetaElement)
|
||||
((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public MetaElement getMetaNodeAt(int x, int y) {
|
||||
MetaElement retVal = null;
|
||||
TreePath path = this.getClosestPathForLocation(x, y);
|
||||
if (path != null) {
|
||||
this.setSelectionPath(path);
|
||||
retVal = (MetaElement)((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject();
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
MetaElement me = this.getSelectedMetaElement();
|
||||
|
||||
if((me != null) && (status != null)){
|
||||
status.setStatus("Element '" + me.getName() + "' selected.", true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,206 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.swing.JEditorPane;
|
||||
|
||||
import org.eclipse.cyclonedds.config.meta.MetaAttribute;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaElement;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaNode;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class MetaNodeDocPane extends JEditorPane {
|
||||
private boolean showElementName;
|
||||
private boolean showChildrenAttributes;
|
||||
private static final String fontStyle = "font-family:Sans-serif";
|
||||
|
||||
public MetaNodeDocPane(){
|
||||
super("text/html", "No selection");
|
||||
this.init(true, true);
|
||||
}
|
||||
|
||||
public MetaNodeDocPane(boolean showElementName, boolean showChildrenAttributes){
|
||||
super("text/html", "No selection");
|
||||
this.init(showElementName, showChildrenAttributes);
|
||||
}
|
||||
|
||||
private void init(boolean showElementName, boolean showChildrenAttributes){
|
||||
this.setEditable(false);
|
||||
this.showElementName = showElementName;
|
||||
this.showChildrenAttributes = showChildrenAttributes;
|
||||
}
|
||||
|
||||
public void setNode(MetaNode node){
|
||||
String doc;
|
||||
MetaNode[] children;
|
||||
MetaAttribute attribute;
|
||||
|
||||
int attributeChildrenCount = 0;
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
if(node == null){
|
||||
writer.write("No element selected.");
|
||||
} else {
|
||||
doc = this.layoutDoc(node.getDoc());
|
||||
|
||||
if(node instanceof MetaElement){
|
||||
if(this.showElementName){
|
||||
int maxOcc = ((MetaElement)node).getMaxOccurrences();
|
||||
int minOcc = ((MetaElement)node).getMinOccurrences();
|
||||
String occ;
|
||||
|
||||
if(maxOcc == Integer.MAX_VALUE){
|
||||
occ = "occurrences: " + minOcc + " - " + "*";
|
||||
} else {
|
||||
occ = "occurrences: " + minOcc + " - " + maxOcc;
|
||||
}
|
||||
writer.write("<h1>" + ((MetaElement)node).getName());
|
||||
|
||||
String dimension = node.getDimension();
|
||||
|
||||
if (dimension != null) {
|
||||
writer.write(" <font size=\"-1\">(" + occ
|
||||
+ " and dimension: " + dimension
|
||||
+ ")</font></h1>");
|
||||
} else {
|
||||
writer.write(" <font size=\"-1\">(" + occ
|
||||
+ ")</font></h1>");
|
||||
}
|
||||
}
|
||||
writer.write("<font style=\"" + MetaNodeDocPane.fontStyle + "\">" + doc + "</font>");
|
||||
children = ((MetaElement)node).getChildren();
|
||||
|
||||
for(MetaNode mn: children){
|
||||
if(mn instanceof MetaAttribute){
|
||||
attributeChildrenCount++;
|
||||
}
|
||||
}
|
||||
if(this.showChildrenAttributes){
|
||||
if(attributeChildrenCount > 0){
|
||||
writer.write("<h2>Attributes</h2>");
|
||||
|
||||
for(MetaNode mn: children){
|
||||
if(mn instanceof MetaAttribute){
|
||||
this.writeNode(writer, mn);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
writer.write("<h2>Attributes</h2>Element has no attributes");
|
||||
}
|
||||
}
|
||||
} else if(node instanceof MetaAttribute){
|
||||
attribute = (MetaAttribute)node;
|
||||
|
||||
if(this.showElementName){
|
||||
writer.write("<h1>" + attribute.getName() + "(");
|
||||
|
||||
if(attribute.isRequired()){
|
||||
writer.write("required");
|
||||
} else {
|
||||
writer.write("optional");
|
||||
}
|
||||
String dimension = attribute.getDimension();
|
||||
|
||||
if (dimension != null) {
|
||||
writer.write(" and dimension: ");
|
||||
writer.write(dimension);
|
||||
}
|
||||
writer.write(")</h1> -");
|
||||
}
|
||||
writer.write("<font style=\"" + MetaNodeDocPane.fontStyle + "\">" + doc + "</font>");
|
||||
} else {
|
||||
writer.write("<font style=\"" + MetaNodeDocPane.fontStyle + "\">" + doc + "</font>");
|
||||
}
|
||||
}
|
||||
this.setText(writer.toString());
|
||||
this.setCaretPosition(0);
|
||||
}
|
||||
|
||||
|
||||
private void writeNode(StringWriter writer, MetaNode node){
|
||||
MetaElement element;
|
||||
MetaAttribute attribute;
|
||||
String doc;
|
||||
String dimension = node.getDimension();
|
||||
|
||||
if(node instanceof MetaElement){
|
||||
element = (MetaElement)node;
|
||||
writer.write("<h3>" + element.getName());
|
||||
writer.write(" (occurrences : " + element.getMinOccurrences()
|
||||
+ " - " + element.getMaxOccurrences());
|
||||
|
||||
if (dimension != null) {
|
||||
writer.write(" dimension: " + dimension);
|
||||
}
|
||||
writer.write(")</h3>");
|
||||
} else if(node instanceof MetaAttribute){
|
||||
attribute = (MetaAttribute)node;
|
||||
writer.write("<h3>" + attribute.getName() + " (");
|
||||
|
||||
if(attribute.isRequired()){
|
||||
writer.write("required");
|
||||
} else {
|
||||
writer.write("optional");
|
||||
}
|
||||
if (dimension != null) {
|
||||
writer.write(" and dimension: " + dimension);
|
||||
}
|
||||
writer.write(")</h3>");
|
||||
}
|
||||
doc = this.layoutDoc(node.getDoc());
|
||||
writer.write("<font style=\"" + MetaNodeDocPane.fontStyle + "\">" + doc + "</font>");
|
||||
}
|
||||
|
||||
private String layoutDoc(String doc){
|
||||
String temp;
|
||||
char c;
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
if(doc == null){
|
||||
temp = "No description available.";
|
||||
} else {
|
||||
temp = doc;
|
||||
}
|
||||
temp = temp.trim();
|
||||
|
||||
if(temp.length() == 0){
|
||||
temp = "No description available.";
|
||||
} else {
|
||||
if(temp.startsWith("<p>")){
|
||||
temp = temp.substring(3);
|
||||
temp = temp.replaceFirst("</p>", " ");
|
||||
}
|
||||
|
||||
for(int i=0; i<temp.length(); i++){
|
||||
c = temp.charAt(i);
|
||||
|
||||
if((c != '\n') && (c != '\t')){
|
||||
if(c == ' '){
|
||||
if((i+1)<temp.length()){
|
||||
if(temp.charAt(i+1) != ' '){
|
||||
writer.write(c);
|
||||
}
|
||||
} else {
|
||||
writer.write(c);
|
||||
}
|
||||
} else {
|
||||
writer.write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,273 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.cyclonedds.config.swing;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.TransferHandler;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
import org.eclipse.cyclonedds.common.view.StatusPanel;
|
||||
import org.eclipse.cyclonedds.config.data.DataAttribute;
|
||||
import org.eclipse.cyclonedds.config.data.DataElement;
|
||||
import org.eclipse.cyclonedds.config.data.DataNode;
|
||||
import org.eclipse.cyclonedds.config.data.DataValue;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaAttribute;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaElement;
|
||||
import org.eclipse.cyclonedds.config.meta.MetaNode;
|
||||
|
||||
public class ServicePanel extends JPanel implements TreeSelectionListener, ListSelectionListener {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JSplitPane northSouthSplitPane = null;
|
||||
private MetaNodeDocPane docPane = null;
|
||||
private JScrollPane docScrollPane = null;
|
||||
private JSplitPane eastWestSplitPane = null;
|
||||
private JScrollPane elementTreeScrollPane = null;
|
||||
private DataElementTree configurationElementTree = null;
|
||||
private JScrollPane tableScrollPane = null;
|
||||
private DataElementTable configurationTable = null;
|
||||
private DataElement serviceElement = null;
|
||||
private DataNodePopup popupController = null;
|
||||
private StatusPanel status = null;
|
||||
|
||||
/**
|
||||
* This is the default constructor
|
||||
*/
|
||||
public ServicePanel(DataElement serviceElement, StatusPanel status) {
|
||||
super();
|
||||
this.serviceElement = serviceElement;
|
||||
this.popupController = new DataNodePopup();
|
||||
this.status = status;
|
||||
initialize();
|
||||
}
|
||||
|
||||
public DataElement getService(){
|
||||
return this.serviceElement;
|
||||
}
|
||||
|
||||
public DataElementTable getConfigurationTable() {
|
||||
if (configurationTable == null) {
|
||||
configurationTable = new DataElementTable(this.popupController, serviceElement, this.status);
|
||||
configurationTable.getSelectionModel().addListSelectionListener(this);
|
||||
}
|
||||
return configurationTable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
TreePath selectionPath = e.getNewLeadSelectionPath();
|
||||
|
||||
if(selectionPath != null){
|
||||
this.getConfigurationTable().getSelectionModel().clearSelection();
|
||||
DataElement selection = (DataElement)(
|
||||
((DefaultMutableTreeNode)(
|
||||
selectionPath.getLastPathComponent())).getUserObject());
|
||||
this.configurationTable.getEditor().stopCellEditing();
|
||||
((DataElementTableModel)this.configurationTable.getModel()).setElement(selection);
|
||||
this.updateDocument(selection);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
if(!e.getValueIsAdjusting()){
|
||||
int selectedRow = this.getConfigurationTable().getSelectedRow();
|
||||
|
||||
if(selectedRow != -1){
|
||||
this.getConfigurationElementTree().getSelectionModel().clearSelection();
|
||||
DataNode selection = this.getConfigurationTable().getDataNodeAt(selectedRow);
|
||||
this.updateDocument(selection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransferHandler(TransferHandler t){
|
||||
super.setTransferHandler(t);
|
||||
int count = this.getComponentCount();
|
||||
|
||||
for(int i=0; i<count; i++){
|
||||
if(this.getComponent(i) instanceof JComponent){
|
||||
((JComponent)this.getComponent(i)).setTransferHandler(t);
|
||||
}
|
||||
}
|
||||
this.getConfigurationElementTree().setTransferHandler(t);
|
||||
this.getConfigurationTable().setTransferHandler(t);
|
||||
this.getDocPane().setTransferHandler(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes this
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private void initialize() {
|
||||
GridBagConstraints gridBagConstraints = new GridBagConstraints();
|
||||
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
||||
gridBagConstraints.gridy = 0;
|
||||
gridBagConstraints.weightx = 1.0;
|
||||
gridBagConstraints.weighty = 1.0;
|
||||
gridBagConstraints.gridx = 0;
|
||||
this.setSize(800, 540);
|
||||
this.setLayout(new GridBagLayout());
|
||||
this.add(getNorthSouthSplitPane(), gridBagConstraints);
|
||||
}
|
||||
|
||||
private JSplitPane getNorthSouthSplitPane() {
|
||||
if (northSouthSplitPane == null) {
|
||||
northSouthSplitPane = new JSplitPane();
|
||||
northSouthSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
|
||||
northSouthSplitPane.setDividerLocation(300);
|
||||
northSouthSplitPane.setBackground(Color.white);
|
||||
northSouthSplitPane.setLeftComponent(getEastWestSplitPane());
|
||||
northSouthSplitPane.setRightComponent(getDocScrollPane());
|
||||
northSouthSplitPane.setDividerSize(5);
|
||||
}
|
||||
return northSouthSplitPane;
|
||||
}
|
||||
/**
|
||||
* This method initializes mainSplitPane
|
||||
*
|
||||
* @return javax.swing.JSplitPane
|
||||
*/
|
||||
private JSplitPane getEastWestSplitPane() {
|
||||
if (eastWestSplitPane == null) {
|
||||
eastWestSplitPane = new JSplitPane();
|
||||
eastWestSplitPane.setDividerLocation(330);
|
||||
eastWestSplitPane.setBackground(Color.white);
|
||||
eastWestSplitPane.setLeftComponent(getElementTreeScrollPane());
|
||||
eastWestSplitPane.setRightComponent(getTableScrollPane());
|
||||
eastWestSplitPane.setDividerSize(5);
|
||||
}
|
||||
return eastWestSplitPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes elementTreeScrollPane
|
||||
*
|
||||
* @return javax.swing.JScrollPane
|
||||
*/
|
||||
private JScrollPane getElementTreeScrollPane() {
|
||||
if (elementTreeScrollPane == null) {
|
||||
elementTreeScrollPane = new JScrollPane();
|
||||
elementTreeScrollPane.setBorder(
|
||||
BorderFactory.createTitledBorder(null, "Elements",
|
||||
TitledBorder.LEFT, TitledBorder.BOTTOM,
|
||||
new Font("Dialog", Font.BOLD, 12),
|
||||
new Color(51, 51, 51)));
|
||||
elementTreeScrollPane.setViewportView(getConfigurationElementTree());
|
||||
elementTreeScrollPane.setBackground(Color.WHITE);
|
||||
}
|
||||
return elementTreeScrollPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes configurationElementTree
|
||||
*
|
||||
* @return javax.swing.JTree
|
||||
*/
|
||||
private DataElementTree getConfigurationElementTree() {
|
||||
if (configurationElementTree == null) {
|
||||
configurationElementTree = new DataElementTree(serviceElement, null, this.status);
|
||||
configurationElementTree.addTreeSelectionListener(this);
|
||||
this.updateDocument(serviceElement);
|
||||
}
|
||||
return configurationElementTree;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes tableScrollPane
|
||||
*
|
||||
* @return javax.swing.JScrollPane
|
||||
*/
|
||||
private JScrollPane getTableScrollPane() {
|
||||
if (tableScrollPane == null) {
|
||||
tableScrollPane = new JScrollPane();
|
||||
tableScrollPane.setViewportView(getConfigurationTable());
|
||||
tableScrollPane.setBorder(BorderFactory.createTitledBorder(null, "Attributes", TitledBorder.RIGHT, TitledBorder.BOTTOM, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
|
||||
//tableScrollPane.setBackground(Color.WHITE);
|
||||
}
|
||||
return tableScrollPane;
|
||||
}
|
||||
|
||||
private JScrollPane getDocScrollPane() {
|
||||
if (docScrollPane == null) {
|
||||
docScrollPane = new JScrollPane();
|
||||
docScrollPane.setViewportView(getDocPane());
|
||||
docScrollPane.setBorder(BorderFactory.createTitledBorder(null, "Documentation", TitledBorder.LEFT, TitledBorder.BOTTOM, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
|
||||
docScrollPane.setBackground(Color.WHITE);
|
||||
}
|
||||
return docScrollPane;
|
||||
}
|
||||
|
||||
private MetaNodeDocPane getDocPane(){
|
||||
if (docPane == null) {
|
||||
docPane = new MetaNodeDocPane(false, false);
|
||||
}
|
||||
return docPane;
|
||||
}
|
||||
|
||||
private void updateDocument(DataNode node){
|
||||
MetaNode meta = null;
|
||||
DataNode parent;
|
||||
|
||||
if(node instanceof DataValue){
|
||||
parent = node.getParent();
|
||||
|
||||
if(parent != null){
|
||||
meta = parent.getMetadata();
|
||||
}
|
||||
} else {
|
||||
meta = node.getMetadata();
|
||||
}
|
||||
|
||||
|
||||
this.getDocScrollPane().setBorder(BorderFactory.createTitledBorder(null,
|
||||
"Documentation for '" + this.getXPath(node) + "'",
|
||||
TitledBorder.LEFT, TitledBorder.BOTTOM,
|
||||
new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
|
||||
this.getDocPane().setNode(meta);
|
||||
}
|
||||
|
||||
private String getXPath(DataNode node){
|
||||
String result;
|
||||
DataNode curNode = node;
|
||||
|
||||
result = "";
|
||||
|
||||
while(curNode != null){
|
||||
if(curNode instanceof DataElement){
|
||||
result = "/" + ((MetaElement)curNode.getMetadata()).getName() + result;
|
||||
} else if(curNode instanceof DataAttribute){
|
||||
result = "[@" + ((MetaAttribute)curNode.getMetadata()).getName() + "]" + result;
|
||||
}
|
||||
curNode = curNode.getParent();
|
||||
}
|
||||
result = "/" + result;
|
||||
return result;
|
||||
}
|
||||
}
|
BIN
src/tools/config/resources/ptlogoc16.png
Executable file
BIN
src/tools/config/resources/ptlogoc16.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 717 B |
BIN
src/tools/config/resources/ptlogoc24.png
Executable file
BIN
src/tools/config/resources/ptlogoc24.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
src/tools/config/resources/ptlogoc32.png
Executable file
BIN
src/tools/config/resources/ptlogoc32.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 929 B |
BIN
src/tools/config/resources/ptlogoc48.png
Executable file
BIN
src/tools/config/resources/ptlogoc48.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
21
src/tools/ddsls/CMakeLists.txt
Normal file
21
src/tools/ddsls/CMakeLists.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
#
|
||||
# Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
#
|
||||
# This program and the accompanying materials are made available under the
|
||||
# terms of the Eclipse Public License v. 2.0 which is available at
|
||||
# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
# v. 1.0 which is available at
|
||||
# http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
#
|
||||
find_package(Abstraction REQUIRED)
|
||||
|
||||
add_executable(ddsls ddsls.c)
|
||||
target_link_libraries(ddsls ddsc OSAPI)
|
||||
|
||||
install(
|
||||
TARGETS ddsls
|
||||
DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
COMPONENT dev
|
||||
)
|
838
src/tools/ddsls/ddsls.c
Normal file
838
src/tools/ddsls/ddsls.c
Normal file
|
@ -0,0 +1,838 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#include "os/os.h"
|
||||
#include "ddsc/dds.h"
|
||||
#include "dds_builtinTopics.h"
|
||||
|
||||
|
||||
#define DURATION_INFINITE_SEC 0x7fffffff
|
||||
#define DURATION_INFINITE_NSEC 0x7fffffff
|
||||
#define zero(pp,sz) _zero((void**)pp,sz)
|
||||
|
||||
// FIXME Temporary workaround for lack of wait_for_historical implementation. Remove this on completion of CHAM-268.
|
||||
#define dds_reader_wait_for_historical_data(a,b) DDS_SUCCESS; dds_sleepfor(DDS_MSECS(200));
|
||||
|
||||
/* Enable DEBUG for printing debug statements*/
|
||||
//#define DEBUG
|
||||
|
||||
#ifdef DEBUG
|
||||
#define PRINTD printf
|
||||
#else
|
||||
#define PRINTD(...)
|
||||
#endif
|
||||
|
||||
#define DCPSTOPIC_FLAG 1
|
||||
#define DCPSPARTICIPANT_FLAG (1<<1)
|
||||
#define DCPSSUBSCRIPTION_FLAG (1<<2)
|
||||
#define DCPSPUBLICATION_FLAG (1<<3)
|
||||
#define CMPARTICIPANT_FLAG (1<<4)
|
||||
#define CMPUBLISHER_FLAG (1<<5)
|
||||
#define CMSUBSCRIBER_FLAG (1<<6)
|
||||
#define CMDATAREADER_FLAG (1<<7)
|
||||
#define CMDATAWRITER_FLAG (1<<8)
|
||||
|
||||
static struct topictab{
|
||||
const char *name;
|
||||
const int flag;
|
||||
} topictab[] = {
|
||||
{"dcpstopic", DCPSTOPIC_FLAG},
|
||||
{"dcpsparticipant", DCPSPARTICIPANT_FLAG},
|
||||
{"dcpssubscription", DCPSSUBSCRIPTION_FLAG},
|
||||
{"dcpspublication", DCPSPUBLICATION_FLAG},
|
||||
{"cmparticipant", CMPARTICIPANT_FLAG},
|
||||
{"cmpublisher", CMPUBLISHER_FLAG},
|
||||
{"cmsubscriber", CMSUBSCRIBER_FLAG},
|
||||
{"cmdatareader", CMDATAREADER_FLAG},
|
||||
{"cmdatawriter", CMDATAWRITER_FLAG},
|
||||
|
||||
};
|
||||
#define TOPICTAB_SIZE (sizeof(topictab)/sizeof(struct topictab))
|
||||
|
||||
const unsigned int MAX_SAMPLES = 10;
|
||||
unsigned int states = DDS_ANY_SAMPLE_STATE | DDS_ANY_VIEW_STATE | DDS_ANY_INSTANCE_STATE;
|
||||
int status = 0;
|
||||
int reader_wait = 0;
|
||||
dds_entity_t participant;
|
||||
dds_entity_t subscriber;
|
||||
dds_domainid_t did = DDS_DOMAIN_DEFAULT;
|
||||
dds_sample_info_t info[10];
|
||||
dds_qos_t* tqos;
|
||||
dds_qos_t* sqos;
|
||||
|
||||
void _zero(void ** samples, int size) {
|
||||
int i;
|
||||
for(i = 0; i < size;i++) {
|
||||
samples[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int duration_is_infinite(const DDS_Duration_t *d){
|
||||
return d->sec == DURATION_INFINITE_SEC && d->nanosec == DURATION_INFINITE_NSEC;
|
||||
}
|
||||
|
||||
void qp_durability (const DDS_DurabilityQosPolicy *q, FILE *fp)
|
||||
{
|
||||
char buf[40];
|
||||
char *k;
|
||||
switch (q->kind)
|
||||
{
|
||||
case DDS_VOLATILE_DURABILITY_QOS: k = "volatile"; break;
|
||||
case DDS_TRANSIENT_LOCAL_DURABILITY_QOS: k = "transient-local"; break;
|
||||
case DDS_TRANSIENT_DURABILITY_QOS: k = "transient"; break;
|
||||
case DDS_PERSISTENT_DURABILITY_QOS: k = "persistent"; break;
|
||||
default: (void) snprintf (buf, sizeof (buf), "invalid (%d)", (int) q->kind); k = buf; break;
|
||||
}
|
||||
fprintf (fp, " durability: kind = %s\n", k);
|
||||
}
|
||||
|
||||
void qp_deadline (const DDS_DeadlineQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp," deadline: period = ");
|
||||
if (duration_is_infinite(&q->period))
|
||||
fprintf (fp, "infinite\n");
|
||||
else
|
||||
fprintf (fp,"%d.%09u\n", q->period.sec, q->period.nanosec);
|
||||
}
|
||||
|
||||
void qp_latency_budget (const DDS_LatencyBudgetQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp," latency_budget: duration = ");
|
||||
if (duration_is_infinite (&q->duration))
|
||||
fprintf (fp,"infinite\n");
|
||||
else
|
||||
fprintf (fp,"%d.%09u\n", q->duration.sec, q->duration.nanosec);
|
||||
}
|
||||
|
||||
void qp_liveliness (const DDS_LivelinessQosPolicy *q, FILE *fp)
|
||||
{
|
||||
char buf[40];
|
||||
char *k;
|
||||
switch (q->kind)
|
||||
{
|
||||
case DDS_AUTOMATIC_LIVELINESS_QOS: k = "automatic"; break;
|
||||
case DDS_MANUAL_BY_PARTICIPANT_LIVELINESS_QOS: k = "manual-by-participant"; break;
|
||||
case DDS_MANUAL_BY_TOPIC_LIVELINESS_QOS: k = "manual-by-topic"; break;
|
||||
default: (void) snprintf (buf, sizeof (buf), "invalid (%d)", (int) q->kind); k = buf; break;
|
||||
}
|
||||
fprintf (fp," liveliness: kind = %s, lease_duration = ", k);
|
||||
if (duration_is_infinite(&q->lease_duration))
|
||||
fprintf (fp,"infinite\n");
|
||||
else
|
||||
fprintf (fp,"%d.%09u\n", q->lease_duration.sec, q->lease_duration.nanosec);
|
||||
}
|
||||
|
||||
void qp_reliability (const DDS_ReliabilityQosPolicy *q, FILE *fp)
|
||||
{
|
||||
char buf[40];
|
||||
char *k;
|
||||
switch (q->kind)
|
||||
{
|
||||
case DDS_BEST_EFFORT_RELIABILITY_QOS: k = "best-effort"; break;
|
||||
case DDS_RELIABLE_RELIABILITY_QOS: k = "reliable"; break;
|
||||
default: (void) snprintf (buf, sizeof (buf), "invalid (%d)", (int) q->kind); k = buf; break;
|
||||
}
|
||||
fprintf (fp," reliability: kind = %s, max_blocking_time = ", k);
|
||||
if (duration_is_infinite(&q->max_blocking_time))
|
||||
fprintf (fp,"infinite");
|
||||
else
|
||||
fprintf (fp,"%d.%09u", q->max_blocking_time.sec, q->max_blocking_time.nanosec);
|
||||
fprintf (fp,", synchronous = %s\n", q->synchronous ? "true" : "false");
|
||||
}
|
||||
|
||||
void qp_transport_priority (const DDS_TransportPriorityQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp," transport_priority: priority = %d\n", q->value);
|
||||
}
|
||||
|
||||
void qp_lifespan (const DDS_LifespanQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp," lifespan: duration = ");
|
||||
if (duration_is_infinite(&q->duration))
|
||||
fprintf (fp, "infinite\n");
|
||||
else
|
||||
fprintf (fp, "%d.%09u\n", q->duration.sec, q->duration.nanosec);
|
||||
}
|
||||
|
||||
void qp_destination_order (const DDS_DestinationOrderQosPolicy *q, FILE *fp)
|
||||
{
|
||||
char buf[40];
|
||||
char *k;
|
||||
switch (q->kind)
|
||||
{
|
||||
case DDS_BY_RECEPTION_TIMESTAMP_DESTINATIONORDER_QOS: k = "by-reception-timestamp"; break;
|
||||
case DDS_BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS: k = "by-source-timestamp"; break;
|
||||
default: (void) snprintf (buf, sizeof (buf), "invalid (%d)", (int) q->kind); k = buf; break;
|
||||
}
|
||||
fprintf (fp," destination_order: kind = %s\n", k);
|
||||
}
|
||||
|
||||
void qp_history_kind_1 (DDS_HistoryQosPolicyKind kind, int indent, FILE *fp)
|
||||
{
|
||||
char buf[40];
|
||||
char *k;
|
||||
switch (kind)
|
||||
{
|
||||
case DDS_KEEP_LAST_HISTORY_QOS: k = "keep-last"; break;
|
||||
case DDS_KEEP_ALL_HISTORY_QOS: k = "keep-all"; break;
|
||||
default: (void) snprintf (buf, sizeof (buf), "invalid (%d)", (int) kind); k = buf; break;
|
||||
}
|
||||
fprintf (fp,"%*.*shistory: kind = %s", indent, indent, "", k);
|
||||
}
|
||||
|
||||
void qp_history (const DDS_HistoryQosPolicy *q, FILE *fp)
|
||||
{
|
||||
qp_history_kind_1 (q->kind, 2,fp);
|
||||
if (q->kind == DDS_KEEP_LAST_HISTORY_QOS)
|
||||
fprintf (fp,", depth = %d\n", q->depth);
|
||||
else
|
||||
fprintf (fp,", (depth = %d)\n", q->depth);
|
||||
}
|
||||
|
||||
void qp_resource_limits_1(int max_samples, int max_instances, int max_samples_per_instance, int indent, FILE *fp)
|
||||
{
|
||||
fprintf (fp,"%*.*sresource_limits: max_samples = ", indent, indent, "");
|
||||
if (max_samples == DDS_LENGTH_UNLIMITED)
|
||||
fprintf (fp,"unlimited");
|
||||
else
|
||||
fprintf (fp, "%d", max_samples);
|
||||
fprintf (fp, ", max_instances = ");
|
||||
if (max_instances == DDS_LENGTH_UNLIMITED)
|
||||
fprintf (fp, "unlimited");
|
||||
else
|
||||
fprintf (fp, "%d", max_instances);
|
||||
fprintf (fp,", max_samples_per_instance = ");
|
||||
if (max_samples_per_instance == DDS_LENGTH_UNLIMITED)
|
||||
fprintf (fp,"unlimited\n");
|
||||
else
|
||||
fprintf (fp,"%d\n", max_samples_per_instance);
|
||||
}
|
||||
|
||||
void qp_resource_limits (const DDS_ResourceLimitsQosPolicy *q, FILE *fp)
|
||||
{
|
||||
qp_resource_limits_1 (q->max_samples, q->max_instances, q->max_samples_per_instance, 2,fp);
|
||||
}
|
||||
|
||||
void qp_ownership (const DDS_OwnershipQosPolicy *q, FILE *fp)
|
||||
{
|
||||
char buf[40];
|
||||
char *k;
|
||||
switch (q->kind)
|
||||
{
|
||||
case DDS_SHARED_OWNERSHIP_QOS: k = "shared"; break;
|
||||
case DDS_EXCLUSIVE_OWNERSHIP_QOS: k = "exclusive"; break;
|
||||
default: (void) snprintf (buf, sizeof (buf), "invalid (%d)", (int) q->kind); k = buf; break;
|
||||
}
|
||||
fprintf (fp," ownership: kind = %s\n", k);
|
||||
}
|
||||
|
||||
unsigned printable_seq_length(const unsigned char *as, unsigned n)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < n; i++) {
|
||||
if (as[i] < 32 || as[i] >= 127)
|
||||
break;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void print_octetseq (const DDS_octSeq *v, FILE *fp)
|
||||
{
|
||||
|
||||
unsigned i, n;
|
||||
const char *sep = "";
|
||||
fprintf (fp, "%u<", v->_length);
|
||||
i = 0;
|
||||
while (i < v->_length)
|
||||
{
|
||||
if ((n = printable_seq_length (v->_buffer + i, v->_length - i)) < 4)
|
||||
{
|
||||
while (n--)
|
||||
fprintf (fp,"%s%u", sep, v->_buffer[i++]);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (fp, "\"%*.*s\"", n, n, v->_buffer + i);
|
||||
i += n;
|
||||
}
|
||||
sep = ",";
|
||||
}
|
||||
fprintf (fp,">");
|
||||
}
|
||||
|
||||
void qp_topic_data (const DDS_TopicDataQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp, " topic_data: value = ");
|
||||
print_octetseq (&q->value,fp);
|
||||
fprintf (fp, "\n");
|
||||
}
|
||||
|
||||
void qp_user_data (const DDS_UserDataQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp, " user_data: value = ");
|
||||
print_octetseq (&q->value,fp);
|
||||
fprintf (fp, "\n");
|
||||
}
|
||||
|
||||
void qp_time_based_filter (const DDS_TimeBasedFilterQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp," time_based_filter: minimum_separation = ");
|
||||
if (duration_is_infinite (&q->minimum_separation))
|
||||
fprintf (fp,"infinite\n");
|
||||
else
|
||||
fprintf (fp,"%d.%09u\n", q->minimum_separation.sec, q->minimum_separation.nanosec);
|
||||
}
|
||||
|
||||
void qp_presentation (const DDS_PresentationQosPolicy *q, FILE *fp)
|
||||
{
|
||||
char buf[40];
|
||||
char *k;
|
||||
switch (q->access_scope)
|
||||
{
|
||||
case DDS_INSTANCE_PRESENTATION_QOS: k = "instance"; break;
|
||||
case DDS_TOPIC_PRESENTATION_QOS: k = "topic"; break;
|
||||
case DDS_GROUP_PRESENTATION_QOS: k = "group"; break;
|
||||
default: (void) snprintf (buf, sizeof (buf), "invalid (%d)", (int) q->access_scope); k = buf; break;
|
||||
}
|
||||
fprintf (fp, " presentation: scope = %s, coherent_access = %s, ordered_access = %s\n", k,
|
||||
q->coherent_access ? "true" : "false",
|
||||
q->ordered_access ? "true" : "false");
|
||||
}
|
||||
|
||||
void qp_partition (const DDS_PartitionQosPolicy *q, FILE *fp)
|
||||
{
|
||||
const DDS_StringSeq *s = &q->name;
|
||||
fprintf (fp, " partition: name = ");
|
||||
if (s->_length == 0)
|
||||
fprintf (fp, "(default)");
|
||||
else if (s->_length == 1)
|
||||
fprintf (fp, "%s", s->_buffer[0]);
|
||||
else
|
||||
{
|
||||
unsigned i;
|
||||
fprintf (fp,"{");
|
||||
for (i = 0; i < s->_length; i++)
|
||||
fprintf (fp, "%s%s", (i > 0) ? "," : "", s->_buffer[i]);
|
||||
fprintf (fp,"}");
|
||||
}
|
||||
fprintf (fp,"\n");
|
||||
}
|
||||
|
||||
void qp_group_data (const DDS_GroupDataQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp," group_data: value = ");
|
||||
print_octetseq (&q->value,fp);
|
||||
fprintf (fp,"\n");
|
||||
}
|
||||
|
||||
void qp_ownership_strength (const DDS_OwnershipStrengthQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp," ownership_strength: value = %d\n", q->value);
|
||||
}
|
||||
|
||||
void qp_product_data (const DDS_ProductDataQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp," product_data: value = %s\n", q->value);
|
||||
}
|
||||
|
||||
void qp_entity_factory (const DDS_EntityFactoryQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp," entity_factory: autoenable_created_entities = %s\n",
|
||||
q->autoenable_created_entities ? "true" : "false");
|
||||
}
|
||||
|
||||
void qp_share (const DDS_ShareQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp," share: enable = %s", q->enable ? "true" : "false");
|
||||
if (q->enable)
|
||||
fprintf (fp,", name = %s", q->name);
|
||||
fprintf (fp,"\n");
|
||||
}
|
||||
|
||||
void qp_writer_data_lifecycle (const DDS_WriterDataLifecycleQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp," writer_data_lifecycle: autodispose_unregistered_instances = %s, autopurge_suspended_samples_delay = ",
|
||||
q->autodispose_unregistered_instances ? "true" : "false");
|
||||
if (duration_is_infinite (&q->autopurge_suspended_samples_delay))
|
||||
fprintf (fp,"infinite");
|
||||
else
|
||||
fprintf (fp,"%d.%09u", q->autopurge_suspended_samples_delay.sec, q->autopurge_suspended_samples_delay.nanosec);
|
||||
fprintf (fp,", autounregister_instance_delay = ");
|
||||
if (duration_is_infinite (&q->autounregister_instance_delay))
|
||||
fprintf (fp,"infinite\n");
|
||||
else
|
||||
fprintf (fp,"%d.%09u\n", q->autounregister_instance_delay.sec, q->autounregister_instance_delay.nanosec);
|
||||
}
|
||||
|
||||
void qp_reader_data_lifecycle (const DDS_ReaderDataLifecycleQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp," reader_data_lifecycle: autopurge_nowriter_samples_delay = ");
|
||||
if (duration_is_infinite (&q->autopurge_nowriter_samples_delay))
|
||||
fprintf (fp,"infinite");
|
||||
else
|
||||
fprintf (fp,"%d.%09u", q->autopurge_nowriter_samples_delay.sec, q->autopurge_nowriter_samples_delay.nanosec);
|
||||
fprintf (fp,", autopurge_disposed_samples_delay = ");
|
||||
if (duration_is_infinite (&q->autopurge_disposed_samples_delay))
|
||||
fprintf (fp,"infinite");
|
||||
else
|
||||
fprintf (fp,"%d.%09u", q->autopurge_disposed_samples_delay.sec, q->autopurge_disposed_samples_delay.nanosec);
|
||||
fprintf (fp,", enable_invalid_samples = %s\n", q->enable_invalid_samples ? "true" : "false");
|
||||
}
|
||||
|
||||
void qp_subscription_keys (const DDS_UserKeyQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp," subscription_keys: enable = %s expression = %s\n", q->enable ? "true" : "false", q->expression);
|
||||
}
|
||||
|
||||
void qp_reader_lifespan (const DDS_ReaderLifespanQosPolicy *q, FILE *fp)
|
||||
{
|
||||
fprintf (fp," reader_lifespan: use_lifespan = %s, ", q->use_lifespan ? "true" : "false");
|
||||
if (!q->use_lifespan)
|
||||
fprintf (fp,"(");
|
||||
fprintf (fp,"duration = ");
|
||||
if (duration_is_infinite (&q->duration))
|
||||
fprintf (fp,"infinite");
|
||||
else
|
||||
fprintf (fp,"%d.%09u", q->duration.sec, q->duration.nanosec);
|
||||
if (!q->use_lifespan)
|
||||
fprintf (fp,")");
|
||||
fprintf (fp,"\n");
|
||||
}
|
||||
|
||||
void print_dcps_topic(FILE *fp){
|
||||
DDS_TopicBuiltinTopicData * dcps_topic_samples[10];
|
||||
dds_entity_t dcps_topic_reader;
|
||||
int i = 0;
|
||||
dcps_topic_reader = dds_create_reader(participant, DDS_BUILTIN_TOPIC_DCPSTOPIC, NULL, NULL);
|
||||
PRINTD("DCPSTopic Reader Create: %s\n", dds_err_str(dcps_topic_reader));
|
||||
reader_wait = dds_reader_wait_for_historical_data(dcps_topic_reader, DDS_SECS(5));
|
||||
PRINTD("reader wait status: %d, %s \n", reader_wait, dds_err_str(reader_wait));
|
||||
while(true){
|
||||
zero(dcps_topic_samples, MAX_SAMPLES);
|
||||
status = dds_take_mask(dcps_topic_reader, (void**)dcps_topic_samples, info, MAX_SAMPLES, MAX_SAMPLES, states);
|
||||
PRINTD("DDS reading samples returns %d \n", status);
|
||||
for(i = 0; i < status; i++) {
|
||||
DDS_TopicBuiltinTopicData * data = dcps_topic_samples[i];
|
||||
fprintf(fp,"TOPIC:\n");
|
||||
fprintf(fp," key = %u:%u:%u \n", (unsigned) data->key[0], (unsigned) data->key[1], (unsigned) data->key[2]);
|
||||
fprintf(fp," name = %s\n", data->name);
|
||||
fprintf(fp," type_name = %s\n", data->type_name);
|
||||
qp_durability (&data->durability,fp);
|
||||
qp_deadline (&data->deadline,fp);
|
||||
qp_latency_budget (&data->latency_budget,fp);
|
||||
qp_liveliness (&data->liveliness,fp);
|
||||
qp_reliability (&data->reliability,fp);
|
||||
qp_transport_priority (&data->transport_priority,fp);
|
||||
qp_lifespan (&data->lifespan,fp);
|
||||
qp_destination_order (&data->destination_order,fp);
|
||||
qp_history (&data->history,fp);
|
||||
qp_resource_limits (&data->resource_limits,fp);
|
||||
qp_ownership (&data->ownership,fp);
|
||||
qp_topic_data (&data->topic_data,fp);
|
||||
}
|
||||
if(status > 0) {
|
||||
status = dds_return_loan(dcps_topic_reader, (void**)dcps_topic_samples, status);
|
||||
}
|
||||
if(status <= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print_dcps_participant(FILE *fp){
|
||||
|
||||
DDS_ParticipantBuiltinTopicData * dcps_participant_samples[10];
|
||||
dds_entity_t dcps_participant_reader;
|
||||
int i = 0;
|
||||
dcps_participant_reader = dds_create_reader(participant, DDS_BUILTIN_TOPIC_DCPSPARTICIPANT, NULL, NULL);
|
||||
PRINTD("DCPSSubscription Reader Create: %s\n", dds_err_str(dcps_participant_reader));
|
||||
reader_wait = dds_reader_wait_for_historical_data(dcps_participant_reader, DDS_SECS(5));
|
||||
PRINTD("reader wait status: %d, %s \n", reader_wait, dds_err_str(reader_wait));
|
||||
while(true){
|
||||
zero(dcps_participant_samples, MAX_SAMPLES);
|
||||
status = dds_take_mask(dcps_participant_reader, (void**)dcps_participant_samples, info, MAX_SAMPLES, MAX_SAMPLES, states);
|
||||
PRINTD("DDS reading samples returns %d \n", status);
|
||||
for(i = 0; i < status; i++) {
|
||||
DDS_ParticipantBuiltinTopicData *data = dcps_participant_samples[i];
|
||||
fprintf(fp,"PARTICIPANT:\n");
|
||||
fprintf(fp," key = %u:%u:%u \n", (unsigned) data->key[0], (unsigned) data->key[1], (unsigned) data->key[2]);
|
||||
qp_user_data(&data->user_data,fp);
|
||||
}
|
||||
if(status > 0) {
|
||||
status = dds_return_loan(dcps_participant_reader, (void**)dcps_participant_samples, status);
|
||||
}
|
||||
if(status <= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print_dcps_subscription(FILE *fp){
|
||||
DDS_SubscriptionBuiltinTopicData * dcps_subscription_samples[10];
|
||||
dds_entity_t dcps_subscription_reader;
|
||||
int i = 0;
|
||||
dcps_subscription_reader = dds_create_reader(participant, DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION, NULL, NULL);
|
||||
PRINTD("DCPSParticipant Reader Create: %s\n", dds_err_str(dcps_subscription_reader));
|
||||
reader_wait = dds_reader_wait_for_historical_data(dcps_subscription_reader, DDS_SECS(5));
|
||||
PRINTD("reader wait status: %d, %s \n", reader_wait, dds_err_str(reader_wait));
|
||||
while(true){
|
||||
zero(dcps_subscription_samples, MAX_SAMPLES);
|
||||
status = dds_take_mask(dcps_subscription_reader, (void**)dcps_subscription_samples, info, MAX_SAMPLES, MAX_SAMPLES, states);
|
||||
PRINTD("DDS reading samples returns %d \n", status);
|
||||
for(i = 0; i < status; i++) {
|
||||
DDS_SubscriptionBuiltinTopicData *data = dcps_subscription_samples[i];
|
||||
fprintf(fp,"SUBSCRIPTION:\n");
|
||||
fprintf(fp," key = %u:%u:%u\n", (uint32_t) data->key[0], (uint32_t) data->key[1], (uint32_t) data->key[2]);
|
||||
fprintf(fp," participant_key = %u:%u:%u\n", (uint32_t) data->participant_key[0], (uint32_t) data->participant_key[1], (uint32_t) data->participant_key[2]);
|
||||
fprintf(fp," topic_name = %s\n", data->topic_name);
|
||||
fprintf(fp," type_name = %s\n", data->type_name);
|
||||
qp_durability(&data->durability,fp);
|
||||
qp_deadline(&data->deadline,fp);
|
||||
qp_latency_budget(&data->latency_budget,fp);
|
||||
qp_liveliness(&data->liveliness,fp);
|
||||
qp_reliability(&data->reliability,fp);
|
||||
qp_ownership(&data->ownership,fp);
|
||||
qp_destination_order(&data->destination_order,fp);
|
||||
qp_user_data(&data->user_data,fp);
|
||||
qp_time_based_filter(&data->time_based_filter,fp);
|
||||
qp_presentation(&data->presentation,fp);
|
||||
qp_partition(&data->partition,fp);
|
||||
qp_topic_data(&data->topic_data,fp);
|
||||
qp_group_data(&data->group_data,fp);
|
||||
}
|
||||
if(status > 0) {
|
||||
status = dds_return_loan(dcps_subscription_reader, (void**)dcps_subscription_samples, status);
|
||||
}
|
||||
if(status <= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print_dcps_publication(FILE *fp){
|
||||
DDS_PublicationBuiltinTopicData * dcps_publication_samples[10];
|
||||
dds_entity_t dcps_publication_reader;
|
||||
int i = 0;
|
||||
dcps_publication_reader = dds_create_reader(participant, DDS_BUILTIN_TOPIC_DCPSPUBLICATION, NULL, NULL);
|
||||
PRINTD("DCPSPublication Reader Create: %s\n", dds_err_str(dcps_publication_reader));
|
||||
reader_wait = dds_reader_wait_for_historical_data(dcps_publication_reader, DDS_SECS(5));
|
||||
PRINTD("reader wait status: %d, %s \n", reader_wait, dds_err_str(reader_wait));
|
||||
while(true){
|
||||
zero(dcps_publication_samples, MAX_SAMPLES);
|
||||
status = dds_take_mask(dcps_publication_reader, (void**)dcps_publication_samples, info, MAX_SAMPLES, MAX_SAMPLES, states);
|
||||
PRINTD("DDS reading samples returns %d \n", status);
|
||||
for(i = 0; i < status; i++) {
|
||||
DDS_PublicationBuiltinTopicData *data = dcps_publication_samples[i];
|
||||
fprintf(fp,"PUBLICATION:\n");
|
||||
fprintf(fp," key = %u:%u:%u\n", (uint32_t) data->key[0], (uint32_t) data->key[1], (uint32_t) data->key[2]);
|
||||
fprintf(fp," participant_key = %u:%u:%u\n", (uint32_t) data->participant_key[0], (uint32_t) data->participant_key[1], (uint32_t) data->participant_key[2]);
|
||||
fprintf(fp," topic_name = %s\n", data->topic_name);
|
||||
fprintf(fp," type_name = %s\n", data->type_name);
|
||||
qp_durability(&data->durability,fp);
|
||||
qp_deadline(&data->deadline,fp);
|
||||
qp_latency_budget(&data->latency_budget,fp);
|
||||
qp_liveliness(&data->liveliness,fp);
|
||||
qp_reliability(&data->reliability,fp);
|
||||
qp_lifespan (&data->lifespan,fp);
|
||||
qp_destination_order (&data->destination_order,fp);
|
||||
qp_user_data (&data->user_data,fp);
|
||||
qp_ownership (&data->ownership,fp);
|
||||
qp_ownership_strength (&data->ownership_strength,fp);
|
||||
qp_presentation (&data->presentation,fp);
|
||||
qp_partition (&data->partition,fp);
|
||||
qp_topic_data (&data->topic_data,fp);
|
||||
qp_group_data (&data->group_data,fp);
|
||||
}
|
||||
if(status > 0) {
|
||||
status = dds_return_loan(dcps_publication_reader, (void**)dcps_publication_samples, status);
|
||||
}
|
||||
if(status <= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print_cm_participant(FILE *fp){
|
||||
DDS_CMParticipantBuiltinTopicData * cm_participant_samples[10];
|
||||
dds_entity_t cm_participant_reader;
|
||||
int i = 0;
|
||||
cm_participant_reader = dds_create_reader(participant, DDS_BUILTIN_TOPIC_CMPARTICIPANT, NULL, NULL);
|
||||
PRINTD("CMParticipant Reader Create: %s\n", dds_err_str(cm_participant_reader));
|
||||
reader_wait = dds_reader_wait_for_historical_data(cm_participant_reader, DDS_SECS(5));
|
||||
PRINTD("reader wait status: %d, %s \n", reader_wait, dds_err_str(reader_wait));
|
||||
while(true){
|
||||
zero(cm_participant_samples, MAX_SAMPLES);
|
||||
status = dds_take_mask(cm_participant_reader, (void**)cm_participant_samples, info, MAX_SAMPLES, MAX_SAMPLES, states);
|
||||
PRINTD("DDS reading samples returns %d \n", status);
|
||||
for(i = 0; i < status; i++) {
|
||||
DDS_CMParticipantBuiltinTopicData *data = cm_participant_samples[i];
|
||||
fprintf(fp,"CMPARTICIPANT:\n");
|
||||
fprintf(fp," key = %u:%u:%u \n", (unsigned) data->key[0], (unsigned) data->key[1], (unsigned) data->key[2]);
|
||||
qp_product_data(&data->product,fp);
|
||||
}
|
||||
if(status > 0) {
|
||||
status = dds_return_loan(cm_participant_reader, (void**)cm_participant_samples, status);
|
||||
}
|
||||
if(status <= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print_cm_publisher(FILE *fp){
|
||||
DDS_CMPublisherBuiltinTopicData * cm_publisher_samples[10];
|
||||
dds_entity_t cm_publisher_reader;
|
||||
int i = 0;
|
||||
cm_publisher_reader = dds_create_reader(participant, DDS_BUILTIN_TOPIC_CMPUBLISHER, NULL, NULL);
|
||||
PRINTD("CMPublisher Reader Create: %s\n", dds_err_str(cm_publisher_reader));
|
||||
reader_wait = dds_reader_wait_for_historical_data(cm_publisher_reader, DDS_SECS(5));
|
||||
PRINTD("reader wait status: %d, %s \n", reader_wait, dds_err_str(reader_wait));
|
||||
while(true){
|
||||
zero(cm_publisher_samples, MAX_SAMPLES);
|
||||
status = dds_take_mask(cm_publisher_reader, (void**)cm_publisher_samples, info, MAX_SAMPLES, MAX_SAMPLES, states);
|
||||
PRINTD("DDS reading samples returns %d \n", status);
|
||||
for(i = 0; i < status; i++) {
|
||||
DDS_CMPublisherBuiltinTopicData *data = cm_publisher_samples[i];
|
||||
fprintf(fp,"CMPUBLISHER:\n");
|
||||
fprintf(fp," key = %u:%u:%u \n", (unsigned) data->key[0], (unsigned) data->key[1], (unsigned) data->key[2]);
|
||||
fprintf(fp," participant_key = %u:%u:%u\n", (unsigned) data->key[0], (unsigned) data->key[1], (unsigned) data->key[2]);
|
||||
fprintf(fp," name = %s\n", data->name);
|
||||
qp_entity_factory(&data->entity_factory,fp);
|
||||
qp_partition(&data->partition,fp);
|
||||
qp_product_data(&data->product,fp);
|
||||
}
|
||||
if(status > 0) {
|
||||
status = dds_return_loan(cm_publisher_reader, (void**)cm_publisher_samples, status);
|
||||
}
|
||||
if(status <= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print_cm_subscriber(FILE *fp){
|
||||
DDS_CMSubscriberBuiltinTopicData * cm_subscriber_samples[10];
|
||||
dds_entity_t cm_subscriber_reader;
|
||||
int i = 0;
|
||||
cm_subscriber_reader = dds_create_reader(participant, DDS_BUILTIN_TOPIC_CMSUBSCRIBER, NULL, NULL);
|
||||
PRINTD("CMSubscriber Reader Create: %s\n", dds_err_str(cm_subscriber_reader));
|
||||
reader_wait = dds_reader_wait_for_historical_data(cm_subscriber_reader, DDS_SECS(5));
|
||||
PRINTD("reader wait status: %d, %s \n", reader_wait, dds_err_str(reader_wait));
|
||||
while(true){
|
||||
zero(cm_subscriber_samples, MAX_SAMPLES);
|
||||
status = dds_take_mask(cm_subscriber_reader, (void**)cm_subscriber_samples, info, MAX_SAMPLES, MAX_SAMPLES, states);
|
||||
PRINTD("DDS reading samples returns %d \n", status);
|
||||
for(i = 0; i < status; i++) {
|
||||
DDS_CMSubscriberBuiltinTopicData *data = cm_subscriber_samples[i];
|
||||
fprintf(fp,"CMSUBSCRIBER:\n");
|
||||
fprintf(fp," key = %u:%u:%u \n", (unsigned) data->key[0], (unsigned) data->key[1], (unsigned) data->key[2]);
|
||||
fprintf(fp," participant_key = %u:%u:%u\n", (unsigned) data->participant_key[0], (unsigned) data->participant_key[1], (unsigned) data->participant_key[2]);
|
||||
fprintf(fp," name = %s\n", data->name);
|
||||
qp_entity_factory(&data->entity_factory,fp);
|
||||
qp_partition(&data->partition,fp);
|
||||
qp_share(&data->share,fp);
|
||||
qp_product_data(&data->product,fp);
|
||||
}
|
||||
if(status > 0) {
|
||||
status = dds_return_loan(cm_subscriber_reader, (void**)cm_subscriber_samples, status);
|
||||
}
|
||||
if(status <= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print_cm_datawriter(FILE *fp){
|
||||
DDS_CMDataWriterBuiltinTopicData * cm_datawriter_samples[10];
|
||||
dds_entity_t cm_datawriter_reader;
|
||||
int i = 0;
|
||||
cm_datawriter_reader = dds_create_reader(participant, DDS_BUILTIN_TOPIC_CMDATAWRITER, NULL, NULL);
|
||||
PRINTD("CMDataWriter Reader Create: %s\n", dds_err_str(cm_datawriter_reader));
|
||||
reader_wait = dds_reader_wait_for_historical_data(cm_datawriter_reader, DDS_SECS(5));
|
||||
PRINTD("reader wait status: %d, %s \n", reader_wait, dds_err_str(reader_wait));
|
||||
while(true){
|
||||
zero(cm_datawriter_samples, MAX_SAMPLES);
|
||||
status = dds_take_mask(cm_datawriter_reader, (void**)cm_datawriter_samples, info, MAX_SAMPLES, MAX_SAMPLES, states);
|
||||
PRINTD("DDS reading samples returns %d \n", status);
|
||||
for(i = 0; i < status; i++) {
|
||||
DDS_CMDataWriterBuiltinTopicData *data = cm_datawriter_samples[i];
|
||||
fprintf(fp,"CMDATAWRITER:\n");
|
||||
fprintf(fp," key = %u:%u:%u \n", (unsigned) data->key[0], (unsigned) data->key[1], (unsigned) data->key[2]);
|
||||
fprintf(fp," publisher_key = %u:%u:%u\n", (unsigned) data->publisher_key[0], (unsigned) data->publisher_key[1], (unsigned) data->publisher_key[2]);
|
||||
fprintf(fp," name = %s\n", data->name);
|
||||
qp_history (&data->history,fp);
|
||||
qp_resource_limits (&data->resource_limits,fp);
|
||||
qp_writer_data_lifecycle (&data->writer_data_lifecycle,fp);
|
||||
qp_product_data (&data->product,fp);
|
||||
}
|
||||
if(status > 0) {
|
||||
status = dds_return_loan(cm_datawriter_reader, (void**)cm_datawriter_samples, status);
|
||||
}
|
||||
if(status <= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print_cm_datareader(FILE *fp){
|
||||
DDS_CMDataReaderBuiltinTopicData * cm_datareader_samples[10];
|
||||
dds_entity_t cm_datareader_reader;
|
||||
int i = 0;
|
||||
cm_datareader_reader = dds_create_reader(participant, DDS_BUILTIN_TOPIC_CMDATAREADER, NULL, NULL);
|
||||
PRINTD("CMDataReader Reader Create: %s\n", dds_err_str(cm_datareader_reader));
|
||||
reader_wait = dds_reader_wait_for_historical_data(cm_datareader_reader, DDS_SECS(5));
|
||||
PRINTD("reader wait status: %d, %s \n", reader_wait, dds_err_str(reader_wait));
|
||||
while(true){
|
||||
zero(cm_datareader_samples, MAX_SAMPLES);
|
||||
status = dds_take_mask(cm_datareader_reader, (void**)cm_datareader_samples, info, MAX_SAMPLES, MAX_SAMPLES, states);
|
||||
PRINTD("DDS reading samples returns %d \n", status);
|
||||
for(i = 0; i < status; i++) {
|
||||
DDS_CMDataReaderBuiltinTopicData *data = cm_datareader_samples[i];
|
||||
fprintf(fp,"CMDATAREADER:\n");
|
||||
fprintf(fp," key = %u:%u:%u \n", (unsigned) data->key[0], (unsigned) data->key[1], (unsigned) data->key[2]);
|
||||
fprintf(fp," subscriber_key = %u:%u:%u\n", (unsigned) data->subscriber_key[0], (unsigned) data->subscriber_key[1], (unsigned) data->subscriber_key[2]);
|
||||
fprintf(fp," name = %s\n", data->name);
|
||||
qp_history (&data->history,fp);
|
||||
qp_resource_limits (&data->resource_limits,fp);
|
||||
qp_reader_data_lifecycle (&data->reader_data_lifecycle,fp);
|
||||
qp_subscription_keys (&data->subscription_keys,fp);
|
||||
qp_reader_lifespan (&data->reader_lifespan,fp);
|
||||
qp_share (&data->share,fp);
|
||||
qp_product_data (&data->product,fp);
|
||||
}
|
||||
if(status > 0) {
|
||||
status = dds_return_loan(cm_datareader_reader, (void**)cm_datareader_samples, status);
|
||||
}
|
||||
if(status <= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void usage(){
|
||||
/*describe the default options*/
|
||||
int tpindex;
|
||||
printf("\n OPTIONS:\n");
|
||||
printf("-f <filename> <topics> -- write to file\n");
|
||||
printf("-a -- all topics\n");
|
||||
printf("\nTOPICS\n");
|
||||
for(tpindex = 0; tpindex < TOPICTAB_SIZE; tpindex++){
|
||||
printf("%s\n", topictab[tpindex].name);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
FILE *fp = NULL;
|
||||
int flags = 0;
|
||||
int j;
|
||||
int index;
|
||||
char *fname = NULL;
|
||||
if(argc == 1){
|
||||
usage();
|
||||
}
|
||||
int choice=0;
|
||||
while((choice = os_getopt(argc,argv,"f:a")) != -1)
|
||||
{
|
||||
switch(choice)
|
||||
{
|
||||
case 'f':
|
||||
fname = os_get_optarg();
|
||||
if(fname != NULL){
|
||||
|
||||
PRINTD("opening file %s \n", fname);
|
||||
fp = fopen(fname, "w");
|
||||
if(fp == NULL)
|
||||
{
|
||||
printf("file does not exist\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'a':
|
||||
for(index=0; index<TOPICTAB_SIZE; index++){
|
||||
flags |= topictab[index].flag;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("%s Invalid option\n", argv[1]);
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(fp == NULL){
|
||||
fp = stdout;
|
||||
}
|
||||
|
||||
for(j = os_get_optind(); j < argc; j++) {
|
||||
if(argv[j][0] == '-') {
|
||||
// it's an option, don't process it...
|
||||
continue;
|
||||
}
|
||||
int k;
|
||||
bool matched = false;
|
||||
for(k = 0; k < TOPICTAB_SIZE; k++) {
|
||||
if(os_strcasecmp(argv[j], topictab[k].name) == 0) {
|
||||
// match
|
||||
flags |= topictab[k].flag;
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!matched) {
|
||||
printf("%s: topic unknown\n", argv[j]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Create the participant with the default domain */
|
||||
participant = dds_create_participant(did, NULL, NULL);
|
||||
PRINTD("DDS Participant Create: %s\n", dds_err_str(status));
|
||||
|
||||
if(flags & DCPSTOPIC_FLAG) {
|
||||
print_dcps_topic(fp);
|
||||
}
|
||||
|
||||
if(flags & DCPSPARTICIPANT_FLAG) {
|
||||
print_dcps_participant(fp);
|
||||
}
|
||||
|
||||
if(flags & DCPSSUBSCRIPTION_FLAG){
|
||||
print_dcps_subscription(fp);
|
||||
}
|
||||
|
||||
if(flags & DCPSPUBLICATION_FLAG){
|
||||
print_dcps_publication(fp);
|
||||
}
|
||||
|
||||
if(flags & CMPARTICIPANT_FLAG){
|
||||
print_cm_participant(fp);
|
||||
}
|
||||
|
||||
if(flags & CMPUBLISHER_FLAG){
|
||||
print_cm_publisher(fp);
|
||||
}
|
||||
|
||||
if(flags & CMSUBSCRIBER_FLAG){
|
||||
print_cm_subscriber(fp);
|
||||
}
|
||||
|
||||
if(flags & CMDATAWRITER_FLAG){
|
||||
print_cm_datawriter(fp);
|
||||
}
|
||||
|
||||
if(flags & CMDATAREADER_FLAG){
|
||||
print_cm_datareader(fp);
|
||||
}
|
||||
|
||||
dds_delete(participant);
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
26
src/tools/pubsub/CMakeLists.txt
Normal file
26
src/tools/pubsub/CMakeLists.txt
Normal file
|
@ -0,0 +1,26 @@
|
|||
#
|
||||
# Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
#
|
||||
# This program and the accompanying materials are made available under the
|
||||
# terms of the Eclipse Public License v. 2.0 which is available at
|
||||
# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
# v. 1.0 which is available at
|
||||
# http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
#
|
||||
find_package(Abstraction REQUIRED)
|
||||
|
||||
add_executable(pubsub pubsub.c common.c testtype.c porting.c)
|
||||
target_link_libraries(pubsub ddsc OSAPI)
|
||||
|
||||
# TODO: improve test inclusion.
|
||||
if((BUILD_TESTING) AND ((NOT DEFINED MSVC_VERSION) OR (MSVC_VERSION GREATER "1800")))
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
install(
|
||||
TARGETS pubsub
|
||||
DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
COMPONENT dev
|
||||
)
|
941
src/tools/pubsub/common.c
Executable file
941
src/tools/pubsub/common.c
Executable file
|
@ -0,0 +1,941 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "testtype.h"
|
||||
#include "common.h"
|
||||
#include "os/os.h"
|
||||
|
||||
dds_entity_t dp = 0;
|
||||
dds_entity_t qosprov = 0;
|
||||
const dds_topic_descriptor_t *ts_KeyedSeq;
|
||||
const dds_topic_descriptor_t *ts_Keyed32;
|
||||
const dds_topic_descriptor_t *ts_Keyed64;
|
||||
const dds_topic_descriptor_t *ts_Keyed128;
|
||||
const dds_topic_descriptor_t *ts_Keyed256;
|
||||
const dds_topic_descriptor_t *ts_OneULong;
|
||||
|
||||
const char *saved_argv0;
|
||||
|
||||
//void nowll_as_ddstime(DDS_Time_t *t) {
|
||||
// os_time ost = os_timeGet();
|
||||
// t->sec = ost.tv_sec;
|
||||
// t->nanosec = (DDS_unsigned_long) ost.tv_nsec;
|
||||
//}
|
||||
//
|
||||
//void bindelta(unsigned long long *bins, unsigned long long d, unsigned repeat) {
|
||||
// int bin = 0;
|
||||
// while (d) {
|
||||
// bin++;
|
||||
// d >>= 1;
|
||||
// }
|
||||
// bins[bin] += repeat;
|
||||
//}
|
||||
//
|
||||
//void binprint(unsigned long long *bins, unsigned long long telapsed) {
|
||||
// unsigned long long n;
|
||||
// unsigned i, minbin = BINS_LENGTH-1, maxbin = 0;
|
||||
// n = 0;
|
||||
// for (i = 0; i < BINS_LENGTH; i++) {
|
||||
// n += bins[i];
|
||||
// if (bins[i] && i < minbin)
|
||||
// minbin = i;
|
||||
// if (bins[i] && i > maxbin)
|
||||
// maxbin = i;
|
||||
// }
|
||||
// printf ("< 2**n | %llu in %.06fs avg %.1f/s\n", n, telapsed * 1e-9, n / (telapsed * 1e-9));
|
||||
// for (i = minbin; i <= maxbin; i++) {
|
||||
// static const char ats[] = "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
|
||||
// double pct = 100.0 * (double) bins[i] / n;
|
||||
// int nats = (int) ((pct / 100.0) * (sizeof(ats) - 1));
|
||||
// printf ("%2d: %6.2f%% %*.*s\n", i, pct, nats, nats, ats);
|
||||
// }
|
||||
//}
|
||||
|
||||
struct hist {
|
||||
unsigned nbins;
|
||||
uint64_t binwidth;
|
||||
uint64_t bin0; /* bins are [bin0,bin0+binwidth),[bin0+binwidth,bin0+2*binwidth) */
|
||||
uint64_t binN; /* bin0 + nbins*binwidth */
|
||||
uint64_t min, max; /* min and max observed since last reset */
|
||||
uint64_t under, over; /* < bin0, >= binN */
|
||||
uint64_t bins[];
|
||||
};
|
||||
|
||||
struct hist *hist_new(unsigned nbins, uint64_t binwidth, uint64_t bin0) {
|
||||
struct hist *h = dds_alloc(sizeof(*h) + nbins * sizeof(*h->bins));
|
||||
h->nbins = nbins;
|
||||
h->binwidth = binwidth;
|
||||
h->bin0 = bin0;
|
||||
h->binN = h->bin0 + h->nbins * h->binwidth;
|
||||
hist_reset(h);
|
||||
return h;
|
||||
}
|
||||
|
||||
void hist_free(struct hist *h) {
|
||||
dds_free(h);
|
||||
}
|
||||
|
||||
void hist_reset_minmax(struct hist *h) {
|
||||
h->min = UINT64_MAX;
|
||||
h->max = 0;
|
||||
}
|
||||
|
||||
void hist_reset(struct hist *h) {
|
||||
hist_reset_minmax(h);
|
||||
h->under = 0;
|
||||
h->over = 0;
|
||||
memset(h->bins, 0, h->nbins * sizeof(*h->bins));
|
||||
}
|
||||
|
||||
void hist_record(struct hist *h, uint64_t x, unsigned weight) {
|
||||
if (x < h->min)
|
||||
h->min = x;
|
||||
if (x > h->max)
|
||||
h->max = x;
|
||||
if (x < h->bin0)
|
||||
h->under += weight;
|
||||
else if (x >= h->binN)
|
||||
h->over += weight;
|
||||
else
|
||||
h->bins[(x - h->bin0) / h->binwidth] += weight;
|
||||
}
|
||||
|
||||
static void xsnprintf(char *buf, size_t bufsz, size_t *p, const char *fmt, ...) {
|
||||
if (*p < bufsz) {
|
||||
int n;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
n = os_vsnprintf(buf + *p, bufsz - *p, fmt, ap);
|
||||
va_end(ap);
|
||||
*p += (size_t)n;
|
||||
}
|
||||
}
|
||||
|
||||
void hist_print(struct hist *h, dds_time_t dt, int reset) {
|
||||
const size_t l_size = sizeof(char) * h->nbins + 200;
|
||||
const size_t hist_size = sizeof(char) * h->nbins + 1;
|
||||
char *l = (char *) dds_alloc(l_size);
|
||||
char *hist = (char *) dds_alloc(hist_size);
|
||||
double dt_s = dt / 1e9, avg;
|
||||
uint64_t peak = 0, cnt = h->under + h->over;
|
||||
size_t p = 0;
|
||||
hist[h->nbins] = 0;
|
||||
for (unsigned i = 0; i < h->nbins; i++) {
|
||||
cnt += h->bins[i];
|
||||
if (h->bins[i] > peak)
|
||||
peak = h->bins[i];
|
||||
}
|
||||
|
||||
const uint64_t p1 = peak / 100;
|
||||
const uint64_t p10 = peak / 10;
|
||||
const uint64_t p20 = 1 * peak / 5;
|
||||
const uint64_t p40 = 2 * peak / 5;
|
||||
const uint64_t p60 = 3 * peak / 5;
|
||||
const uint64_t p80 = 4 * peak / 5;
|
||||
for (unsigned i = 0; i < h->nbins; i++) {
|
||||
if (h->bins[i] == 0) hist[i] = ' ';
|
||||
else if (h->bins[i] <= p1) hist[i] = '.';
|
||||
else if (h->bins[i] <= p10) hist[i] = '_';
|
||||
else if (h->bins[i] <= p20) hist[i] = '-';
|
||||
else if (h->bins[i] <= p40) hist[i] = '=';
|
||||
else if (h->bins[i] <= p60) hist[i] = 'x';
|
||||
else if (h->bins[i] <= p80) hist[i] = 'X';
|
||||
else hist[i] = '@';
|
||||
}
|
||||
|
||||
avg = cnt / dt_s;
|
||||
if (avg < 999.5)
|
||||
xsnprintf(l, l_size, &p, "%5.3g", avg);
|
||||
else if (avg < 1e6)
|
||||
xsnprintf(l, l_size, &p, "%4.3gk", avg / 1e3);
|
||||
else
|
||||
xsnprintf(l, l_size, &p, "%4.3gM", avg / 1e6);
|
||||
xsnprintf(l, l_size, &p, "/s (");
|
||||
|
||||
if (cnt < (uint64_t) 10e3)
|
||||
xsnprintf(l, l_size, &p, "%5"PRIu64" ", cnt);
|
||||
else if (cnt < (uint64_t) 1e6)
|
||||
xsnprintf(l, l_size, &p, "%5.1fk", cnt / 1e3);
|
||||
else
|
||||
xsnprintf(l, l_size, &p, "%5.1fM", cnt / 1e6);
|
||||
|
||||
xsnprintf(l, l_size, &p, " in %.1fs) ", dt_s);
|
||||
|
||||
if (h->min == UINT64_MAX)
|
||||
xsnprintf(l, l_size, &p, " inf ");
|
||||
else if (h->min < 1000)
|
||||
xsnprintf(l, l_size, &p, "%3"PRIu64"n ", h->min);
|
||||
else if (h->min + 500 < 1000000)
|
||||
xsnprintf(l, l_size, &p, "%3"PRIu64"u ", (h->min + 500) / 1000);
|
||||
else if (h->min + 500000 < 1000000000)
|
||||
xsnprintf(l, l_size, &p, "%3"PRIu64"m ", (h->min + 500000) / 1000000);
|
||||
else
|
||||
xsnprintf(l, l_size, &p, "%3"PRIu64"s ", (h->min + 500000000) / 1000000000);
|
||||
|
||||
if (h->bin0 > 0) {
|
||||
int pct = (cnt == 0) ? 0 : 100 * (int) ((h->under + cnt/2) / cnt);
|
||||
xsnprintf(l, l_size, &p, "%3d%% ", pct);
|
||||
}
|
||||
|
||||
{
|
||||
int pct = (cnt == 0) ? 0 : 100 * (int) ((h->over + cnt/2) / cnt);
|
||||
xsnprintf(l, l_size, &p, "|%s| %3d%%", hist, pct);
|
||||
}
|
||||
|
||||
if (h->max < 1000)
|
||||
xsnprintf(l, l_size, &p, " %3"PRIu64"n", h->max);
|
||||
else if (h->max + 500 < 1000000)
|
||||
xsnprintf(l, l_size, &p, " %3"PRIu64"u", (h->max + 500) / 1000);
|
||||
else if (h->max + 500000 < 1000000000)
|
||||
xsnprintf(l, l_size, &p, " %3"PRIu64"m", (h->max + 500000) / 1000000);
|
||||
else
|
||||
xsnprintf(l, l_size, &p, " %3"PRIu64"s", (h->max + 500000000) / 1000000000);
|
||||
|
||||
(void) p;
|
||||
puts(l);
|
||||
dds_free(l);
|
||||
dds_free(hist);
|
||||
if (reset)
|
||||
hist_reset(h);
|
||||
}
|
||||
|
||||
void error(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
fprintf (stderr, "%s: error: ", saved_argv0);
|
||||
va_start(ap, fmt);
|
||||
vfprintf (stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
|
||||
void save_argv0(const char *argv0) {
|
||||
saved_argv0 = argv0;
|
||||
}
|
||||
|
||||
int common_init(const char *argv0) {
|
||||
save_argv0(argv0);
|
||||
dp = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
|
||||
error_abort(dp, "dds_create_participant failed");
|
||||
|
||||
ts_KeyedSeq = &KeyedSeq_desc;
|
||||
ts_Keyed32 = &Keyed32_desc;
|
||||
ts_Keyed64 = &Keyed64_desc;
|
||||
ts_Keyed128 = &Keyed128_desc;
|
||||
ts_Keyed256 = &Keyed256_desc;
|
||||
ts_OneULong = &OneULong_desc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void common_fini(void) {
|
||||
dds_return_t rc;
|
||||
if (qosprov != 0) {
|
||||
rc = dds_delete(qosprov);
|
||||
error_report(rc, "dds_delete qosprov failed");
|
||||
}
|
||||
rc = dds_delete(dp);
|
||||
error_report(rc, "dds_delete participant failed");
|
||||
}
|
||||
|
||||
int change_publisher_partitions(dds_entity_t pub, unsigned npartitions, const char *partitions[]) {
|
||||
dds_qos_t *qos;
|
||||
dds_return_t rc;
|
||||
|
||||
qos = dds_qos_create();
|
||||
rc = dds_get_qos(pub, qos);
|
||||
if (rc == DDS_SUCCESS) {
|
||||
dds_qset_partition(qos, npartitions, partitions);
|
||||
rc = dds_set_qos(pub, qos);
|
||||
}
|
||||
dds_qos_delete(qos);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int change_subscriber_partitions(dds_entity_t sub, unsigned npartitions, const char *partitions[]) {
|
||||
dds_qos_t *qos;
|
||||
dds_return_t rc;
|
||||
|
||||
qos = dds_qos_create();
|
||||
rc = dds_get_qos(sub, qos);
|
||||
if (rc == DDS_SUCCESS) {
|
||||
dds_qset_partition(qos, npartitions, partitions);
|
||||
rc = dds_set_qos(sub, qos);
|
||||
}
|
||||
dds_qos_delete(qos);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static dds_qos_t *get_topic_qos(dds_entity_t tp) {
|
||||
dds_qos_t *tQos = dds_qos_create();
|
||||
dds_return_t rc = dds_get_qos(tp, tQos);
|
||||
error_abort(rc, "dds_qos_get_topic_qos");
|
||||
return tQos;
|
||||
}
|
||||
|
||||
dds_qos_t *new_tqos(void) {
|
||||
dds_qos_t *q = dds_qos_create();
|
||||
|
||||
/* Not all defaults are those of DCPS: */
|
||||
dds_qset_reliability(q, DDS_RELIABILITY_RELIABLE, DDS_SECS(1));
|
||||
dds_qset_destination_order(q, DDS_DESTINATIONORDER_BY_SOURCE_TIMESTAMP);
|
||||
return q;
|
||||
}
|
||||
|
||||
dds_qos_t *new_rdqos(dds_entity_t tp) {
|
||||
dds_qos_t *tQos = get_topic_qos(tp);
|
||||
dds_qos_t *qos = dds_qos_create();
|
||||
|
||||
dds_return_t rc = dds_qos_copy(qos, tQos);
|
||||
error_abort(rc ,"new_rdqos: dds_qos_copy");
|
||||
dds_qos_delete(tQos);
|
||||
return qos;
|
||||
}
|
||||
|
||||
dds_qos_t *new_wrqos(dds_entity_t tp) {
|
||||
dds_qos_t *tQos = get_topic_qos(tp);
|
||||
dds_qos_t *qos = dds_qos_create();
|
||||
|
||||
dds_return_t rc = dds_qos_copy(qos, tQos);
|
||||
error_abort(rc ,"new_wrqos: dds_qos_copy");
|
||||
dds_qos_delete(tQos);
|
||||
|
||||
/* Not all defaults are those of DCPS: */
|
||||
dds_qset_writer_data_lifecycle(qos, false);
|
||||
return qos;
|
||||
}
|
||||
|
||||
dds_entity_t new_topic(const char *name, const dds_topic_descriptor_t *topicDesc, const dds_qos_t *q) {
|
||||
dds_entity_t tp = dds_create_topic(dp, topicDesc, name, q, NULL);
|
||||
error_abort(tp, "dds_create_topic failed");
|
||||
return tp;
|
||||
}
|
||||
|
||||
dds_entity_t new_publisher(dds_qos_t *q, unsigned npartitions, const char **partitions) {
|
||||
dds_qos_t *pQos;
|
||||
if (q == NULL) {
|
||||
pQos = dds_qos_create();
|
||||
} else {
|
||||
pQos = q;
|
||||
}
|
||||
dds_qset_partition(pQos, npartitions, partitions);
|
||||
dds_entity_t pub = dds_create_publisher(dp, pQos, NULL);
|
||||
error_abort(pub, "new_publisher: dds_create_publisher");
|
||||
if (q == NULL)
|
||||
dds_qos_delete(pQos);
|
||||
return pub;
|
||||
}
|
||||
|
||||
dds_entity_t new_subscriber(dds_qos_t *q, unsigned npartitions, const char **partitions) {
|
||||
dds_qos_t *sQos;
|
||||
if (q == NULL) {
|
||||
sQos = dds_qos_create();
|
||||
} else {
|
||||
sQos = q;
|
||||
}
|
||||
dds_qset_partition(sQos, npartitions, partitions);
|
||||
dds_entity_t sub = dds_create_subscriber(dp, sQos, NULL);
|
||||
error_abort(sub, "new_subscriber: dds_create_subscriber");
|
||||
if (q == NULL)
|
||||
dds_qos_delete(sQos);
|
||||
return sub;
|
||||
}
|
||||
|
||||
dds_entity_t new_datawriter_listener(const dds_entity_t pub, const dds_entity_t tp, const dds_qos_t *q, const dds_listener_t *l) {
|
||||
dds_entity_t wr = dds_create_writer(pub, tp, q, l);
|
||||
error_abort(wr, "dds_create_writer failed");
|
||||
return wr;
|
||||
}
|
||||
|
||||
dds_entity_t new_datawriter(const dds_entity_t pub, const dds_entity_t tp, const dds_qos_t *q) {
|
||||
return new_datawriter_listener(pub, tp, q, NULL);
|
||||
}
|
||||
|
||||
dds_entity_t new_datareader_listener(const dds_entity_t sub, const dds_entity_t tp, const dds_qos_t *q, const dds_listener_t *l) {
|
||||
dds_entity_t rd = dds_create_reader(sub, tp, q, l);
|
||||
error_abort(rd, "dds_create_reader failed");
|
||||
return rd;
|
||||
}
|
||||
|
||||
dds_entity_t new_datareader(const dds_entity_t sub, const dds_entity_t tp, const dds_qos_t *q) {
|
||||
return new_datareader_listener(sub, tp, q, NULL);
|
||||
}
|
||||
|
||||
static void inapplicable_qos(dds_entity_kind_t qt, const char *n) {
|
||||
const char *en = "?";
|
||||
switch (qt) {
|
||||
case DDS_KIND_TOPIC: en = "topic"; break;
|
||||
case DDS_KIND_PUBLISHER: en = "publisher"; break;
|
||||
case DDS_KIND_SUBSCRIBER: en = "subscriber"; break;
|
||||
case DDS_KIND_WRITER: en = "writer"; break;
|
||||
case DDS_KIND_READER: en = "reader"; break;
|
||||
case DDS_KIND_DONTCARE: en = "dontcare"; break;
|
||||
case DDS_KIND_PARTICIPANT: en = "participant"; break;
|
||||
case DDS_KIND_COND_READ: en = "cond read"; break;
|
||||
case DDS_KIND_COND_QUERY: en = "cond query"; break;
|
||||
case DDS_KIND_WAITSET: en = "waitset"; break;
|
||||
case DDS_KIND_INTERNAL: en = "internal"; break;
|
||||
default: en = "?"; break;
|
||||
}
|
||||
fprintf(stderr, "warning: %s entity ignoring inapplicable QoS \"%s\"\n", en, n);
|
||||
}
|
||||
|
||||
#define get_qos_T(qt, q, n) ((qt == DDS_KIND_TOPIC) ? q : (inapplicable_qos((qt), n), NULL))
|
||||
#define get_qos_R(qt, q, n) ((qt == DDS_KIND_READER) ? q : (inapplicable_qos((qt), n), NULL))
|
||||
#define get_qos_W(qt, q, n) ((qt == DDS_KIND_WRITER) ? q : (inapplicable_qos((qt), n), NULL))
|
||||
#define get_qos_TW(qt, q, n) ((qt == DDS_KIND_TOPIC) || (qt == DDS_KIND_WRITER) ? q : (inapplicable_qos((qt), n), NULL))
|
||||
#define get_qos_RW(qt, q, n) ((qt == DDS_KIND_READER) || (qt == DDS_KIND_WRITER) ? q : (inapplicable_qos((qt), n), NULL))
|
||||
#define get_qos_PS(qt, q, n) ((qt == DDS_KIND_PUBLISHER) || (qt == DDS_KIND_SUBSCRIBER) ? q : (inapplicable_qos((qt), n), NULL))
|
||||
#define get_qos_TRW(qt, q, n) ((qt == DDS_KIND_TOPIC) || (qt == DDS_KIND_READER) || (qt == DDS_KIND_WRITER) ? q : (inapplicable_qos((qt), n), NULL))
|
||||
|
||||
void qos_durability(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_qos_t *qp = get_qos_TRW(qt, q, "durability");
|
||||
if (qp == NULL)
|
||||
return;
|
||||
if (strcmp(arg, "v") == 0)
|
||||
dds_qset_durability(qp, DDS_DURABILITY_VOLATILE);
|
||||
else if (strcmp(arg, "tl") == 0)
|
||||
dds_qset_durability(qp, DDS_DURABILITY_TRANSIENT_LOCAL);
|
||||
else if (strcmp(arg, "t") == 0)
|
||||
dds_qset_durability(qp, DDS_DURABILITY_TRANSIENT);
|
||||
else if (strcmp(arg, "p") == 0)
|
||||
dds_qset_durability(qp, DDS_DURABILITY_PERSISTENT);
|
||||
else
|
||||
error_exit("durability qos: %s: invalid\n", arg);
|
||||
}
|
||||
|
||||
void qos_history(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_qos_t *qp = get_qos_TRW(qt, q, "history");
|
||||
int hist_depth, pos;
|
||||
if (qp == NULL)
|
||||
return;
|
||||
if (strcmp(arg, "all") == 0) {
|
||||
dds_qset_history(qp, DDS_HISTORY_KEEP_ALL, DDS_LENGTH_UNLIMITED);
|
||||
} else if (sscanf(arg, "%d%n", &hist_depth, &pos) == 1 && arg[pos] == 0 && hist_depth > 0) {
|
||||
dds_qset_history(qp, DDS_HISTORY_KEEP_LAST, hist_depth);
|
||||
} else {
|
||||
error_exit("history qos: %s: invalid\n", arg);
|
||||
}
|
||||
}
|
||||
|
||||
void qos_destination_order(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_qos_t *qp = get_qos_TRW(qt, q, "destination_order");
|
||||
if (qp == NULL)
|
||||
return;
|
||||
if (strcmp(arg, "r") == 0) {
|
||||
dds_qset_destination_order(qp, DDS_DESTINATIONORDER_BY_RECEPTION_TIMESTAMP);
|
||||
} else if (strcmp(arg, "s") == 0) {
|
||||
dds_qset_destination_order(qp, DDS_DESTINATIONORDER_BY_SOURCE_TIMESTAMP);
|
||||
} else {
|
||||
error_exit("destination order qos: %s: invalid\n", arg);
|
||||
}
|
||||
}
|
||||
|
||||
void qos_ownership(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_qos_t *qp = get_qos_TRW(qt, q, "ownership");
|
||||
int strength, pos;
|
||||
if (qp == NULL)
|
||||
return;
|
||||
if (strcmp(arg, "s") == 0) {
|
||||
dds_qset_ownership(qp, DDS_OWNERSHIP_SHARED);
|
||||
} else if (strcmp(arg, "x") == 0) {
|
||||
dds_qset_ownership(qp, DDS_OWNERSHIP_EXCLUSIVE);
|
||||
} else if (sscanf(arg, "x:%d%n", &strength, &pos) == 1 && arg[pos] == 0) {
|
||||
dds_qos_t *qps = get_qos_W(qt, q, "ownership_strength");
|
||||
dds_qset_ownership(qp, DDS_OWNERSHIP_EXCLUSIVE);
|
||||
if(qps) {
|
||||
dds_qset_ownership_strength(qps, strength);
|
||||
}
|
||||
} else {
|
||||
error_exit("ownership qos: %s invalid\n", arg);
|
||||
}
|
||||
}
|
||||
|
||||
void qos_transport_priority(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_qos_t *qp = get_qos_W(qt, q, "transport_priority");
|
||||
int pos;
|
||||
int value;
|
||||
if (qp == NULL)
|
||||
return;
|
||||
if (sscanf(arg, "%d%n", &value, &pos) != 1 || arg[pos] != 0)
|
||||
error_exit("transport_priority qos: %s invalid\n", arg);
|
||||
dds_qset_transport_priority(qp, value);
|
||||
}
|
||||
|
||||
static unsigned char gethexchar(const char **str) {
|
||||
unsigned char v = 0;
|
||||
int empty = 1;
|
||||
while (**str) {
|
||||
switch (**str) {
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
v = 16 * v + (unsigned char) **str - '0';
|
||||
(*str)++;
|
||||
break;
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
v = 16 * v + (unsigned char) **str - 'a' + 10;
|
||||
(*str)++;
|
||||
break;
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
v = 16 * v + (unsigned char) **str - 'A' + 10;
|
||||
(*str)++;
|
||||
break;
|
||||
default:
|
||||
if (empty)
|
||||
error_exit("empty \\x escape");
|
||||
goto done;
|
||||
}
|
||||
empty = 0;
|
||||
}
|
||||
done:
|
||||
return v;
|
||||
}
|
||||
|
||||
static unsigned char getoctchar(const char **str) {
|
||||
unsigned char v = 0;
|
||||
int nseen = 0;
|
||||
while (**str && nseen < 3) {
|
||||
if (**str >= '0' && **str <= '7') {
|
||||
v = 8 * v + (unsigned char) **str - '0';
|
||||
(*str)++;
|
||||
nseen++;
|
||||
} else {
|
||||
if (nseen == 0)
|
||||
error_exit("empty \\ooo escape");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
static void *unescape(const char *str, size_t *len) {
|
||||
/* results in a blob without explicit terminator, i.e., can't get
|
||||
* any longer than strlen(str) */
|
||||
unsigned char *x = dds_alloc(strlen(str)), *p = x;
|
||||
while (*str) {
|
||||
if (*str != '\\')
|
||||
*p++ = (unsigned char) *str++;
|
||||
else {
|
||||
str++;
|
||||
switch (*str) {
|
||||
case '\\': case ',': case '\'': case '"': case '?':
|
||||
*p++ = (unsigned char) *str;
|
||||
str++;
|
||||
break;
|
||||
case 'x':
|
||||
str++;
|
||||
*p++ = gethexchar(&str);
|
||||
break;
|
||||
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7':
|
||||
*p++ = getoctchar(&str);
|
||||
break;
|
||||
case 'a': *p++ = '\a'; str++; break;
|
||||
case 'b': *p++ = '\b'; str++; break;
|
||||
case 'f': *p++ = '\f'; str++; break;
|
||||
case 'n': *p++ = '\n'; str++; break;
|
||||
case 'r': *p++ = '\r'; str++; break;
|
||||
case 't': *p++ = '\t'; str++; break;
|
||||
case 'v': *p++ = '\v'; str++; break;
|
||||
case 'e': *p++ = 0x1b; str++; break;
|
||||
default:
|
||||
error_exit("invalid escape string: %s\n", str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*len = (size_t) (p - x);
|
||||
return x;
|
||||
}
|
||||
|
||||
void qos_user_data(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_qos_t *qp = get_qos_RW(qt, q, "user_data");
|
||||
size_t len;
|
||||
if (qp == NULL)
|
||||
return;
|
||||
|
||||
void *unesc = unescape(arg, &len);
|
||||
if(len==0) {
|
||||
dds_qset_userdata(qp, NULL, 0);
|
||||
} else {
|
||||
dds_qset_userdata(qp, unesc, len);
|
||||
}
|
||||
|
||||
dds_free(unesc);
|
||||
}
|
||||
|
||||
int double_to_dds_duration(dds_duration_t *dd, double d) {
|
||||
if (d < 0)
|
||||
return -1;
|
||||
double nanosec = d * 1e9;
|
||||
if(nanosec > INT64_MAX) {
|
||||
*dd = DDS_INFINITY;
|
||||
} else {
|
||||
*dd = (int64_t) nanosec;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void set_infinite_dds_duration(dds_duration_t *dd) {
|
||||
*dd = DDS_INFINITY;
|
||||
}
|
||||
|
||||
void qos_reliability(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_qos_t *qp = get_qos_TRW(qt, q, "reliability");
|
||||
const char *argp = arg;
|
||||
dds_duration_t max_block_t = DDS_MSECS(100);
|
||||
|
||||
if (qp == NULL)
|
||||
return;
|
||||
|
||||
switch (*argp++) {
|
||||
case 'b':
|
||||
case 'n':
|
||||
dds_qset_reliability(qp, DDS_RELIABILITY_BEST_EFFORT, max_block_t);
|
||||
break;
|
||||
case 'r':
|
||||
case 'y':
|
||||
if (*argp == ':') {
|
||||
double max_blocking_time;
|
||||
int pos;
|
||||
if (strcmp(argp, ":inf") == 0) {
|
||||
set_infinite_dds_duration(&max_block_t);
|
||||
argp += 4;
|
||||
} else if (sscanf(argp, ":%lf%n", &max_blocking_time, &pos) == 1 && argp[pos] == 0) {
|
||||
if (max_blocking_time <= 0 || double_to_dds_duration(&max_block_t, max_blocking_time) < 0)
|
||||
error_exit("reliability qos: %s: max blocking time out of range\n", arg);
|
||||
argp += pos;
|
||||
} else {
|
||||
error_exit("reliability qos: %s: invalid max_blocking_time\n", arg);
|
||||
}
|
||||
}
|
||||
dds_qset_reliability(qp, DDS_RELIABILITY_RELIABLE, max_block_t);
|
||||
break;
|
||||
default:
|
||||
error_exit("reliability qos: %s: invalid\n", arg);
|
||||
}
|
||||
|
||||
if (*argp != 0) {
|
||||
error_exit("reliability qos: %s: invalid\n", arg);
|
||||
}
|
||||
}
|
||||
|
||||
void qos_liveliness(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_duration_t dd = 0;
|
||||
dds_qos_t *qp = get_qos_TRW(qt, q, "liveliness");
|
||||
double lease_duration;
|
||||
int pos;
|
||||
|
||||
if (qp == NULL)
|
||||
return;
|
||||
|
||||
if (strcmp(arg, "a") == 0) {
|
||||
dds_qset_liveliness(qp, DDS_LIVELINESS_AUTOMATIC, DDS_INFINITY);
|
||||
} else if (sscanf(arg, "p:%lf%n", &lease_duration, &pos) == 1 && arg[pos] == 0) {
|
||||
if (lease_duration <= 0 || double_to_dds_duration(&dd, lease_duration) < 0)
|
||||
error_exit("liveliness qos: %s: lease duration out of range\n", arg);
|
||||
dds_qset_liveliness(qp, DDS_LIVELINESS_MANUAL_BY_PARTICIPANT, dd);
|
||||
} else if (sscanf(arg, "w:%lf%n", &lease_duration, &pos) == 1 && arg[pos] == 0) {
|
||||
if (lease_duration <= 0 || double_to_dds_duration(&dd, lease_duration) < 0)
|
||||
error_exit("liveliness qos: %s: lease duration out of range\n", arg);
|
||||
dds_qset_liveliness(qp, DDS_LIVELINESS_MANUAL_BY_TOPIC, dd);
|
||||
} else {
|
||||
error_exit("liveliness qos: %s: invalid\n", arg);
|
||||
}
|
||||
}
|
||||
|
||||
static void qos_simple_duration(dds_duration_t *dd, const char *name, const char *arg) {
|
||||
double duration;
|
||||
int pos;
|
||||
if (strcmp(arg, "inf") == 0) {
|
||||
set_infinite_dds_duration(dd);
|
||||
} else if (sscanf(arg, "%lf%n", &duration, &pos) == 1 && arg[pos] == 0) {
|
||||
if (double_to_dds_duration(dd, duration) < 0)
|
||||
error_exit("%s qos: %s: duration invalid\n", name, arg);
|
||||
} else {
|
||||
error_exit("%s qos: %s: invalid\n", name, arg);
|
||||
}
|
||||
}
|
||||
|
||||
void qos_latency_budget(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_qos_t *qp = get_qos_TRW(qt, q, "latency_budget");
|
||||
dds_duration_t duration = 0;
|
||||
if (qp == NULL)
|
||||
return;
|
||||
qos_simple_duration(&duration, "latency_budget", arg);
|
||||
dds_qset_latency_budget(qp, duration);
|
||||
}
|
||||
|
||||
void qos_deadline(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_qos_t *qp = get_qos_TRW(qt, q, "deadline");
|
||||
dds_duration_t deadline = 0;
|
||||
if (qp == NULL)
|
||||
return;
|
||||
qos_simple_duration(&deadline, "deadline", arg);
|
||||
dds_qset_deadline(qp, deadline);
|
||||
}
|
||||
|
||||
void qos_lifespan(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_qos_t *qp = get_qos_TW(qt, q, "lifespan");
|
||||
dds_duration_t duration = 0;
|
||||
if (qp == NULL)
|
||||
return;
|
||||
qos_simple_duration(&duration, "lifespan", arg);
|
||||
dds_qset_lifespan(qp, duration);
|
||||
}
|
||||
|
||||
static int one_resource_limit(int32_t *val, const char **arg) {
|
||||
int pos;
|
||||
if (strncmp(*arg, "inf", 3) == 0) {
|
||||
*val = DDS_LENGTH_UNLIMITED;
|
||||
(*arg) += 3;
|
||||
return 1;
|
||||
} else if (sscanf(*arg, "%d%n", val, &pos) == 1) {
|
||||
(*arg) += pos;
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void qos_resource_limits(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_qos_t *qp = get_qos_TRW(qt, q, "resource_limits");
|
||||
const char *argp = arg;
|
||||
int32_t max_samples = 0;
|
||||
int32_t max_instances = 0;
|
||||
int32_t max_samples_per_instance = 0;
|
||||
if (qp == NULL)
|
||||
return;
|
||||
|
||||
if (!one_resource_limit(&max_samples, &argp))
|
||||
goto err;
|
||||
if (*argp++ != '/')
|
||||
goto err;
|
||||
if (!one_resource_limit(&max_instances, &argp))
|
||||
goto err;
|
||||
if (*argp++ != '/')
|
||||
goto err;
|
||||
if (!one_resource_limit(&max_samples_per_instance, &argp))
|
||||
goto err;
|
||||
|
||||
dds_qset_resource_limits(qp, max_samples, max_instances, max_samples_per_instance);
|
||||
|
||||
if (*argp != 0)
|
||||
goto err;
|
||||
return;
|
||||
|
||||
err:
|
||||
error_exit("resource limits qos: %s: invalid\n", arg);
|
||||
}
|
||||
|
||||
void qos_durability_service(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_qos_t *qp = get_qos_T(qt, q, "durability_service");
|
||||
const char *argp = arg;
|
||||
double service_cleanup_delay_t;
|
||||
int pos, hist_depth;
|
||||
dds_duration_t service_cleanup_delay = 0;
|
||||
dds_history_kind_t history_kind = DDS_HISTORY_KEEP_LAST;
|
||||
int32_t history_depth = 1;
|
||||
int32_t max_samples = DDS_LENGTH_UNLIMITED;
|
||||
int32_t max_instances = DDS_LENGTH_UNLIMITED;
|
||||
int32_t max_samples_per_instance = DDS_LENGTH_UNLIMITED;
|
||||
|
||||
if (qp == NULL)
|
||||
return;
|
||||
|
||||
argp = arg;
|
||||
if (strncmp(argp, "inf", 3) == 0) {
|
||||
set_infinite_dds_duration(&service_cleanup_delay);
|
||||
pos = 3;
|
||||
} else if (sscanf(argp, "%lf%n", &service_cleanup_delay_t, &pos) == 1) {
|
||||
if (service_cleanup_delay_t < 0 || double_to_dds_duration(&service_cleanup_delay, service_cleanup_delay_t) < 0)
|
||||
error_exit("durability service qos: %s: service cleanup delay out of range\n", arg);
|
||||
} else {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (argp[pos] == 0) {
|
||||
dds_qset_durability_service(qp, service_cleanup_delay, history_kind, history_depth, max_samples, max_instances, max_samples_per_instance);
|
||||
return;
|
||||
} else if (argp[pos] != '/') goto err;
|
||||
argp += pos + 1;
|
||||
|
||||
if (strncmp(argp, "all", 3) == 0) {
|
||||
history_kind = DDS_HISTORY_KEEP_ALL;
|
||||
pos = 3;
|
||||
} else if (sscanf(argp, "%d%n", &hist_depth, &pos) == 1 && hist_depth > 0) {
|
||||
history_depth = hist_depth;
|
||||
} else {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (argp[pos] == 0) {
|
||||
dds_qset_durability_service(qp, service_cleanup_delay, history_kind, history_depth, max_samples, max_instances, max_samples_per_instance);
|
||||
return;
|
||||
} else if (argp[pos] != '/') goto err;
|
||||
argp += pos + 1;
|
||||
|
||||
if (!one_resource_limit(&max_samples, &argp))
|
||||
goto err;
|
||||
if (*argp++ != '/')
|
||||
goto err;
|
||||
if (!one_resource_limit(&max_instances, &argp))
|
||||
goto err;
|
||||
if (*argp++ != '/')
|
||||
goto err;
|
||||
if (!one_resource_limit(&max_samples_per_instance, &argp))
|
||||
goto err;
|
||||
|
||||
dds_qset_durability_service(qp, service_cleanup_delay, history_kind, history_depth, max_samples, max_instances, max_samples_per_instance);
|
||||
|
||||
if (*argp != 0)
|
||||
goto err;
|
||||
return;
|
||||
|
||||
err:
|
||||
error_exit("durability service qos: %s: invalid\n", arg);
|
||||
}
|
||||
|
||||
void qos_presentation(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_qos_t *qp = get_qos_PS(qt, q, "presentation");
|
||||
if (qp == NULL)
|
||||
return;
|
||||
if (strcmp(arg, "i") == 0) {
|
||||
dds_qset_presentation(qp, DDS_PRESENTATION_INSTANCE, 0, 0);
|
||||
} else if (strcmp(arg, "t") == 0) {
|
||||
dds_qset_presentation(qp, DDS_PRESENTATION_TOPIC, 1, 0);
|
||||
} else if (strcmp(arg, "g") == 0) {
|
||||
dds_qset_presentation(qp, DDS_PRESENTATION_GROUP, 1, 0);
|
||||
} else {
|
||||
error_exit("presentation qos: %s: invalid\n", arg);
|
||||
}
|
||||
}
|
||||
|
||||
void qos_autodispose_unregistered_instances(dds_entity_kind_t qt, dds_qos_t *q, const char *arg) {
|
||||
dds_qos_t *qp = get_qos_W(qt, q, "writer_data_lifecycle");
|
||||
if (qp == NULL)
|
||||
return;
|
||||
if (strcmp(arg, "n") == 0)
|
||||
dds_qset_writer_data_lifecycle(qp, false);
|
||||
else if (strcmp(arg, "y") == 0)
|
||||
dds_qset_writer_data_lifecycle(qp, true);
|
||||
else
|
||||
error_exit("autodispose_unregistered_instances qos: %s: invalid\n", arg);
|
||||
}
|
||||
|
||||
const char *qos_arg_usagestr = "\
|
||||
QOS (not all are universally applicable):\n\
|
||||
A={a|p:S|w:S} liveliness (automatic, participant or writer, S in seconds)\n\
|
||||
d={v|tl|t|p} durability (default: v)\n\
|
||||
D=P deadline P in seconds (default: inf)\n\
|
||||
k={all|N} KEEP_ALL or KEEP_LAST N\n\
|
||||
l=D latency budget in seconds (default: 0)\n\
|
||||
L=D lifespan in seconds (default: inf)\n\
|
||||
o=[r|s] order by reception or source timestamp (default: s)\n\
|
||||
O=[s|x[:S]] ownership: shared or exclusive, strength S (default: s)\n\
|
||||
p=PRIO transport priority (default: 0)\n\
|
||||
P={i|t|g} instance, or {topic|group} + coherent updates\n\
|
||||
r={r[:T]|b} reliability, T is max blocking time in seconds,\n\
|
||||
(default: r:1)\n\
|
||||
R=S/I/SpI resource limits (samples, insts, S/I; default: inf/inf/inf)\n\
|
||||
S=C[/H[/S/I/SpI]] durability_service (cleanup delay, history, resource limits)\n\
|
||||
u={y|n} autodispose unregistered instances (default: n)\n\
|
||||
U=TEXT set user_data to TEXT\n\
|
||||
";
|
||||
|
||||
void set_qosprovider(const char *arg) {
|
||||
//Todo: There is no qosprovider_create in dds.h, yet
|
||||
// int result = DDS_RETCODE_OK;
|
||||
// const char *p = strchr(arg, ',');
|
||||
// const char *xs = strstr(arg, "://");
|
||||
// char *profile = NULL;
|
||||
// const char *uri;
|
||||
// if (p == NULL || xs == NULL || p >= xs)
|
||||
// uri = arg;
|
||||
// else {
|
||||
// uri = p+1;
|
||||
// profile = dds_string_dup(arg);
|
||||
// profile[p-arg] = 0;
|
||||
// }
|
||||
//
|
||||
// if((result = dds_qosprovider_create(&qosprov, uri, profile)) != DDS_RETCODE_OK)
|
||||
// error("dds_qosprovider_create(%s,%s) failed\n", uri, profile ? profile : "(null)");
|
||||
// dds_free(profile);
|
||||
}
|
||||
|
||||
void setqos_from_args(dds_entity_kind_t qt, dds_qos_t *q, int n, const char *args[]) {
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
char *args_copy = dds_string_dup(args[i]), *cursor = args_copy;
|
||||
const char *arg;
|
||||
while ((arg = os_strsep(&cursor, ",")) != NULL) {
|
||||
if (arg[0] && arg[1] == '=') {
|
||||
const char *a = arg + 2;
|
||||
switch (arg[0]) {
|
||||
case 'A': qos_liveliness(qt, q, a); break;
|
||||
case 'd': qos_durability(qt, q, a); break;
|
||||
case 'D': qos_deadline(qt, q, a); break;
|
||||
case 'k': qos_history(qt, q, a); break;
|
||||
case 'l': qos_latency_budget(qt, q, a); break;
|
||||
case 'L': qos_lifespan(qt, q, a); break;
|
||||
case 'o': qos_destination_order(qt, q, a); break;
|
||||
case 'O': qos_ownership(qt, q, a); break;
|
||||
case 'p': qos_transport_priority(qt, q, a); break;
|
||||
case 'P': qos_presentation(qt, q, a); break;
|
||||
case 'r': qos_reliability(qt, q, a); break;
|
||||
case 'R': qos_resource_limits(qt, q, a); break;
|
||||
case 'S': qos_durability_service(qt, q, a); break;
|
||||
case 'u': qos_autodispose_unregistered_instances(qt, q, a); break;
|
||||
case 'U': qos_user_data(qt, q, a); break;
|
||||
default:
|
||||
error_exit("%s: unknown QoS\n", arg);
|
||||
}
|
||||
} else if (!qosprov) {
|
||||
error_exit("QoS specification %s requires a QoS provider but none set\n", arg);
|
||||
} else {
|
||||
printf ("Qos provider not supported\n"); //Todo: Commentted qos provider. Could not find in dds.h. Fix required.
|
||||
// int result;
|
||||
// if (*arg == 0)
|
||||
// arg = NULL;
|
||||
// switch (q->qt) {
|
||||
// case QT_TOPIC:
|
||||
// if ((result = dds_qosprovider_get_topic_qos(qosprov, q->u.topic.q, arg)) != DDS_RETCODE_OK)
|
||||
// error ("dds_qosprovider_get_topic_qos(%s): error %d (%s)\n", arg, (int) result, dds_strerror(result));
|
||||
// break;
|
||||
// case QT_PUBLISHER:
|
||||
// if ((result = dds_qosprovider_get_publisher_qos(qosprov, q->u.pub.q, arg)) != DDS_RETCODE_OK)
|
||||
// error ("dds_qosprovider_get_publisher_qos(%s): error %d (%s)\n", arg, (int) result, dds_strerror(result));
|
||||
// break;
|
||||
// case QT_SUBSCRIBER:
|
||||
// if ((result = dds_qosprovider_get_subscriber_qos(qosprov, q->u.sub.q, arg)) != DDS_RETCODE_OK)
|
||||
// error ("dds_qosprovider_subscriber_qos(%s): error %d (%s)\n", arg, (int) result, dds_strerror(result));
|
||||
// break;
|
||||
// case QT_WRITER:
|
||||
// if ((result = dds_qosprovider_get_writer_qos(qosprov, q->u.wr.q, arg)) != DDS_RETCODE_OK)
|
||||
// error ("dds_qosprovider_get_writer_qos(%s): error %d (%s)\n", arg, (int) result, dds_strerror(result));
|
||||
// break;
|
||||
// case QT_READER:
|
||||
// if ((result = dds_qosprovider_get_reader_qos(qosprov, q->u.rd.q, arg)) != DDS_RETCODE_OK)
|
||||
// error ("dds_qosprovider_get_reader_qos(%s): error %d (%s)\n", arg, (int) result, dds_strerror(result));
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
}
|
||||
dds_free((char *)arg);
|
||||
dds_free(args_copy);
|
||||
}
|
||||
}
|
116
src/tools/pubsub/common.h
Executable file
116
src/tools/pubsub/common.h
Executable file
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include "ddsc/dds.h"
|
||||
#include <assert.h>
|
||||
|
||||
#define DDS_USERDATA_QOS_POLICY_NAME "UserData"
|
||||
#define DDS_DURABILITY_QOS_POLICY_NAME "Durability"
|
||||
#define DDS_PRESENTATION_QOS_POLICY_NAME "Presentation"
|
||||
#define DDS_DEADLINE_QOS_POLICY_NAME "Deadline"
|
||||
#define DDS_LATENCYBUDGET_QOS_POLICY_NAME "LatencyBudget"
|
||||
#define DDS_OWNERSHIP_QOS_POLICY_NAME "Ownership"
|
||||
#define DDS_OWNERSHIPSTRENGTH_QOS_POLICY_NAME "OwnershipStrength"
|
||||
#define DDS_LIVELINESS_QOS_POLICY_NAME "Liveliness"
|
||||
#define DDS_TIMEBASEDFILTER_QOS_POLICY_NAME "TimeBasedFilter"
|
||||
#define DDS_PARTITION_QOS_POLICY_NAME "Partition"
|
||||
#define DDS_RELIABILITY_QOS_POLICY_NAME "Reliability"
|
||||
#define DDS_DESTINATIONORDER_QOS_POLICY_NAME "DestinationOrder"
|
||||
#define DDS_HISTORY_QOS_POLICY_NAME "History"
|
||||
#define DDS_RESOURCELIMITS_QOS_POLICY_NAME "ResourceLimits"
|
||||
#define DDS_ENTITYFACTORY_QOS_POLICY_NAME "EntityFactory"
|
||||
#define DDS_WRITERDATALIFECYCLE_QOS_POLICY_NAME "WriterDataLifecycle"
|
||||
#define DDS_READERDATALIFECYCLE_QOS_POLICY_NAME "ReaderDataLifecycle"
|
||||
#define DDS_TOPICDATA_QOS_POLICY_NAME "TopicData"
|
||||
#define DDS_GROUPDATA_QOS_POLICY_NAME "GroupData"
|
||||
#define DDS_TRANSPORTPRIORITY_QOS_POLICY_NAME "TransportPriority"
|
||||
#define DDS_LIFESPAN_QOS_POLICY_NAME "Lifespan"
|
||||
#define DDS_DURABILITYSERVICE_QOS_POLICY_NAME "DurabilityService"
|
||||
#define DDS_SUBSCRIPTIONKEY_QOS_POLICY_NAME "SubscriptionKey"
|
||||
#define DDS_VIEWKEY_QOS_POLICY_NAME "ViewKey"
|
||||
#define DDS_READERLIFESPAN_QOS_POLICY_NAME "ReaderLifespan"
|
||||
#define DDS_SHARE_QOS_POLICY_NAME "Share"
|
||||
#define DDS_SCHEDULING_QOS_POLICY_NAME "Scheduling"
|
||||
|
||||
#define DDS_SUBSCRIPTIONKEY_QOS_POLICY_ID 23
|
||||
#define DDS_VIEWKEY_QOS_POLICY_ID 24
|
||||
#define DDS_READERLIFESPAN_QOS_POLICY_ID 25
|
||||
#define DDS_SHARE_QOS_POLICY_ID 26
|
||||
#define DDS_SCHEDULING_QOS_POLICY_ID 27
|
||||
|
||||
extern dds_entity_t dp;
|
||||
extern const dds_topic_descriptor_t *ts_KeyedSeq;
|
||||
extern const dds_topic_descriptor_t *ts_Keyed32;
|
||||
extern const dds_topic_descriptor_t *ts_Keyed64;
|
||||
extern const dds_topic_descriptor_t *ts_Keyed128;
|
||||
extern const dds_topic_descriptor_t *ts_Keyed256;
|
||||
extern const dds_topic_descriptor_t *ts_OneULong;
|
||||
extern const char *saved_argv0;
|
||||
extern const char *qos_arg_usagestr;
|
||||
|
||||
//#define BINS_LENGTH (8 * sizeof(unsigned long long) + 1)
|
||||
|
||||
//void nowll_as_ddstime(DDS_Time_t *t);
|
||||
//void bindelta(unsigned long long *bins, unsigned long long d, unsigned repeat);
|
||||
//void binprint(unsigned long long *bins, unsigned long long telapsed);
|
||||
|
||||
struct hist;
|
||||
struct hist *hist_new(unsigned nbins, uint64_t binwidth, uint64_t bin0);
|
||||
void hist_free(struct hist *h);
|
||||
void hist_reset_minmax(struct hist *h);
|
||||
void hist_reset(struct hist *h);
|
||||
void hist_record(struct hist *h, uint64_t x, unsigned weight);
|
||||
void hist_print(struct hist *h, dds_time_t dt, int reset);
|
||||
|
||||
void error(const char *fmt, ...);
|
||||
#define error_abort(rc, fmt, ...) if (rc < DDS_SUCCESS) { error(fmt); DDS_ERR_CHECK(rc, DDS_CHECK_FAIL); }
|
||||
#define error_report(rc, fmt, ...) if (rc < DDS_SUCCESS) { error(fmt); DDS_ERR_CHECK(rc, DDS_CHECK_REPORT); }
|
||||
#define error_return(rc, fmt, ...) if (rc < DDS_SUCCESS) { error_report(rc, fmt); return; }
|
||||
#define error_exit(fmt, ...) { error(fmt); exit(2); }
|
||||
#define os_error_exit(osres, fmt, ...) if (osres != os_resultSuccess) { error(fmt); exit(2); }
|
||||
|
||||
void save_argv0(const char *argv0);
|
||||
int common_init(const char *argv0);
|
||||
void common_fini(void);
|
||||
int change_publisher_partitions(dds_entity_t pub, unsigned npartitions, const char *partitions[]);
|
||||
int change_subscriber_partitions(dds_entity_t sub, unsigned npartitions, const char *partitions[]);
|
||||
dds_entity_t new_publisher(dds_qos_t *q, unsigned npartitions, const char **partitions);
|
||||
dds_entity_t new_subscriber(dds_qos_t *q, unsigned npartitions, const char **partitions);
|
||||
dds_qos_t *new_tqos(void);
|
||||
dds_qos_t *new_rdqos(dds_entity_t tp);
|
||||
dds_qos_t *new_wrqos(dds_entity_t tp);
|
||||
void set_infinite_dds_duration(dds_duration_t *dd);
|
||||
int double_to_dds_duration(dds_duration_t *dd, double d);
|
||||
dds_entity_t new_topic(const char *name, const dds_topic_descriptor_t *topicDesc, const dds_qos_t *q);
|
||||
dds_entity_t new_datawriter(const dds_entity_t pub, const dds_entity_t tp, const dds_qos_t *q);
|
||||
dds_entity_t new_datareader(const dds_entity_t sub, const dds_entity_t tp, const dds_qos_t *q);
|
||||
dds_entity_t new_datawriter_listener(const dds_entity_t pub, const dds_entity_t tp, const dds_qos_t *q, const dds_listener_t *l);
|
||||
dds_entity_t new_datareader_listener(const dds_entity_t sub, const dds_entity_t tp, const dds_qos_t *q, const dds_listener_t *l);
|
||||
void qos_liveliness(dds_entity_kind_t qt, dds_qos_t *q, const char *arg);
|
||||
void qos_deadline(dds_entity_kind_t qt, dds_qos_t *q, const char *arg);
|
||||
void qos_durability(dds_entity_kind_t qt, dds_qos_t *q, const char *arg);
|
||||
void qos_history(dds_entity_kind_t qt, dds_qos_t *q, const char *arg);
|
||||
void qos_destination_order(dds_entity_kind_t qt, dds_qos_t *q, const char *arg);
|
||||
void qos_ownership(dds_entity_kind_t qt, dds_qos_t *q, const char *arg);
|
||||
void qos_transport_priority(dds_entity_kind_t qt, dds_qos_t *q, const char *arg);
|
||||
void qos_reliability(dds_entity_kind_t qt, dds_qos_t *q, const char *arg);
|
||||
void qos_resource_limits(dds_entity_kind_t qt, dds_qos_t *q, const char *arg);
|
||||
void qos_user_data(dds_entity_kind_t qt, dds_qos_t *q, const char *arg);
|
||||
void qos_latency_budget(dds_entity_kind_t qt, dds_qos_t *q, const char *arg);
|
||||
void qos_lifespan(dds_entity_kind_t qt, dds_qos_t *q, const char *arg);
|
||||
void qos_autodispose_unregistered_instances(dds_entity_kind_t qt, dds_qos_t *q, const char *arg);
|
||||
void set_qosprovider(const char *arg);
|
||||
void setqos_from_args(dds_entity_kind_t qt, dds_qos_t *q, int n, const char *args[]);
|
||||
|
||||
#endif
|
32
src/tools/pubsub/porting.c
Executable file
32
src/tools/pubsub/porting.c
Executable file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "porting.h"
|
||||
|
||||
#if NEED_STRSEP
|
||||
char *strsep(char **str, const char *sep) {
|
||||
char *ret;
|
||||
if (*str == NULL)
|
||||
return NULL;
|
||||
ret = *str;
|
||||
while (**str && strchr(sep, **str) == 0)
|
||||
(*str)++;
|
||||
if (**str == '\0') {
|
||||
*str = NULL;
|
||||
} else {
|
||||
**str = '\0';
|
||||
(*str)++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
27
src/tools/pubsub/porting.h
Executable file
27
src/tools/pubsub/porting.h
Executable file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef __ospli_osplo__porting__
|
||||
#define __ospli_osplo__porting__
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define __attribute__(x)
|
||||
#endif
|
||||
|
||||
#if __SunOS_5_10 && ! defined NEED_STRSEP
|
||||
#define NEED_STRSEP 1
|
||||
#endif
|
||||
|
||||
#if NEED_STRSEP
|
||||
char *strsep(char **str, const char *sep);
|
||||
#endif
|
||||
|
||||
#endif /* defined(__ospli_osplo__porting__) */
|
2768
src/tools/pubsub/pubsub.c
Executable file
2768
src/tools/pubsub/pubsub.c
Executable file
File diff suppressed because it is too large
Load diff
14
src/tools/pubsub/tests/CMakeLists.txt
Normal file
14
src/tools/pubsub/tests/CMakeLists.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
#
|
||||
# Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
#
|
||||
# This program and the accompanying materials are made available under the
|
||||
# terms of the Eclipse Public License v. 2.0 which is available at
|
||||
# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
# v. 1.0 which is available at
|
||||
# http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
#
|
||||
include(Criterion)
|
||||
add_criterion_executable(criterion_tools_pubsub . ../common.c ../testtype.c ../porting.c)
|
||||
target_link_libraries(criterion_tools_pubsub util CycloneDDS::ddsc)
|
28
src/tools/pubsub/tests/basic.c
Normal file
28
src/tools/pubsub/tests/basic.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#include <criterion/criterion.h>
|
||||
#include <criterion/logging.h>
|
||||
|
||||
#define MAIN test_main
|
||||
#include "../pubsub.c"
|
||||
|
||||
Test(tools_pubsub, main) {
|
||||
char *argv[] = {"pubsub", "-T", "pubsubTestTopic", "-K", "KS", "-w1:1", "-D", "1", "-q", "t:d=t,r=r", "pubsub_partition"};
|
||||
int argc = sizeof(argv) / sizeof(char*);
|
||||
|
||||
cr_log_info("Starting pubsub basic test");
|
||||
int result = MAIN(argc, argv);
|
||||
if (result != 0)
|
||||
printf("exitcode was %d\n", result);
|
||||
cr_assert_eq(result, 0, "pubsub exited non-zero");
|
||||
cr_log_info("Stopping pubsub basic test");
|
||||
}
|
176
src/tools/pubsub/testtype.c
Executable file
176
src/tools/pubsub/testtype.c
Executable file
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
/****************************************************************
|
||||
|
||||
Generated by Vortex Lite IDL to C Translator
|
||||
File name: testtype.c
|
||||
Source: testtype.idl
|
||||
Generated: Mon Jun 12 12:03:08 EDT 2017
|
||||
Vortex Lite: V2.1.0
|
||||
|
||||
*****************************************************************/
|
||||
#include "testtype.h"
|
||||
|
||||
|
||||
static const uint32_t OneULong_ops [] =
|
||||
{
|
||||
DDS_OP_ADR | DDS_OP_TYPE_4BY, offsetof (OneULong, seq),
|
||||
DDS_OP_RTS
|
||||
};
|
||||
|
||||
const dds_topic_descriptor_t OneULong_desc =
|
||||
{
|
||||
sizeof (OneULong),
|
||||
4u,
|
||||
0u,
|
||||
0u,
|
||||
"OneULong",
|
||||
NULL,
|
||||
2,
|
||||
OneULong_ops,
|
||||
"<MetaData version=\"1.0.0\"><Struct name=\"OneULong\"><Member name=\"seq\"><ULong/></Member></Struct></MetaData>"
|
||||
};
|
||||
|
||||
|
||||
static const dds_key_descriptor_t Keyed32_keys[1] =
|
||||
{
|
||||
{ "keyval", 2 }
|
||||
};
|
||||
|
||||
static const uint32_t Keyed32_ops [] =
|
||||
{
|
||||
DDS_OP_ADR | DDS_OP_TYPE_4BY, offsetof (Keyed32, seq),
|
||||
DDS_OP_ADR | DDS_OP_TYPE_4BY | DDS_OP_FLAG_KEY, offsetof (Keyed32, keyval),
|
||||
DDS_OP_ADR | DDS_OP_TYPE_ARR | DDS_OP_SUBTYPE_1BY, offsetof (Keyed32, baggage), 24,
|
||||
DDS_OP_RTS
|
||||
};
|
||||
|
||||
const dds_topic_descriptor_t Keyed32_desc =
|
||||
{
|
||||
sizeof (Keyed32),
|
||||
4u,
|
||||
DDS_TOPIC_FIXED_KEY,
|
||||
1u,
|
||||
"Keyed32",
|
||||
Keyed32_keys,
|
||||
4,
|
||||
Keyed32_ops,
|
||||
"<MetaData version=\"1.0.0\"><Struct name=\"Keyed32\"><Member name=\"seq\"><ULong/></Member><Member name=\"keyval\"><Long/></Member><Member name=\"baggage\"><Array size=\"24\"><Octet/></Array></Member></Struct></MetaData>"
|
||||
};
|
||||
|
||||
|
||||
static const dds_key_descriptor_t Keyed64_keys[1] =
|
||||
{
|
||||
{ "keyval", 2 }
|
||||
};
|
||||
|
||||
static const uint32_t Keyed64_ops [] =
|
||||
{
|
||||
DDS_OP_ADR | DDS_OP_TYPE_4BY, offsetof (Keyed64, seq),
|
||||
DDS_OP_ADR | DDS_OP_TYPE_4BY | DDS_OP_FLAG_KEY, offsetof (Keyed64, keyval),
|
||||
DDS_OP_ADR | DDS_OP_TYPE_ARR | DDS_OP_SUBTYPE_1BY, offsetof (Keyed64, baggage), 56,
|
||||
DDS_OP_RTS
|
||||
};
|
||||
|
||||
const dds_topic_descriptor_t Keyed64_desc =
|
||||
{
|
||||
sizeof (Keyed64),
|
||||
4u,
|
||||
DDS_TOPIC_FIXED_KEY,
|
||||
1u,
|
||||
"Keyed64",
|
||||
Keyed64_keys,
|
||||
4,
|
||||
Keyed64_ops,
|
||||
"<MetaData version=\"1.0.0\"><Struct name=\"Keyed64\"><Member name=\"seq\"><ULong/></Member><Member name=\"keyval\"><Long/></Member><Member name=\"baggage\"><Array size=\"56\"><Octet/></Array></Member></Struct></MetaData>"
|
||||
};
|
||||
|
||||
|
||||
static const dds_key_descriptor_t Keyed128_keys[1] =
|
||||
{
|
||||
{ "keyval", 2 }
|
||||
};
|
||||
|
||||
static const uint32_t Keyed128_ops [] =
|
||||
{
|
||||
DDS_OP_ADR | DDS_OP_TYPE_4BY, offsetof (Keyed128, seq),
|
||||
DDS_OP_ADR | DDS_OP_TYPE_4BY | DDS_OP_FLAG_KEY, offsetof (Keyed128, keyval),
|
||||
DDS_OP_ADR | DDS_OP_TYPE_ARR | DDS_OP_SUBTYPE_1BY, offsetof (Keyed128, baggage), 120,
|
||||
DDS_OP_RTS
|
||||
};
|
||||
|
||||
const dds_topic_descriptor_t Keyed128_desc =
|
||||
{
|
||||
sizeof (Keyed128),
|
||||
4u,
|
||||
DDS_TOPIC_FIXED_KEY,
|
||||
1u,
|
||||
"Keyed128",
|
||||
Keyed128_keys,
|
||||
4,
|
||||
Keyed128_ops,
|
||||
"<MetaData version=\"1.0.0\"><Struct name=\"Keyed128\"><Member name=\"seq\"><ULong/></Member><Member name=\"keyval\"><Long/></Member><Member name=\"baggage\"><Array size=\"120\"><Octet/></Array></Member></Struct></MetaData>"
|
||||
};
|
||||
|
||||
|
||||
static const dds_key_descriptor_t Keyed256_keys[1] =
|
||||
{
|
||||
{ "keyval", 2 }
|
||||
};
|
||||
|
||||
static const uint32_t Keyed256_ops [] =
|
||||
{
|
||||
DDS_OP_ADR | DDS_OP_TYPE_4BY, offsetof (Keyed256, seq),
|
||||
DDS_OP_ADR | DDS_OP_TYPE_4BY | DDS_OP_FLAG_KEY, offsetof (Keyed256, keyval),
|
||||
DDS_OP_ADR | DDS_OP_TYPE_ARR | DDS_OP_SUBTYPE_1BY, offsetof (Keyed256, baggage), 248,
|
||||
DDS_OP_RTS
|
||||
};
|
||||
|
||||
const dds_topic_descriptor_t Keyed256_desc =
|
||||
{
|
||||
sizeof (Keyed256),
|
||||
4u,
|
||||
DDS_TOPIC_FIXED_KEY,
|
||||
1u,
|
||||
"Keyed256",
|
||||
Keyed256_keys,
|
||||
4,
|
||||
Keyed256_ops,
|
||||
"<MetaData version=\"1.0.0\"><Struct name=\"Keyed256\"><Member name=\"seq\"><ULong/></Member><Member name=\"keyval\"><Long/></Member><Member name=\"baggage\"><Array size=\"248\"><Octet/></Array></Member></Struct></MetaData>"
|
||||
};
|
||||
|
||||
|
||||
static const dds_key_descriptor_t KeyedSeq_keys[1] =
|
||||
{
|
||||
{ "keyval", 2 }
|
||||
};
|
||||
|
||||
static const uint32_t KeyedSeq_ops [] =
|
||||
{
|
||||
DDS_OP_ADR | DDS_OP_TYPE_4BY, offsetof (KeyedSeq, seq),
|
||||
DDS_OP_ADR | DDS_OP_TYPE_4BY | DDS_OP_FLAG_KEY, offsetof (KeyedSeq, keyval),
|
||||
DDS_OP_ADR | DDS_OP_TYPE_SEQ | DDS_OP_SUBTYPE_1BY, offsetof (KeyedSeq, baggage),
|
||||
DDS_OP_RTS
|
||||
};
|
||||
|
||||
const dds_topic_descriptor_t KeyedSeq_desc =
|
||||
{
|
||||
sizeof (KeyedSeq),
|
||||
sizeof (char *),
|
||||
DDS_TOPIC_FIXED_KEY | DDS_TOPIC_NO_OPTIMIZE,
|
||||
1u,
|
||||
"KeyedSeq",
|
||||
KeyedSeq_keys,
|
||||
4,
|
||||
KeyedSeq_ops,
|
||||
"<MetaData version=\"1.0.0\"><Struct name=\"KeyedSeq\"><Member name=\"seq\"><ULong/></Member><Member name=\"keyval\"><Long/></Member><Member name=\"baggage\"><Sequence><Octet/></Sequence></Member></Struct></MetaData>"
|
||||
};
|
129
src/tools/pubsub/testtype.h
Executable file
129
src/tools/pubsub/testtype.h
Executable file
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
/****************************************************************
|
||||
|
||||
Generated by Vortex Lite IDL to C Translator
|
||||
File name: testtype.h
|
||||
Source: testtype.idl
|
||||
Generated: Mon Jun 12 12:03:08 EDT 2017
|
||||
Vortex Lite: V2.1.0
|
||||
|
||||
*****************************************************************/
|
||||
|
||||
#include "ddsc/dds.h"
|
||||
|
||||
#ifndef _DDSL_TESTTYPE_H_
|
||||
#define _DDSL_TESTTYPE_H_
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct OneULong
|
||||
{
|
||||
uint32_t seq;
|
||||
} OneULong;
|
||||
|
||||
extern const dds_topic_descriptor_t OneULong_desc;
|
||||
|
||||
#define OneULong__alloc() \
|
||||
((OneULong*) dds_alloc (sizeof (OneULong)));
|
||||
|
||||
#define OneULong_free(d,o) \
|
||||
dds_sample_free ((d), &OneULong_desc, (o))
|
||||
|
||||
|
||||
typedef struct Keyed32
|
||||
{
|
||||
uint32_t seq;
|
||||
int32_t keyval;
|
||||
uint8_t baggage[24];
|
||||
} Keyed32;
|
||||
|
||||
extern const dds_topic_descriptor_t Keyed32_desc;
|
||||
|
||||
#define Keyed32__alloc() \
|
||||
((Keyed32*) dds_alloc (sizeof (Keyed32)));
|
||||
|
||||
#define Keyed32_free(d,o) \
|
||||
dds_sample_free ((d), &Keyed32_desc, (o))
|
||||
|
||||
|
||||
typedef struct Keyed64
|
||||
{
|
||||
uint32_t seq;
|
||||
int32_t keyval;
|
||||
uint8_t baggage[56];
|
||||
} Keyed64;
|
||||
|
||||
extern const dds_topic_descriptor_t Keyed64_desc;
|
||||
|
||||
#define Keyed64__alloc() \
|
||||
((Keyed64*) dds_alloc (sizeof (Keyed64)));
|
||||
|
||||
#define Keyed64_free(d,o) \
|
||||
dds_sample_free ((d), &Keyed64_desc, (o))
|
||||
|
||||
|
||||
typedef struct Keyed128
|
||||
{
|
||||
uint32_t seq;
|
||||
int32_t keyval;
|
||||
uint8_t baggage[120];
|
||||
} Keyed128;
|
||||
|
||||
extern const dds_topic_descriptor_t Keyed128_desc;
|
||||
|
||||
#define Keyed128__alloc() \
|
||||
((Keyed128*) dds_alloc (sizeof (Keyed128)));
|
||||
|
||||
#define Keyed128_free(d,o) \
|
||||
dds_sample_free ((d), &Keyed128_desc, (o))
|
||||
|
||||
|
||||
typedef struct Keyed256
|
||||
{
|
||||
uint32_t seq;
|
||||
int32_t keyval;
|
||||
uint8_t baggage[248];
|
||||
} Keyed256;
|
||||
|
||||
extern const dds_topic_descriptor_t Keyed256_desc;
|
||||
|
||||
#define Keyed256__alloc() \
|
||||
((Keyed256*) dds_alloc (sizeof (Keyed256)));
|
||||
|
||||
#define Keyed256_free(d,o) \
|
||||
dds_sample_free ((d), &Keyed256_desc, (o))
|
||||
|
||||
|
||||
typedef struct KeyedSeq
|
||||
{
|
||||
uint32_t seq;
|
||||
int32_t keyval;
|
||||
dds_sequence_t baggage;
|
||||
} KeyedSeq;
|
||||
|
||||
extern const dds_topic_descriptor_t KeyedSeq_desc;
|
||||
|
||||
#define KeyedSeq__alloc() \
|
||||
((KeyedSeq*) dds_alloc (sizeof (KeyedSeq)));
|
||||
|
||||
#define KeyedSeq_free(d,o) \
|
||||
dds_sample_free ((d), &KeyedSeq_desc, (o))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _DDSL_TESTTYPE_H_ */
|
48
src/tools/pubsub/tglib.h
Executable file
48
src/tools/pubsub/tglib.h
Executable file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef __ospli_osplo__tglib__
|
||||
#define __ospli_osplo__tglib__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
struct tgtype;
|
||||
|
||||
struct tgtopic_key {
|
||||
char *name; /* field name */
|
||||
size_t off; /* from start of data */
|
||||
const struct tgtype *type; /* aliases tgtopic::type */
|
||||
};
|
||||
|
||||
struct tgtopic {
|
||||
char *name;
|
||||
size_t size;
|
||||
struct tgtype *type;
|
||||
unsigned nkeys;
|
||||
struct tgtopic_key *keys;
|
||||
};
|
||||
|
||||
enum tgprint_mode {
|
||||
TGPM_DENSE,
|
||||
TGPM_SPACE,
|
||||
TGPM_FIELDS,
|
||||
TGPM_MULTILINE
|
||||
};
|
||||
|
||||
struct tgtopic *tgnew(dds_entity_t tp, int printtype);
|
||||
void tgfree(struct tgtopic *tp);
|
||||
void tgprint(FILE *fp, const struct tgtopic *tp, const void *data, enum tgprint_mode mode);
|
||||
void tgprintkey(FILE *fp, const struct tgtopic *tp, const void *keydata, enum tgprint_mode mode);
|
||||
|
||||
void *tgscan(const struct tgtopic *tp, const char *src, char **endp);
|
||||
void tgfreedata(const struct tgtopic *tp, void *data);
|
||||
|
||||
#endif /* defined(__ospli_osplo__tglib__) */
|
Loading…
Add table
Add a link
Reference in a new issue