package frama-c

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file kernel_project.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
(**************************************************************************)
(*                                                                        *)
(*  This file is part of Frama-C.                                         *)
(*                                                                        *)
(*  Copyright (C) 2007-2024                                               *)
(*    CEA (Commissariat à l'énergie atomique et aux énergies              *)
(*         alternatives)                                                  *)
(*                                                                        *)
(*  you can redistribute it and/or modify it under the terms of the GNU   *)
(*  Lesser General Public License as published by the Free Software       *)
(*  Foundation, version 2.1.                                              *)
(*                                                                        *)
(*  It 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 Lesser General Public License for more details.                   *)
(*                                                                        *)
(*  See the GNU Lesser General Public License version 2.1                 *)
(*  for more details (enclosed in the file licenses/LGPLv2.1).            *)
(*                                                                        *)
(**************************************************************************)

open Data
module Md = Markdown
module Js = Yojson.Basic.Util
module Pkg = Package

let package = Pkg.package ~name:"project"
    ~title:"Project Management" ~readme:"project.md" ()

(* -------------------------------------------------------------------------- *)
(* --- Project Info                                                       --- *)
(* -------------------------------------------------------------------------- *)

module ProjectId = (val jkey ~kind:"project")

module ProjectInfo =
struct
  type t = Project.t
  let jtype = Data.declare ~package
      ~name:"projectInfo"
      ~descr:(Md.plain "Project informations")
      Pkg.(Jrecord [
          "id",ProjectId.jtype;
          "name",Jalpha;
          "current",Jboolean;
        ])

  let of_json js =
    Js.member "id" js |> Js.to_string |> Project.from_unique_name

  let to_json p =
    `Assoc [
      "id", `String (Project.get_unique_name p) ;
      "name", `String (Project.get_name p) ;
      "current", `Bool (Project.is_current p) ;
    ]
end

(* -------------------------------------------------------------------------- *)
(* --- Project Requests                                                   --- *)
(* -------------------------------------------------------------------------- *)

(*
module ProjectRequest =
struct

  (* forward request on a given project *)

  type t = Project.t * string * json

  let jtype = Data.declare ~package ~name:"projectRequest"
      ~descr:(Md.plain "Request to be executed on the specified project.")
      (Jrecord [
          "project",ProjectId.jtype;
          "request",Jstring;
          "data",Jany;
        ])

  let of_json js =
    begin
      Project.from_unique_name Js.(member "project" js |> to_string) ,
      Js.(member "request" js |> to_string) ,
      Js.(member "data" js)
    end

  let process kind (project,request,data) =
    match Main.find request with
    | Some(kd,handler) when kd = kind -> Project.on project handler data
    | Some _ -> failwith (Printf.sprintf "Incompatible kind for '%s'" request)
    | None -> failwith (Printf.sprintf "Request '%s' undefined" request)

end
*)

(* -------------------------------------------------------------------------- *)
(* --- Project Requests                                                   --- *)
(* -------------------------------------------------------------------------- *)

(*
let () = Request.register ~package
    ~kind:`GET ~name:"getCurrent"
    ~descr:(Md.plain "Returns the current project")
    ~input:(module Junit) ~output:(module ProjectInfo)
    Project.current

let () = Request.register ~package
    ~kind:`SET ~name:"setCurrent"
    ~descr:(Md.plain "Switches the current project")
    ~input:(module ProjectId) ~output:(module Junit)
    (fun pid -> Project.(set_current (from_unique_name pid)))
*)

let () = Request.register ~package
    ~kind:`GET ~name:"getList"
    ~descr:(Md.plain "Returns the list of all projects")
    ~input:(module Junit) ~output:(module Jlist(ProjectInfo))
    (fun () -> Project.fold_on_projects (fun ids p -> p :: ids) [])

(*
let () = Request.register ~package
    ~kind:`GET ~name:"getOn"
    ~descr:(Md.plain "Execute a GET request within the given project")
    ~input:(module ProjectRequest) ~output:(module Jany)
    (ProjectRequest.process `GET)

let () = Request.register ~package
    ~kind:`SET ~name:"setOn"
    ~descr:(Md.plain "Execute a SET request within the given project")
    ~input:(module ProjectRequest) ~output:(module Jany)
    (ProjectRequest.process `SET)

let () = Request.register ~package
    ~kind:`EXEC ~name:"execOn"
    ~descr:(Md.plain "Execute an EXEC request within the given project")
    ~input:(module ProjectRequest) ~output:(module Jany)
    (ProjectRequest.process `EXEC)
*)

(* -------------------------------------------------------------------------- *)
(* --- Project Management                                                 --- *)
(* -------------------------------------------------------------------------- *)

let () =
  Request.register
    ~package
    ~descr:(Md.plain "Create a new project")
    ~kind:`SET
    ~name:"create"
    ~input:(module Jstring)
    ~output:(module ProjectInfo)
    Project.create

(* -------------------------------------------------------------------------- *)
OCaml

Innovation. Community. Security.