-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit converts the stdin/stdout IPC interface to use FFI using emulated stdin/stdout. Signed-off-by: Sumner Evans <[email protected]>
- Loading branch information
1 parent
7c700e3
commit 688129a
Showing
13 changed files
with
108 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ | |
/beeper-imessage | ||
/start | ||
/.android-ipc-bin | ||
/imgo.h | ||
/imgo.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// beeper-imessage - A Matrix-iMessage puppeting bridge. | ||
// Copyright (C) 2023 Beeper, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero 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 Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package main | ||
|
||
import "C" | ||
import ( | ||
"io" | ||
"unsafe" | ||
) | ||
|
||
var FFIStdinReader, FFIStdinWriter = io.Pipe() | ||
|
||
// stdin_write is a function which allows C code to write to the fake "stdin" | ||
// buffer. | ||
// | ||
// This function returns the number of bytes written, or -1 if an error | ||
// occurred. | ||
// | ||
//export stdin_write | ||
func stdin_write(data *C.char, n C.int) C.int { | ||
buf := C.GoBytes(unsafe.Pointer(data), n) | ||
written, err := FFIStdinWriter.Write(buf) | ||
if err != nil { | ||
return C.int(-1) | ||
} | ||
return C.int(written) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <stdio.h> | ||
|
||
typedef void (*stdout_callback_t)(const char *, int); | ||
|
||
void stdout_write(stdout_callback_t callback, const char *data, int n) { | ||
callback(data, n); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// beeper-imessage - A Matrix-iMessage puppeting bridge. | ||
// Copyright (C) 2023 Beeper, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero 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 Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package main | ||
|
||
/* | ||
#include <stdio.h> | ||
// stdout_callback is a function pointer to a function that takes a string and | ||
// returns nothing. | ||
typedef void (*stdout_callback_t)(const char*, int); | ||
void stdout_write(stdout_callback_t callback, const char* data, int n); | ||
*/ | ||
import "C" | ||
import "unsafe" | ||
|
||
type ffiStdout struct { | ||
callback C.stdout_callback_t | ||
} | ||
|
||
func (s *ffiStdout) Write(p []byte) (n int, err error) { | ||
C.stdout_write(s.callback, (*C.char)(unsafe.Pointer(&p[0])), C.int(len(p))) | ||
return len(p), nil | ||
} | ||
|
||
var FFIStdout = ffiStdout{} | ||
|
||
//export set_stdout_callback | ||
func set_stdout_callback(callback C.stdout_callback_t) { | ||
FFIStdout.callback = callback | ||
} |