Skip to content

Commit

Permalink
'toggle enquire link logs' button added
Browse files Browse the repository at this point in the history
  • Loading branch information
ukarim committed Sep 5, 2023
1 parent daebf9a commit 3a94ae2
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {

java {
sourceCompatibility = JavaVersion.VERSION_11
version = '0.1.4-SNAPSHOT'
version = '0.1.4'
}

def smppguiFilename = 'smppgui.jar'
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/com/ukarim/smppgui/core/SmppHandlerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,17 @@ public class SmppHandlerImpl implements SmppHandler {

private Charset defaultCharset;

private boolean showEnqLinkLogs = true; // show enquire_link logs by default

public SmppHandlerImpl(EventDispatcher eventDispatcher) {
this.eventDispatcher = eventDispatcher;
this.smppClient = new SmppClient(this);
}

public void toggleEnqLinkLogs() {
showEnqLinkLogs = !showEnqLinkLogs;
}

@Override
public Pdu handlePdu(Pdu pdu, Throwable e) {
if (e != null) {
Expand All @@ -63,10 +69,12 @@ public Pdu handlePdu(Pdu pdu, Throwable e) {
eventDispatcher.dispatch(EventType.SHOW_LOGIN_FORM);
return null;
}
printMsg("Pdu received:\n%s", fmtPdu(pdu));
if (shouldLogPdu(pdu)) {
printMsg("Pdu received:\n%s", fmtPdu(pdu));
}

Pdu respPdu = handlePduInternal(pdu);
if (respPdu != null) {
if (respPdu != null && shouldLogPdu(pdu)) {
printMsg("Pdu sent:\n%s", fmtPdu(respPdu));
}
return respPdu;
Expand Down Expand Up @@ -246,4 +254,11 @@ private String fmtPdu(Pdu pdu) {
private String fmtPdu(Pdu pdu, Charset charset) {
return FmtUtils.fmtPdu(pdu, charset);
}

private boolean shouldLogPdu(Pdu pdu) {
if (SmppCmd.ENQUIRE_LINK.equals(pdu.getCmd())) {
return showEnqLinkLogs;
}
return true;
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/ukarim/smppgui/gui/EventDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ private void dispatchInternal(EventType eventType, Object eventAttach) {
}
case CLEAR_LOGS:
loggingPane.clearLogs();
break;
case TOGGLE_ENQ_LINK_LOGS:
smppHandler.toggleEnqLinkLogs();
break;
default: {
// NOOP
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/ukarim/smppgui/gui/EventType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public enum EventType {
SHOW_INFO,
DO_SUBMIT,
CLEAR_LOGS,
TOGGLE_ENQ_LINK_LOGS,
}
2 changes: 1 addition & 1 deletion src/main/java/com/ukarim/smppgui/gui/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class MainFrame extends JFrame {

private static final int WIDTH = 1200;
private static final int HEIGHT = 600;
private static final int HEIGHT = 700;
private static final Image ICON = Resources.loadImage("/icon.png");
private static final String ABOUT_INFO = Resources.loadStr("/about.txt");

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/ukarim/smppgui/gui/SubmitForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
Expand Down Expand Up @@ -62,6 +63,9 @@ class SubmitForm extends JPanel implements ActionListener {
var clearLogsButton = new JButton("Clear logs");
clearLogsButton.addActionListener((e) -> eventDispatcher.dispatch(EventType.CLEAR_LOGS));

var enqLinkLogButton = new JButton("Toggle enquire links logging");
enqLinkLogButton.addActionListener((e) -> eventDispatcher.dispatch(EventType.TOGGLE_ENQ_LINK_LOGS));

var submitButton = new JButton("Send");
submitButton.addActionListener(this);

Expand All @@ -79,6 +83,8 @@ class SubmitForm extends JPanel implements ActionListener {

var components = Arrays.asList(
new Pair(disconnectButton, clearLogsButton),
new Pair(null, enqLinkLogButton),
new Pair(new JSeparator(), new JSeparator()),

// mandatory fields
new Pair(new JLabel("source_addr"), srcAddrField),
Expand Down

0 comments on commit 3a94ae2

Please sign in to comment.