add custom Editor and Unidraw class to DrawServ library
Brought to you by:
johnston
From: <ivt...@li...> - 2004-02-12 21:33:10
|
Patch: ivtools-040212-johnston-010 For: ivtools-1.1.2 Author: joh...@us... Subject: add custom Editor and Unidraw class to DrawServ library. Requires: This is an intermediate patch to ivtools-1.1.2. To apply, cd to the top-level directory of the ivtools source tree (the directory with src and config subdirs), and apply like this: patch -p0 <ThisFile Summary of Changes: - extend the DrawServ class library with its own specialized Editor (DrawEditor) and Unidraw (DrawServ) class. Populate with an empty drawserv func. Index: DrawServ/Imakefile diff -c DrawServ/Imakefile:1.1 DrawServ/Imakefile:1.2 *** DrawServ/Imakefile:1.1 Fri Jan 9 11:45:18 2004 --- src/DrawServ/Imakefile Thu Feb 12 13:27:07 2004 *************** *** 18,23 **** --- 18,26 ---- Obj26(drawcatalog) Obj26(drawcreator) Obj26(drawcomps) + Obj26(draweditor) + Obj26(drawfunc) + Obj26(drawserv) Obj26(drawviews) Index: DrawServ/draweditor.c diff -c /dev/null DrawServ/draweditor.c:1.1 *** /dev/null Thu Feb 12 13:27:08 2004 --- src/DrawServ/draweditor.c Thu Feb 12 13:27:07 2004 *************** *** 0 **** --- 1,88 ---- + /* + * Copyright (c) 2004 Scott E. Johnston + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + + #include <DrawServ/drawcomps.h> + #include <DrawServ/draweditor.h> + #include <DrawServ/drawfunc.h> + #include <DrawServ/drawserv.h> + + #include <Unidraw/catalog.h> + + #include <ComTerp/comterpserv.h> + + / ************************************************************************ *****/ + + DrawEditor::DrawEditor(OverlayComp* comp, OverlayKit* kit) + : FrameEditor(false, kit) { + Init(comp, "DrawEditor"); + } + + DrawEditor::DrawEditor(const char* file, OverlayKit* kit) + : FrameEditor(false, kit) + { + if (file == nil) { + Init(); + + } else { + Catalog* catalog = unidraw->GetCatalog(); + OverlayComp* comp; + + if (catalog->Retrieve(file, (Component*&) comp)) { + Init(comp); + + } else { + Init(); + fprintf(stderr, "drawserv: couldn't open %s\n", file); + } + } + } + + DrawEditor::DrawEditor(boolean initflag, OverlayKit* kit) + : FrameEditor(initflag, kit) { + } + + void DrawEditor::Init (OverlayComp* comp, const char* name) { + _curr_others = _prev_others = nil; + _num_curr_others = _num_prev_others = 0; + _texteditor = nil; + _autonewframe = false; + _autonewframe_tts = nil; + if (!comp) comp = new DrawIdrawComp; + _terp = new ComTerpServ(); + ((OverlayUnidraw*)unidraw)->comterp(_terp); + AddCommands(_terp); + add_comterp("DrawServ", _terp); + _overlay_kit->Init(comp, name); + InitFrame(); + } + + void DrawEditor::InitCommands() { + FrameEditor::InitCommands(); + } + + void DrawEditor::AddCommands(ComTerp* comterp) { + FrameEditor::AddCommands(comterp); + + comterp->add_command("drawserv", new DrawServFunc(comterp, this)); + } + Index: DrawServ/draweditor.h diff -c /dev/null DrawServ/draweditor.h:1.1 *** /dev/null Thu Feb 12 13:27:08 2004 --- src/DrawServ/draweditor.h Thu Feb 12 13:27:07 2004 *************** *** 0 **** --- 1,50 ---- + /* + * Copyright (c) 2004 Scott E. Johnston + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + + #ifndef draweditor_h + #define draweditor_h + + #include <FrameUnidraw/frameeditor.h> + + //: editor for DrawServ application + class DrawEditor : public FrameEditor { + public: + DrawEditor(OverlayComp*, OverlayKit* = OverlayKit::Instance()); + // constructor for using existing component. + DrawEditor(const char* file, OverlayKit* = OverlayKit::Instance()); + // constructor for building top-level component from a file. + DrawEditor(boolean initflag, OverlayKit* = OverlayKit::Instance()); + // constructor for use of derived classes. + void Init(OverlayComp* = nil, const char* name = "DrawEditor"); + virtual void InitCommands(); + // method for running Unidraw Command objects after OverlayEditor + // is constructed. + virtual void AddCommands(ComTerp*); + // method for adding ComFunc objects to the ComTerp associated with + // this DrawEditor. + + protected: + + }; + + #endif Index: DrawServ/drawfunc.c diff -c /dev/null DrawServ/drawfunc.c:1.1 *** /dev/null Thu Feb 12 13:27:08 2004 --- src/DrawServ/drawfunc.c Thu Feb 12 13:27:07 2004 *************** *** 0 **** --- 1,120 ---- + /* + * Copyright (c) 2004 Scott E. Johnston + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + + #ifdef HAVE_ACE + #include <ComTerp/comhandler.h> + #include <ace/SOCK_Connector.h> + #endif + + #include <DrawServ/draweditor.h> + #include <DrawServ/drawfunc.h> + + #define TITLE "DrawServFunc" + + / ************************************************************************ *****/ + + DrawServFunc::DrawServFunc(ComTerp* comterp, DrawEditor* ed) : UnidrawFunc(comterp, ed) { + } + + void DrawServFunc::execute() { + #if 1 + reset_stack(); + printf("drawserv func is empty\n"); + push_stack(ComValue::nullval()); + #else + ComValue hostv(stack_arg(0, true)); + ComValue portv(stack_arg(1)); + ComValue cmdstrv(stack_arg(2)); + static int nowait_sym = symbol_add("nowait"); + ComValue nowaitv(stack_key(nowait_sym)); + reset_stack(); + + #ifdef HAVE_ACE + + #if __GNUC__==3&&__GNUC_MINOR__<1 + fprintf(stderr, "Please upgrade to gcc-3.1 or greater\n"); + push_stack(ComValue::nullval()); + return; + #endif + + if (hostv.is_string() && portv.is_known() && cmdstrv.is_string()) { + + const char* hoststr = hostv.string_ptr(); + const char* portstr = portv.is_string() ? portv.string_ptr() : nil; + u_short portnum = portstr ? atoi(portstr) : portv.ushort_val(); + ACE_INET_Addr addr (portnum, hoststr); + ACE_SOCK_Stream socket; + ACE_SOCK_Connector conn; + if (conn.connect (socket, addr) == -1) { + ACE_ERROR ((LM_ERROR, "%p\n", "open")); + push_stack(ComValue::nullval()); + return; + } + + #if __GNUC__<3 + filebuf ofbuf; + ofbuf.attach(socket.get_handle()); + #else + fileptr_filebuf ofbuf((int)socket.get_handle(), ios_base::out, + false, static_cast<size_t>(BUFSIZ)); + #endif + ostream out(&ofbuf); + const char* cmdstr = cmdstrv.string_ptr(); + out << cmdstr; + if (cmdstr[strlen(cmdstr)-1] != '\n') out << "\n"; + out.flush(); + if (nowaitv.is_false()) { + #if __GNUC__<3 + filebuf ifbuf; + ifbuf.attach(socket.get_handle()); + istream in(&ifbuf); + char* buf; + in.gets(&buf); + #else + char buf[BUFSIZ]; + int i=0; + do { + read(socket.get_handle(), buf+i++, 1); + } while (i<BUFSIZ-1 && buf[i-1]!='\n'); + if (buf[i]=='\n') buf[i]==0; + #endif + ComValue& retval = comterpserv()->run(buf, true); + push_stack(retval); + } + + if (socket.close () == -1) + ACE_ERROR ((LM_ERROR, "%p\n", "close")); + } + + return; + + #else + + cerr << "for the remote command to work rebuild comterp with ACE\n"; + return; + + #endif + #endif + + } + Index: DrawServ/drawfunc.h diff -c /dev/null DrawServ/drawfunc.h:1.1 *** /dev/null Thu Feb 12 13:27:08 2004 --- src/DrawServ/drawfunc.h Thu Feb 12 13:27:07 2004 *************** *** 0 **** --- 1,41 ---- + /* + * Copyright (c) 2004 Scott E. Johnston + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + + #if !defined(_drawfunc_h) + #define _drawfunc_h + + #include <DrawServ/draweditor.h> + #include <ComUnidraw/unifunc.h> + + //: command to connect to another drawserv + // drawserv(hoststr :port portnum) -- connect to remote drawserv + class DrawServFunc : public UnidrawFunc { + public: + DrawServFunc(ComTerp*,DrawEditor*); + virtual void execute(); + virtual const char* docstring() { + return "%s(hoststr :port portnum) -- connect to remote drawserv"; } + }; + + #endif /* !defined(_drawfunc_h) */ + Index: DrawServ/drawserv.c diff -c /dev/null DrawServ/drawserv.c:1.1 *** /dev/null Thu Feb 12 13:27:08 2004 --- src/DrawServ/drawserv.c Thu Feb 12 13:27:07 2004 *************** *** 0 **** --- 1,42 ---- + /* + * Copyright (c) 2004 Scott E. Johnston + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + + /* + * Implementation of DrawServ class. + */ + + #include <DrawServ/drawserv.h> + / ************************************************************************ *****/ + + DrawServ::DrawServ (Catalog* c, int& argc, char** argv, + OptionDesc* od, PropertyData* pd) + : OverlayUnidraw(c, argc, argv, od, pd) { + } + + DrawServ::DrawServ (Catalog* c, World* w) + : OverlayUnidraw(c, w) { + } + + DrawServ::~DrawServ () + { + } Index: DrawServ/drawserv.h diff -c /dev/null DrawServ/drawserv.h:1.1 *** /dev/null Thu Feb 12 13:27:08 2004 --- src/DrawServ/drawserv.h Thu Feb 12 13:27:07 2004 *************** *** 0 **** --- 1,47 ---- + /* + * Copyright (c) 2004 Scott E. Johnston + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + + /* + * DrawServ - Unidraw derived from OverlayUnidraw for DrawServ library + */ + #ifndef drawserv_h + #define drawserv_h + + #include <OverlayUnidraw/ovunidraw.h> + + //: Unidraw specialized for DrawServ + // Unidraw (OverlayUnidraw) specialized for DrawServ application. + // Networked application of the Unidraw framework. + class DrawServ : public OverlayUnidraw { + public: + DrawServ( + Catalog*, int& argc, char** argv, + OptionDesc* = nil, PropertyData* = nil + ); + DrawServ(Catalog*, World*); + virtual ~DrawServ(); + + protected: + }; + + #endif Index: drawserv_/main.c diff -c drawserv_/main.c:1.2 drawserv_/main.c:1.3 *** drawserv_/main.c:1.2 Fri Jan 30 11:12:57 2004 --- src/drawserv_/main.c Thu Feb 12 13:27:09 2004 *************** *** 1,4 **** --- 1,5 ---- /* + * Copyright (c) 2004 Scott E. Johnston * Copyright (c) 1994-1999 Vectaport, Inc. * Copyright (c) 1990, 1991 Stanford University * *************** *** 36,44 **** #include <DrawServ/drawcatalog.h> #include <DrawServ/drawcreator.h> #include <DrawServ/drawcomps.h> #include <DrawServ/drawkit.h> - #include <FrameUnidraw/frameeditor.h> #include <GraphUnidraw/grapheditor.h> #include <OverlayUnidraw/ovellipse.h> --- 37,46 ---- #include <DrawServ/drawcatalog.h> #include <DrawServ/drawcreator.h> #include <DrawServ/drawcomps.h> + #include <DrawServ/draweditor.h> #include <DrawServ/drawkit.h> + #include <DrawServ/drawserv.h> #include <GraphUnidraw/grapheditor.h> #include <OverlayUnidraw/ovellipse.h> *************** *** 213,219 **** #endif DrawCreator creator; DrawCatalog* catalog = new DrawCatalog("ivtools drawserv", &creator); ! OverlayUnidraw* unidraw = new OverlayUnidraw( catalog, argc, argv, options, properties ); --- 215,221 ---- #endif DrawCreator creator; DrawCatalog* catalog = new DrawCatalog("ivtools drawserv", &creator); ! DrawServ* unidraw = new DrawServ( catalog, argc, argv, options, properties ); *************** *** 272,282 **** } else { const char* initial_file = (argc == 2) ? argv[1] : nil; ! FrameEditor* ed = nil; if (initial_file) ! ed = new FrameEditor(initial_file, DrawKit::Instance()); else ! ed = new FrameEditor(new DrawIdrawComp, DrawKit::Instance()); unidraw->Open(ed); --- 274,284 ---- } else { const char* initial_file = (argc == 2) ? argv[1] : nil; ! DrawEditor* ed = nil; if (initial_file) ! ed = new DrawEditor(initial_file, DrawKit::Instance()); else ! ed = new DrawEditor(new DrawIdrawComp, DrawKit::Instance()); unidraw->Open(ed); Index: top_ivtools/MANIFEST diff -c top_ivtools/MANIFEST:1.2 top_ivtools/MANIFEST:1.3 *** top_ivtools/MANIFEST:1.2 Tue Feb 10 11:40:58 2004 --- ./MANIFEST Thu Feb 12 13:26:51 2004 *************** *** 281,288 **** --- 281,294 ---- ivtools-1.1/src/DrawServ/drawcomps.h ivtools-1.1/src/DrawServ/drawcreator.c ivtools-1.1/src/DrawServ/drawcreator.h + ivtools-1.1/src/DrawServ/draweditor.c + ivtools-1.1/src/DrawServ/draweditor.h + ivtools-1.1/src/DrawServ/drawfunc.c + ivtools-1.1/src/DrawServ/drawfunc.h ivtools-1.1/src/DrawServ/drawkit.c ivtools-1.1/src/DrawServ/drawkit.h + ivtools-1.1/src/DrawServ/drawserv.c + ivtools-1.1/src/DrawServ/drawserv.h ivtools-1.1/src/DrawServ/drawviews.c ivtools-1.1/src/DrawServ/drawviews.h ivtools-1.1/src/FrameUnidraw/Imakefile Index: top_ivtools/MANIFEST.perceps diff -c top_ivtools/MANIFEST.perceps:1.1 top_ivtools/MANIFEST.perceps:1.2 *** top_ivtools/MANIFEST.perceps:1.1 Fri Jan 9 11:42:09 2004 --- ./MANIFEST.perceps Thu Feb 12 13:26:52 2004 *************** *** 69,75 **** --- 69,78 ---- DrawServ/drawclasses.h DrawServ/drawcomps.h DrawServ/drawcreator.h + DrawServ/draweditor.h + DrawServ/drawfunc.h DrawServ/drawkit.h + DrawServ/drawserv.h DrawServ/drawviews.h FrameUnidraw/framecatalog.h FrameUnidraw/frameclasses.h *** /dev/null Thu Feb 12 13:27:16 PST 2004 --- patches/ivtools-040212-johnston-010 *************** patches/ivtools-040212-johnston-010 *** 0 **** --- 1 ---- + ivtools-040212-johnston-010 |