From 6459bb3e5c82cdd5474bdd77d8aff3a12ce88910 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 14 Jan 2014 13:17:25 +0100 Subject: wx: Refactor C++ code Try to clean up the files a bit --- lib/wx/c_src/wxe_helpers.h | 111 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 lib/wx/c_src/wxe_helpers.h (limited to 'lib/wx/c_src/wxe_helpers.h') diff --git a/lib/wx/c_src/wxe_helpers.h b/lib/wx/c_src/wxe_helpers.h new file mode 100644 index 0000000000..c8a7e35bdb --- /dev/null +++ b/lib/wx/c_src/wxe_helpers.h @@ -0,0 +1,111 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 2014. All Rights Reserved. + * + * The contents of this file are subject to the Erlang Public License, + * Version 1.1, (the "License"); you may not use this file except in + * compliance with the License. You should have received a copy of the + * Erlang Public License along with this software. If not, it can be + * retrieved online at http://www.erlang.org/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * %CopyrightEnd% + */ + +#ifndef _WXE_HELPER_H +#define _WXE_HELPER_H + +DECLARE_EVENT_TYPE(wxeEVT_META_COMMAND, -1) + +class wxeMetaCommand : public wxEvent +{ + public: + wxeMetaCommand(wxe_data *sd, int EvId) + : wxEvent(EvId, wxeEVT_META_COMMAND) + { caller = driver_caller(sd->port_handle); port = sd->port; pdl = sd->pdl; } ; + wxeMetaCommand(const wxeMetaCommand& event) + : wxEvent(event) + { caller = event.caller; port = event.port; pdl = event.pdl; }; + virtual ~wxeMetaCommand() {}; + virtual wxEvent *Clone() const { return new wxeMetaCommand(*this); } + + ErlDrvTermData caller; + ErlDrvTermData port; + ErlDrvPDL pdl; +}; + +class wxeCommand : public wxObject +{ + public: + wxeCommand(int fc,char * cbuf,int buflen, wxe_data *); + virtual ~wxeCommand(); + + ErlDrvTermData caller; + ErlDrvTermData port; + WXEBinRef * bin[3]; + char * buffer; + int len; + int op; +}; + +class intListElement { + public: + intListElement(int Element) {car = Element; cdr = NULL;}; + intListElement(int Element, intListElement *list) + {car = Element; cdr = list;}; + int car; + intListElement *cdr; +}; + +class intList { + public: + intList() {list = NULL;}; + bool IsEmpty() {return list == NULL;}; + void Append(int Element) { list = new intListElement(Element, list); }; + int Pop() { + intListElement *temp = list; + int res = list->car; + list = temp->cdr; + delete temp; + return res; + } + intListElement *list; +}; + +class wxe_badarg +{ + public: + wxe_badarg(int Ref) : ref(Ref) { } ; + int ref; +}; + +class wxeErlTerm : public wxClientData +{ + public: + wxeErlTerm(WXEBinRef * data) + { + size = data->size; + bin = (char *) driver_alloc(size); + memcpy(bin, data->base, size); + } ; + ~wxeErlTerm() { driver_free(bin); }; + char * bin; + int size; +}; + +class wxETreeItemData : public wxTreeItemData +{ + public: + wxETreeItemData(int sz, char * data); + ~wxETreeItemData(); + + int size; + char * bin; +}; + +#endif -- cgit v1.2.3 From fd055cf43486358a413a1fa22f30f0aa711d25e1 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Thu, 23 Jan 2014 15:33:09 +0100 Subject: wx: Delay all deletes if recursed in event loop Avoids crashes. --- lib/wx/c_src/wxe_helpers.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/wx/c_src/wxe_helpers.h') diff --git a/lib/wx/c_src/wxe_helpers.h b/lib/wx/c_src/wxe_helpers.h index c8a7e35bdb..659bc666c6 100644 --- a/lib/wx/c_src/wxe_helpers.h +++ b/lib/wx/c_src/wxe_helpers.h @@ -43,7 +43,10 @@ class wxeCommand : public wxObject { public: wxeCommand(int fc,char * cbuf,int buflen, wxe_data *); - virtual ~wxeCommand(); + virtual ~wxeCommand(); // Use Delete() + + wxeCommand * Save() {ref_count++; return this; }; + void Delete() {if(--ref_count < 1) delete this;}; ErlDrvTermData caller; ErlDrvTermData port; @@ -51,6 +54,7 @@ class wxeCommand : public wxObject char * buffer; int len; int op; + int ref_count; }; class intListElement { @@ -65,6 +69,13 @@ class intListElement { class intList { public: intList() {list = NULL;}; + ~intList() { + intListElement *head = list; + while(head) { + intListElement *tail=head->cdr; + delete head; + head = tail; + } }; bool IsEmpty() {return list == NULL;}; void Append(int Element) { list = new intListElement(Element, list); }; int Pop() { -- cgit v1.2.3 From 3e12120327654e7e66f7ae09cd3929cb1132766c Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Mon, 13 Apr 2015 15:58:22 +0200 Subject: wx: Optimize command queues Remove allocations --- lib/wx/c_src/wxe_helpers.h | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'lib/wx/c_src/wxe_helpers.h') diff --git a/lib/wx/c_src/wxe_helpers.h b/lib/wx/c_src/wxe_helpers.h index 659bc666c6..ec3a5debdb 100644 --- a/lib/wx/c_src/wxe_helpers.h +++ b/lib/wx/c_src/wxe_helpers.h @@ -39,14 +39,14 @@ class wxeMetaCommand : public wxEvent ErlDrvPDL pdl; }; -class wxeCommand : public wxObject +class wxeCommand { public: - wxeCommand(int fc,char * cbuf,int buflen, wxe_data *); + wxeCommand(); virtual ~wxeCommand(); // Use Delete() - wxeCommand * Save() {ref_count++; return this; }; - void Delete() {if(--ref_count < 1) delete this;}; + wxeCommand * Save() { return this; }; + void Delete(); ErlDrvTermData caller; ErlDrvTermData port; @@ -54,7 +54,27 @@ class wxeCommand : public wxObject char * buffer; int len; int op; - int ref_count; + char c_buf[64]; // 64b covers 90% of usage +}; + +class wxeFifo { + public: + wxeFifo(unsigned int size); + virtual ~wxeFifo(); + + void Add(int fc, char * cbuf,int buflen, wxe_data *); + void Append(wxeCommand *Other); + + wxeCommand * Get(); + + void Realloc(); + + unsigned int m_max; + unsigned int m_first; + unsigned int m_n; + unsigned int m_orig_sz; + wxeCommand *m_q; + wxeCommand *m_old; }; class intListElement { -- cgit v1.2.3 From 38cb91a91ac2d8f3231761b98909ff89416a4942 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Thu, 4 Jun 2015 15:57:37 +0200 Subject: wx: Optimize binary args --- lib/wx/c_src/wxe_helpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/wx/c_src/wxe_helpers.h') diff --git a/lib/wx/c_src/wxe_helpers.h b/lib/wx/c_src/wxe_helpers.h index ec3a5debdb..61d385641f 100644 --- a/lib/wx/c_src/wxe_helpers.h +++ b/lib/wx/c_src/wxe_helpers.h @@ -50,7 +50,7 @@ class wxeCommand ErlDrvTermData caller; ErlDrvTermData port; - WXEBinRef * bin[3]; + WXEBinRef bin[3]; char * buffer; int len; int op; -- cgit v1.2.3 From 738c34d4bb8f1a3811acd00af8c6c12107f8315b Mon Sep 17 00:00:00 2001 From: Bruce Yinhe Date: Thu, 18 Jun 2015 11:31:02 +0200 Subject: Change license text to APLv2 --- lib/wx/c_src/wxe_helpers.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'lib/wx/c_src/wxe_helpers.h') diff --git a/lib/wx/c_src/wxe_helpers.h b/lib/wx/c_src/wxe_helpers.h index 61d385641f..4f9d9ca9c3 100644 --- a/lib/wx/c_src/wxe_helpers.h +++ b/lib/wx/c_src/wxe_helpers.h @@ -3,16 +3,17 @@ * * Copyright Ericsson AB 2014. All Rights Reserved. * - * The contents of this file are subject to the Erlang Public License, - * Version 1.1, (the "License"); you may not use this file except in - * compliance with the License. You should have received a copy of the - * Erlang Public License along with this software. If not, it can be - * retrieved online at http://www.erlang.org/. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * * %CopyrightEnd% */ -- cgit v1.2.3 From e732293edc5a970885d9eb362dcaddf3548f84a4 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 20 Oct 2015 10:19:16 +0200 Subject: wx: Use only one ring buffer for command queue Avoid copying between command queues, cleaner, faster and safer implementation. --- lib/wx/c_src/wxe_helpers.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/wx/c_src/wxe_helpers.h') diff --git a/lib/wx/c_src/wxe_helpers.h b/lib/wx/c_src/wxe_helpers.h index 4f9d9ca9c3..ff949e332b 100644 --- a/lib/wx/c_src/wxe_helpers.h +++ b/lib/wx/c_src/wxe_helpers.h @@ -67,9 +67,13 @@ class wxeFifo { void Append(wxeCommand *Other); wxeCommand * Get(); + wxeCommand * Peek(unsigned int *item); void Realloc(); + void Strip(); + unsigned int Cleanup(unsigned int peek=0); + unsigned int cb_start; unsigned int m_max; unsigned int m_first; unsigned int m_n; -- cgit v1.2.3 From 6664eed554974336909d3ffe03f20349cc4c38fd Mon Sep 17 00:00:00 2001 From: Henrik Nord Date: Tue, 15 Mar 2016 15:19:56 +0100 Subject: update copyright-year --- lib/wx/c_src/wxe_helpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/wx/c_src/wxe_helpers.h') diff --git a/lib/wx/c_src/wxe_helpers.h b/lib/wx/c_src/wxe_helpers.h index ff949e332b..3f66b6d97a 100644 --- a/lib/wx/c_src/wxe_helpers.h +++ b/lib/wx/c_src/wxe_helpers.h @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2014. All Rights Reserved. + * Copyright Ericsson AB 2014-2016. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. -- cgit v1.2.3 From 7604209d02278b5547ae42fb328bfbc7d9043963 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Fri, 15 Apr 2016 10:19:59 +0200 Subject: wx: Fix callback problems Commands could be executed twice, if the command was dispatched from a callback and caused a recursive invocation of command loop. Solution is to mark op as -1 before calling wxWidgets. Also commands could be missed when idle processing was done inside while executing a recursive callback, solved be always resetting peak index after idle processing is done. --- lib/wx/c_src/wxe_helpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/wx/c_src/wxe_helpers.h') diff --git a/lib/wx/c_src/wxe_helpers.h b/lib/wx/c_src/wxe_helpers.h index 3f66b6d97a..70ffccdc13 100644 --- a/lib/wx/c_src/wxe_helpers.h +++ b/lib/wx/c_src/wxe_helpers.h @@ -46,7 +46,7 @@ class wxeCommand wxeCommand(); virtual ~wxeCommand(); // Use Delete() - wxeCommand * Save() { return this; }; + wxeCommand * Save(int Op) { op = Op; return this; }; void Delete(); ErlDrvTermData caller; -- cgit v1.2.3