Initial code check in continued

This commit is contained in:
dennis.sheirer
2014-04-26 19:48:24 +00:00
parent 960a6f9952
commit 3dfedcf8d1
474 changed files with 76613 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
******************************************************************************/
package eventlog;
import java.nio.file.Path;
import sample.Listener;
import controller.activity.CallEvent;
public class CallEventLogger extends EventLogger implements Listener<CallEvent>
{
public CallEventLogger( Path logDirectory, String fileNameSuffix )
{
super( logDirectory, fileNameSuffix );
}
@Override
public void receive( CallEvent callEvent )
{
write( callEvent.toCSV() );
}
@Override
public String getHeader()
{
return CallEvent.getCSVHeader();
}
}

View File

@@ -0,0 +1,98 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
******************************************************************************/
package eventlog;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.SwingUtilities;
import controller.channel.AbstractChannelEditor;
import controller.channel.ChannelNode;
import eventlog.config.EventLogConfiguration;
public class EventLogComponentEditor extends AbstractChannelEditor
{
private static final long serialVersionUID = 1L;
private JCheckBox mBinaryLogger = new JCheckBox( "Binary Messages" );
private JCheckBox mDecodedLogger = new JCheckBox( "Decoded Messages" );
private JCheckBox mCallEventLogger = new JCheckBox( "Call Events" );
public EventLogComponentEditor( ChannelNode channelNode )
{
super( channelNode );
add( mBinaryLogger, "span" );
add( mDecodedLogger, "span" );
add( mCallEventLogger, "span" );
reset();
}
/**
* Sets the combo box to the type stored in the config object, causing the
* editor panel to reset with the stored config
*/
public void reset()
{
SwingUtilities.invokeLater(new Runnable()
{
final ArrayList<EventLogType> mLoggers = mChannelNode.getChannel()
.getEventLogConfiguration().getLoggers();
@Override
public void run()
{
mBinaryLogger.setSelected(
mLoggers.contains( EventLogType.BINARY_MESSAGE ) );
mDecodedLogger.setSelected(
mLoggers.contains( EventLogType.DECODED_MESSAGE ) );
mCallEventLogger.setSelected(
mLoggers.contains( EventLogType.CALL_EVENT ) );
}
});
}
/**
* Saves the current configuration as the stored configuration
*/
@Override
public void save()
{
EventLogConfiguration config = mChannelNode.getChannel()
.getEventLogConfiguration();
config.clear();
if( mBinaryLogger.isSelected() )
{
config.addLogger( EventLogType.BINARY_MESSAGE );
}
if( mDecodedLogger.isSelected() )
{
config.addLogger( EventLogType.DECODED_MESSAGE );
}
if( mCallEventLogger.isSelected() )
{
config.addLogger( EventLogType.CALL_EVENT );
}
}
}

View File

@@ -0,0 +1,60 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
******************************************************************************/
package eventlog;
import java.nio.file.Path;
import properties.SystemProperties;
import controller.channel.ProcessingChain;
import eventlog.MessageEventLogger.Type;
public class EventLogManager
{
private Path mDirectory;
public EventLogManager()
{
mDirectory = SystemProperties.getInstance()
.getApplicationFolder( "event_logs" );
}
public EventLogger getLogger( ProcessingChain chain, EventLogType eventLogType )
{
StringBuilder sb = new StringBuilder();
sb.append( chain.getChannel().getSystem() );
sb.append( "_" );
sb.append( chain.getChannel().getSite() );
sb.append( "_" );
sb.append( chain.getChannel().getName() );
sb.append( eventLogType.getFileSuffix() );
sb.append( ".log" );
switch( eventLogType )
{
case BINARY_MESSAGE:
return new MessageEventLogger( mDirectory, sb.toString(), Type.BINARY );
case DECODED_MESSAGE:
return new MessageEventLogger( mDirectory, sb.toString(), Type.DECODED );
case CALL_EVENT:
return new CallEventLogger( mDirectory, sb.toString() );
default:
return null;
}
}
}

View File

