NCBI C Toolkit Cross Reference

C/sequin/sequiny.c


  1 /*   sequiny.c
  2 * ===========================================================================
  3 *
  4 *                            PUBLIC DOMAIN NOTICE
  5 *            National Center for Biotechnology Information (NCBI)
  6 *
  7 *  This software/database is a "United States Government Work" under the
  8 *  terms of the United States Copyright Act.  It was written as part of
  9 *  the author's official duties as a United States Government employee and
 10 *  thus cannot be copyrighted.  This software/database is freely available
 11 *  to the public for use. The National Library of Medicine and the U.S.
 12 *  Government do not place any restriction on its use or reproduction.
 13 *  We would, however, appreciate having the NCBI and the author cited in
 14 *  any work or product based on this material
 15 *
 16 *  Although all reasonable efforts have been taken to ensure the accuracy
 17 *  and reliability of the software and data, the NLM and the U.S.
 18 *  Government do not and cannot warrant the performance or results that
 19 *  may be obtained by using this software or data. The NLM and the U.S.
 20 *  Government disclaim all warranties, express or implied, including
 21 *  warranties of performance, merchantability or fitness for any particular
 22 *  purpose.
 23 *
 24 * ===========================================================================
 25 *
 26 * File Name:  sequiny.c
 27 *
 28 * Author:  Jim Ostell
 29 *
 30 * Version Creation Date:   5/24/96
 31 *
 32 * $Revision: 6.1 $
 33 *
 34 * File Description:
 35 *    This is a companion file to sequinx.c. In order to register additional proceedures
 36 *    of your own design, to replace or supplement those intrinsic to sequin,
 37 *    we have provided sequinx.c where you can register your functions with the
 38 *    object manager. For demonstration purposes, we have included a REGISTER call
 39 *    (commented out) to functions in this file.
 40 *
 41 *    This file contains the demonstration functions themselves, as well as extensive
 42 *    comments describing what they do. They are intended to serve as a model for what
 43 *    you might do in a file of your own design.
 44 *
 45 *    Basically, to register a proceedure with the object manager, you call a function
 46 *    which specifies a name for the function, a string to show in a menu, an input
 47 *    data type (OBJ_ in objmgr.h), possibly a subtype, and an output type, and possibly
 48 *    a subtype, the type of function (filter, editor, etc), and a pointer to the function
 49 *    to be called. The called function always
 50 *    returns an Int2 (whose values are defined in objmgr.h as OM_MSG_RET_...) and takes
 51 *    a single Pointer as an argument. This pointer always must be cast to an OMProcControlPtr
 52 *    (objmgr.h) which contains the input arguments. It is only declared as a Pointer because
 53 *    of C typedef order limitations. We will call this function the "work" function.
 54 *
 55 *    The work function does the real job. It looks at the contents of the data pointer,
 56 *    executes the appropriate actions and returns a completion or error code. Normally it
 57 *    will return one of:
 58 *      OM_MSG_RET_ERROR - an error occurred, presumably reported with ErrPostEx()
 59 *      OM_MSG_RET_OK - everything was ok, but this function did not do anything.
 60 *      OM_MSG_RET_DONE - everything was ok, and this function did the processing requested.
 61 *
 62 *    When the object manager looks for a function to satisfy a request it enters a loop
 63 *    which goes through appropriate functions until the action is done. First, it goes
 64 *    through all registered functions of the requested class (editor, filter,..) in priority
 65 *    order. First it looks for a match of type, and subtype. Failing that, it looks for a
 66 *    match to type, with subtype = 0 (any). For each match, it calls the function with the
 67 *    data. If the functions returns OM_MSG_RET_ERROR, or OM_MSG_RET_OK, the object manager
 68 *    tries the next function. When a function returns OM_MSG_RET_DONE or there are no more
 69 *    matching functions, the object manager returns. This means your functions can be called
 70 *    before or after the default functions (priority), or by specifying a subtype not
 71 *    supported by a default function. You can have your function called first, check the
 72 *    data to decide if you want to handle it, return OM_MSG_RET_DONE if you do, or 
 73 *    OM_MSG_RET_OK if you want the object manager to find some other function to handle it.
 74 *
 75 *    If you wish your function to receive messages from the object manager you must also
 76 *    supply a message loop function and register it with the object manager when your
 77 *    function is first called. You must remember to unregister it when your function exits.
 78 *    If your function performs some quick computation and returns, you probably don't need
 79 *    a message loop function. If it will persist awhile (like an editor or viewer) you
 80 *    probably will. This is for cases such as 1) your function is a viewer showing Bioseq X
 81 *    2) some other function is an editor on Bioseq X. When Bioseq X is updated in the editor
 82 *    it will send an update message to the object manager. Your function will want to receive
 83 *    this message so it can update its display from the underlying (now edited) data
 84 *    appropriately. Your message loop should return OM_MSG_RET_OK (not _DONE) so the object
 85 *    manager will continue to relay the message to all functions that want to see it.
 86 *
 87 *     
 88 *
 89 * Modifications:  
 90 * --------------------------------------------------------------------------
 91 * Date     Name        Description of modification
 92 * -------  ----------  -----------------------------------------------------
 93 *
 94 *
 95 * ==========================================================================
 96 */
 97 
 98 #include <gather.h>
 99 #include "sequin.h"
