Comments (8)
Hi @rapgenic,
Thank you for your interest in cppdap.
There was no easy way to do this (without duplicating the field reflection of the base class into the derived class). #33 however gives you the ability to do this.
Once this lands you can use typeinfo_test.cpp
as a reference for usage.
Many thanks,
Ben
from cppdap.
Now landed.
from cppdap.
@ben-clayton Thank you for your quick answer and implementation!
I tried and I am actually able to subclass the AttachRequest type, however I do not understand how to register the handler: I tried using my custom type in the callback but it does not compile.
I tried to dynamic_cast the AttachRequest to my custom type, but that did not work either.
Could you give me a simple example for making it work? Thank you very much, again
from cppdap.
If you want to just add some custom fields to the request (not the response) you'd declare your extended AttachRequest
request message type as:
namespace dap {
class AttachRequestEx : public AttachRequest {
public:
dap::number some_custom_data;
};
DAP_STRUCT_TYPEINFO_EXT(AttachRequestEx,
AttachRequest,
"attach", // This is the wire protocol name for the AttachRequest
DAP_FIELD(some_custom_data, "some_custom_data")); // Repeat these for each of your custom fields
} // namespace dap
You can then set up a handler for this extended message type with:
void bindAttachRequestExHandler(std::unique_ptr<dap::Session> session) {
session->registerHandler([](const dap::AttachRequestEx& request) {
dap::AttachResponse response;
return response;
});
}
If you want to send a AttachRequestEx
you can with:
void sendAttachRequestEx(std::unique_ptr<dap::Session> session) {
dap::AttachRequestEx request; // Assign to the custom fields.
session->send(request);
}
If you also want a custom derived response type:
namespace dap {
class AttachResponseEx : public AttachResponse {
public:
dap::number some_custom_data;
};
DAP_STRUCT_TYPEINFO_EXT(AttachResponseEx,
AttachResponse,
"",
DAP_FIELD(some_custom_data, "some_custom_data"));
class AttachRequestEx : public AttachRequest {
public:
using Response = AttachResponseEx; // This is the magic that binds the AttachRequestEx to the AttachResponseEx
dap::number some_custom_data;
};
DAP_STRUCT_TYPEINFO_EXT(AttachRequestEx,
AttachRequest,
"attach", // This is the wire protocol name for the AttachRequest
DAP_FIELD(some_custom_data, "some_custom_data"));
} // namespace dap
void bindAttachRequestExHandler(std::unique_ptr<dap::Session> session) {
session->registerHandler([](const dap::AttachRequestEx&) {
dap::AttachResponseEx response; // Note the Ex suffix
return response;
});
}
void sendAttachRequestEx(std::unique_ptr<dap::Session> session) {
dap::AttachRequestEx request; // This is the same...
session->send(request); // but the return type is a dap::AttachResponseEx
}
If you're still having difficulties, please share with me your code snippet and compiler error.
Many thanks,
Ben
Edit: Fixed the wire protocol name which should have been "attach"
. See:
cppdap/src/protocol_requests.cpp
Lines 24 to 26 in cc93ba9
from cppdap.
I think I have managed to do it.
The error was mine, the source was not compiling because I did not return a response.
Thank you very much for your help, I think the issue can be closed now!
Giulio
from cppdap.
Great to hear.
Shout if you have any other questions or issues!
from cppdap.
This is my way . Name another AttachRequest type.
namespace dap {
// The attach request is sent from the client to the debug adapter to attach to
// a debuggee that is already running. Since attaching is debugger/runtime
// specific, the arguments for this request are not part of this specification.
struct JavaDebugAttachRequest : public Request {
using Response = AttachResponse;
JavaDebugAttachRequest() = default;
~JavaDebugAttachRequest() = default;
// Optional data from the previous, restarted session.
// The data is sent as the 'restart' attribute of the 'terminated' event.
// The client should leave the data intact.
// optional<variant<array<any>, boolean, integer, null, number, object, string>>
// restart;
string type;
string name;
string request;
optional<string> projectName;
array<string> sourcePaths;
string hostName;
integer port;
integer timeout;
};
DAP_DECLARE_STRUCT_TYPEINFO(JavaDebugAttachRequest);
DAP_IMPLEMENT_STRUCT_TYPEINFO(JavaDebugAttachRequest,
"attach",
DAP_FIELD(type, "type"),
DAP_FIELD(name, "name"),
DAP_FIELD(request, "request"),
DAP_FIELD(projectName, "projectName"),
DAP_FIELD(sourcePaths, "sourcePaths"),
DAP_FIELD(hostName, "hostName"),
DAP_FIELD(port, "port"),
DAP_FIELD(timeout, "timeout"));
}
from cppdap.
@kuafuwang - your solution works, but the DAP_STRUCT_TYPEINFO_EXT
solution is more future proof - if the DAP specification later adds additional fields to the AttachRequest
, these will automatically be included in your derived type. You could of course just embed those new fields directly into your JavaDebugAttachRequest
, but this a tedious and manual process that you'd need to do every time you update cppdap
that's rolled to the new spec.
Also - DAP_STRUCT_TYPEINFO
is a helper that performs both the DAP_DECLARE_STRUCT_TYPEINFO
and DAP_IMPLEMENT_STRUCT_TYPEINFO
macros into one:
Lines 212 to 217 in cc93ba9
from cppdap.
Related Issues (20)
- Allow starting of `dap::net::Server` on other address than `localhost` HOT 3
- A closed Socket::Shared reads indefinitely HOT 4
- Include missing header in cpp/dap/io.h
- a tag or a release HOT 10
- Manjaro update fails cause cppdap is not found HOT 2
- possibly memory leak reported by valgrind HOT 1
- Async response support
- ABI Break HOT 1
- New tag for 1.65.0?
- Server::start deadlocks on bind failure.
- Update CMake version to 2.8.12 HOT 4
- Create DAP Server which listen a tcp port HOT 2
- Support for Server::start(host, port, callback, OnError)
- intermittent unreleased lock in `Socket::Socket`
- "body" field in "Terminated Event" is an optional field, but if no "body" will return {} in processEvent function. HOT 3
- Building DAP version 1.58.0 HOT 2
- Any client sample? HOT 1
- Add GitHub CI workflows? HOT 1
- How to specify implementation-specific arguments for `LaunchRequest`? HOT 2
- How to handle client socket close when using `dap::net::Server`? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cppdap.