Driver question

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Driver question

Sean Hinde-2

Hi,

>     I would like to do sone parsing of data. What is the best
> way to do this? I
> have an integer and I would like to make sure that is is a
> particular length
> and that it is comprised entirly of digits. I have looked at
> io_lib and a
> number of other spots but havent really found anything too
> elegant.  Everything
> seems to involve converting to strings or using large
> function gaurds. If this
> is the way to go I will, but if anyone has a better idea I
> would like to know.
> I am always parsing packets in erlang so any info on that in
> general would be
> nice.

I'm not sure quite what you are getting at here. If it is an integer then I
don't see how it can contain anything other than digits. If you have it as a
list (e.g [0,0,1,2,3]) the best solution I have come up with is to convert
it to ascii representation and use the BIF list_to_integer("00123"). I agree
it isn't really that pretty.

For just about every other kind of packet parsing the bit syntax is just too
cool for words.

>     I have an application running that emails the interested
> parties when it
> goes down. I have accomplished this in a way that I think is
> rather kludgy. I
> use a linked process that traps exit signals from my main
> supervisor. I was
> wondering if there is a call back that is called during the
> shutdown sequence
> of the app that I could use to make sure that the email is
> sent on the death of
> the app.

We usually send out an SNMP trap when apps die. There is a callback provided
for exactly this in the standard application template provided in the emacs
mode (included below).

Cheers,
Sean

-module(test).
-author('shinde').

%%-compile(export_all).
%%-export([Function/Arity, ...]).

-behaviour(application).

%% application callbacks
-export([start/2, stop/1]).

%%%----------------------------------------------------------------------
%%% Callback functions from application
%%%----------------------------------------------------------------------

%%----------------------------------------------------------------------
%% Func: start/2
%% Returns: {ok, Pid}        |
%%          {ok, Pid, State} |
%%          {error, Reason}  
%%----------------------------------------------------------------------
start(Type, StartArgs) ->
    case 'TopSupervisor':start_link(StartArgs) of
        {ok, Pid} ->
            {ok, Pid};
        Error ->
            Error
    end.

%%----------------------------------------------------------------------
%% Func: stop/1
%% Returns: any
%%----------------------------------------------------------------------
stop(State) ->
    send_email_from_here(State),
    ok.



NOTICE AND DISCLAIMER:
This email (including attachments) is confidential.  If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents.  We cannot accept liability for any breaches of
confidence arising through use of email.  Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions.  We will not accept responsibility for any commitments
made by our employees outside the scope of our business.  We do not warrant
the accuracy or completeness of such information.