Skip to content

Commit

Permalink
Merge pull request #24 from moaxcp/fix-plugins
Browse files Browse the repository at this point in the history
Fix plugins
  • Loading branch information
moaxcp committed Dec 6, 2023
2 parents ad09881 + ad32786 commit 53f900f
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 17 deletions.
11 changes: 11 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/modules/x11-client.integrationTest.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/modules/x11-client.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules/x11-client.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules/x11-client.testFixtures.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions .idea/runConfigurations.xml

This file was deleted.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ https://jamey.thesharps.us/2021/03/25/xcb-protocol-specifications-data/

# versions

## 0.13.0

ProtocolPluginService now sets majorOpcode on XProtocolPlugins and uses it instead of majorVersion as the base opcode for requests. This fixes a bug in loading plugins and sending requests.

## 0.12.0

Adding jbang examples
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
id 'jacoco'
}

version = '0.12.0'
version = '0.13.0'
group = 'com.github.moaxcp.x11'
description = 'An x11 client implemented in java'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ class XResult {
.initializer('$L', minorVersion)
.build())

builder.addField(
FieldSpec.builder(byte.class, 'majorOpcode', Modifier.PRIVATE)
.addAnnotation(Getter.class)
.addAnnotation(Setter.class)
.build())

builder.addField(
FieldSpec.builder(byte.class, 'firstEvent', Modifier.PRIVATE)
.addAnnotation(Getter.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class XPluginSpec extends XmlSpec {
@lombok.Getter
private byte minorVersion = 3;
@lombok.Getter
@lombok.Setter
private byte majorOpcode;
@lombok.Getter
@lombok.Setter
private byte firstEvent;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.github.moaxcp.x11client;

import com.github.moaxcp.x11client.protocol.record.QueryVersion;
import com.github.moaxcp.x11client.protocol.record.QueryVersionReply;
import java.io.IOException;
import lombok.extern.java.Log;
import org.junit.jupiter.api.Test;

@Log
public class QueryVersionIT {
@Test
void record() throws IOException {
try (X11Client client = X11Client.connect()) {
QueryVersion queryVersion = QueryVersion.builder().majorVersion((short) 1).minorVersion((short) 13).build();
QueryVersionReply reply = client.send(queryVersion);
log.info(reply.toString());
}
}
}
60 changes: 60 additions & 0 deletions src/integrationTest/java/com/github/moaxcp/x11client/RecordIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.github.moaxcp.x11client;

import com.github.moaxcp.x11client.protocol.record.*;
import lombok.extern.java.Log;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Collections;

@Log
public class RecordIT {
@Test
void test() {
try (X11Client client = X11Client.connect()) {
int rc = client.nextResourceId();
Range8 empty = Range8.builder().build();
ExtRange emptyExtRange = ExtRange.builder()
.major(empty)
.minor(Range16.builder().build())
.build();
Range range = Range.builder()
.deviceEvents(Range8.builder().first((byte) 2).last((byte) 6).build())
.coreRequests(empty)
.coreReplies(empty)
.extRequests(emptyExtRange)
.extReplies(emptyExtRange)
.deliveredEvents(empty)
.clientStarted(false)
.errors(empty)
.clientDied(false)
.build();

CreateContext createContext = CreateContext.builder()
.context(rc)
.clientSpecs(Collections.singletonList(Cs.ALL_CLIENTS.getValue()))
.elementHeader((byte) 0)
.ranges(Collections.singletonList(range))
.build();

log.info(String.format("createContext: %s, size: %d, length: %d", createContext, createContext.getSize(), createContext.getLength()));

client.send(createContext);

client.sync();

EnableContext enableContext = EnableContext
.builder()
.context(rc)
.build();
EnableContextReply enableContextReply = client.send(enableContext);
if (enableContextReply.getCategory() == 0) {
for (Byte datum : enableContextReply.getData()) {
System.out.println(datum);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ boolean activatePlugin(String name, byte majorOpcode, byte firstEvent, byte firs
Optional<XProtocolPlugin> loaded = loadedPlugin(name);
if(loaded.isPresent()) {
XProtocolPlugin plugin = loaded.get();
if(plugin.getMajorVersion() != majorOpcode) {
return false; //client must match server version
}
plugin.setMajorOpcode(majorOpcode);
plugin.setFirstEvent(firstEvent);
plugin.setFirstError(firstError);
activatedPlugins.add(plugin);
Expand All @@ -74,11 +72,11 @@ boolean activatedPlugin(String name) {
return getActivatedPlugin(name).isPresent();
}

byte majorVersionForRequest(XRequest request) {
byte majorOpcodeForRequest(XRequest request) {
return activatedPlugins.stream()
.filter(p -> p.supportedRequest(request))
.findFirst()
.map(XProtocolPlugin::getMajorVersion)
.map(XProtocolPlugin::getMajorOpcode)
.orElseThrow(() -> new UnsupportedOperationException("Plugin missing or not activated for request. Could not find majorOpcode for request: " + request));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void send(OneWayRequest request) {

private void actuallySend(XRequest request) {
try {
request.write(pluginService.majorVersionForRequest(request), out);
request.write(pluginService.majorOpcodeForRequest(request), out);
} catch(IOException e) {
throw new X11ClientException("exception writing request \"" + request + "\"", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public interface XProtocolPlugin {
String getName();
byte getMajorVersion();
byte getMinorVersion();
byte getMajorOpcode();
void setMajorOpcode(byte firstOpcode);
byte getFirstEvent();
void setFirstEvent(byte firstEvent);
byte getFirstError();
Expand Down

0 comments on commit 53f900f

Please sign in to comment.