100 #include "sequiny.h"
101 
102 
103                                                         /** prototype for message loop function **/
104 static Int2 LIBCALLBACK MyBioseqEditMsgFunc (OMMsgStructPtr ommsp);
105 
106 Int2 LIBCALLBACK MyBioseqEditFunc (Pointer data)
107 {
108   BioseqPtr         bsp;
109   OMProcControlPtr  ompcp;
110   Char buf[41];
111   OMUserDataPtr omudp;  /* user data structure used for message loop */
112   Uint2 userkey;        /* used to track omudp uniquely */
113 
114   ompcp = (OMProcControlPtr) data;   /* always do this cast */
115 
116                                                                          /* check that all is cool */
117   if (ompcp == NULL) return OM_MSG_RET_ERROR;
118   if (ompcp->input_itemtype != OBJ_BIOSEQ) return OM_MSG_RET_ERROR;
119 
120   if (ompcp->input_data == NULL)     /* no BioseqPtr yet */
121   {
122           if (! GatherDataForProc (ompcp, FALSE))  /* find it -- gather.h */
123           {
124                   ErrPostEx(SEV_ERROR,0,0,"MyBioseqEditFunc: couldn't gather BioseqPtr");
125                   return OM_MSG_RET_ERROR;
126           }
127   }
128 
129   bsp = (BioseqPtr)(ompcp->input_data);   /* get the pointer */
130 
131   BioseqLabel(bsp, buf, 40, OM_LABEL_BOTH);   /* make a text string to show */
132 
133   Message(MSG_OK, "MyBioseqEditFunc called with [%s]", buf);   /* show it */
134 
135   /* assuming we need a message loop ************************************************/
136 
137         userkey = OMGetNextUserKey ();            /* get a unique key for this proc instance */
138                                               /* only necessary if the same proc could be
139                                                                                      invoked multiple times at once */
140                                               /* attach data to the entity for this procedure */
141         omudp = ObjMgrAddUserData(ompcp->input_entityID, ompcp->proc->procid, OMPROC_EDIT, userkey);
142         omudp->userdata.ptrvalue = (Pointer)bsp; /* this could point to any data */
143         omudp->messagefunc = MyBioseqEditMsgFunc; /* add my message loop */
144 
145 
146                                               /* now we can send a message to ourselves */
147                                               /* just to prove it works. The message could just
148                                                                                   /* as well be from another proceedure though */
149 
150         ObjMgrSendMsg (OM_MSG_SELECT, ompcp->input_entityID, 0, 0);
151 
152    /*** end of message loop setup ***************************************************/
153 
154         /** here you would do whatever work you wanted on this entry **/
155         /** in this case we will just arbitrarily change the length to 10 */
156 
157         bsp->length = 10;              /* make the change */
158                                    /* inform any listening proceedures */
159         ObjMgrSendMsg (OM_MSG_UPDATE, ompcp->input_entityID, ompcp->input_itemID, ompcp->input_itemtype);
160 
161   /*** if we set up the message loop, we need to clean up before we leave *****/
162 
163         ObjMgrFreeUserData(ompcp->input_entityID, ompcp->proc->procid, OMPROC_EDIT, userkey);
164 
165   /**  Now we are done. Give a Done return code *******************************/
166 
167         return OM_MSG_RET_DONE;
168 }
169 
170 /******************************************************************************************
171 *
172 *  Here's the sample message loop function. It really does nothing but say hello
173 *
174 *******************************************************************************************/
175 static Int2 LIBCALLBACK MyBioseqEditMsgFunc (OMMsgStructPtr ommsp)
176 {
177         OMUserDataPtr omudp;
178         BioseqPtr bsp;
179         Char buf[41];
180    
181         omudp = (OMUserDataPtr)(ommsp->omuserdata);
182         bsp = (BioseqPtr)(omudp->userdata.ptrvalue);
183 
184         BioseqLabel(bsp, buf, 40, OM_LABEL_BOTH);   /* make a text string to show */
185         
186         switch (ommsp->message)
187         {
188                 case OM_MSG_DEL:
189                         break;
190                 case OM_MSG_CREATE:
191                         break;
192                 case OM_MSG_UPDATE:
193                         Message(MSG_OK, "Got an update message on [%s]", buf);
194                         break;
195                 case OM_MSG_SELECT:          /* add highlight code */
196                         Message(MSG_OK, "Got a select message on [%s]", buf);
197                         break;
198                 case OM_MSG_DESELECT:        /* add deselect code */
199                         break;
200                 case OM_MSG_CACHED:
201                         break;
202                 case OM_MSG_UNCACHED:
203                         break;
204                 case OM_MSG_TO_CLIPBOARD:  /* this is just because no clipboard now */
205                         break;
206                 default:
207                         break;
208         }
209 
210         return OM_MSG_RET_OK;
211 }
212 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.