@@ -0,0 +1,51 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
******************************************************************************/
package eventlog;
public enum EventLogType
{
BINARY_MESSAGE( "Binary Messages", "_binary_messages" ),
DECODED_MESSAGE( "Decoded Messages", "_decoded_messages" ),
CALL_EVENT( "Call Events", "_call_events" );
private String mDisplayString;
private String mFileSuffix;
EventLogType( String displayString, String fileSuffix )
{
mDisplayString = displayString;
mFileSuffix = fileSuffix;
}
public String getDisplayString()
{
return mDisplayString;
}
public String getFileSuffix()
{
return mFileSuffix;
}
@Override
public String toString()
{
return mDisplayString;
}
}

View File

@@ -0,0 +1,111 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
******************************************************************************/
package eventlog;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.file.Path;
import log.Log;
import util.TimeStamp;
public abstract class EventLogger
{
private Path mLogDirectory;
private String mFileNameSuffix;
private String mLogFileName;
protected Writer mLogFile;
public EventLogger( Path logDirectory, String fileNameSuffix )
{
mLogDirectory = logDirectory;
mFileNameSuffix = fileNameSuffix;
}
public String toString()
{
if( mLogFileName != null )
{
return mLogFileName;
}
else
{
return "Unknown";
}
}
public abstract String getHeader();
public void start()
{
try
{
StringBuilder sb = new StringBuilder();
sb.append( mLogDirectory );
sb.append( File.separator );
sb.append( TimeStamp.getTimeStamp( "_" ) );
sb.append( "_" );
sb.append( mFileNameSuffix );
mLogFileName = sb.toString();
Log.info( "Creating log file:" + mLogFileName );
mLogFile = new OutputStreamWriter(new FileOutputStream( mLogFileName ) );
write( getHeader() );
}
catch (FileNotFoundException e)
{
Log.error("Couldn't create log file in directory:" + mLogDirectory );
}
}
public void stop()
{
if( mLogFile != null )
{
try
{
mLogFile.flush();
mLogFile.close();
}
catch( Exception e )
{
Log.error( "Couldn't close log file:" + mFileNameSuffix );
}
}
}
protected void write( String eventLogEntry )
{
try
{
mLogFile.write( eventLogEntry + "\n" );
}
catch ( IOException e )
{
Log.error( "Error writing entry to event log file:" + e.getLocalizedMessage() );
}
}
}

View File

@@ -0,0 +1,65 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
******************************************************************************/
package eventlog;
import java.nio.file.Path;
import message.Message;
import sample.Listener;
import util.TimeStamp;
public class MessageEventLogger extends EventLogger implements Listener<Message>
{
public enum Type { BINARY, DECODED };
private Type mType;
public MessageEventLogger( Path logDirectory, String fileNameSuffix, Type type )
{
super( logDirectory, fileNameSuffix );
mType = type;
}
@Override
public void receive( Message message )
{
StringBuilder sb = new StringBuilder();
sb.append( TimeStamp.getTimeStamp( " " ) );
sb.append( "," );
sb.append( ( message.isValid() ? "PASSED" : "FAILED" ) );
sb.append( "," );
if( mType == Type.BINARY )
{
sb.append( message.getBinaryMessage() );
}
else
{
sb.append( message.getMessage() );
}
write( sb.toString() );
}
@Override
public String getHeader()
{
return mType.toString() + " Message Logger\n";
}
}

View File

@@ -0,0 +1,57 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
******************************************************************************/
package eventlog.config;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import controller.config.Configuration;
import eventlog.EventLogType;
@XmlRootElement( name = "event_log_configuration" )
public class EventLogConfiguration extends Configuration
{
protected ArrayList<EventLogType> mLoggers = new ArrayList<EventLogType>();
public EventLogConfiguration()
{
}
@XmlElement( name = "logger" )
public ArrayList<EventLogType> getLoggers()
{
return mLoggers;
}
public void setLoggers( ArrayList<EventLogType> loggers )
{
mLoggers = loggers;
}
public void addLogger( EventLogType logger )
{
mLoggers.add( logger );
}
public void clear()
{
mLoggers.clear();
}
}