github.com/amp-space/amp-sdk-go@v0.7.6/amp/api.app.go (about) 1 package amp 2 3 import ( 4 "net/url" 5 6 "github.com/amp-space/amp-sdk-go/stdlib/task" 7 ) 8 9 // App is how an app module is registered with an amp.Host so it can be invoked. 10 // 11 // An App is invoked by a client or other app via the app's UID or URI. 12 type App struct { 13 14 // AppID identifies this app with form "{AppNameID}.{FamilyID}.{PublisherID}" -- e.g. "filesys.hosting.arcspace.systems" 15 // - PublisherID: typically the domain name of the publisher of this app -- e.g. "arcspace.systems" 16 // - FamilyID: encompassing namespace ID used to group related apps (no spaces or punctuation) 17 // - AppNameID: identifies this app within its parent family and domain (no spaces or punctuation) 18 // 19 // AppID form is consistent with a URL domain name (and subdomains). 20 AppID string 21 UID UID // Universally unique and persistent ID for this module (and the module's "home" planet if present) 22 Desc string // Human-readable description of this app 23 Version string // "v{MajorVers}.{MinorID}.{RevID}" 24 Dependencies []UID // Module UIDs this app may access 25 Invocations []string // Additional aliases that invoke this app 26 AttrDecl []string // Attrs to be resolved and registered with a HostSession 27 28 // NewAppInstance is the entry point for an App. 29 // Called when an App is invoked on an active User session and is not yet running. 30 NewAppInstance func() AppInstance 31 } 32 33 // AppContext is provided by the arc runtime to an AppInstance for support and context. 34 type AppContext interface { 35 task.Context // Allows select{} for graceful handling of app shutdown 36 AssetPublisher // Allows an app to publish assets for client consumption 37 Session() HostSession // Access to underlying Session 38 39 // Returns the absolute file system path of the app's local read-write directory. 40 // This directory is scoped by the app's UID. 41 LocalDataPath() string 42 43 // Issues a mew cell ID guaranteed to be universally unique. 44 // This should not be called concurrently with other IssueCellID() calls. 45 IssueCellID() CellID 46 47 // Gets the named cell and attribute from the user's home planet -- used high-level app settings. 48 // The attr is scoped by both the app UID so key collision with other users or apps is not possible. 49 // This is how an app can store and retrieve settings. 50 GetAppCellAttr(attrSpec string, dst ElemVal) error 51 52 // Write analog for GetAppCellAttr() 53 PutAppCellAttr(attrSpec string, src ElemVal) error 54 } 55 56 // AppInstance is implemented by an App and invoked by amp.Host responding to a client pin request. 57 type AppInstance interface { 58 AppContext // The arc runtime's app context support exposed 59 60 // Instantiation callback made immediately after App.NewAppInstance() -- typically resolves app-specific type specs. 61 OnNew(this AppContext) error 62 63 // Celled when the app is pin the cell IAW with the given request. 64 // If parent != nil, this is the context of the request. 65 // If parent == nil, this app was invoked without out a parent cell / context. 66 PinCell(parent PinnedCell, req PinReq) (PinnedCell, error) 67 68 // Handles a meta message sent to this app, which could be any attr type. 69 HandleURL(*url.URL) error 70 71 // Called exactly once when an app is signaled to close. 72 OnClosing() 73 } 74 75 // Cell is an interface for an app Cell 76 type Cell interface { 77 78 // Returns this cell's immutable info. 79 Info() CellID 80 } 81 82 // PinnedCell is how your app encapsulates a pinned cell to the host runtime and thus clients. 83 type PinnedCell interface { 84 Cell 85 86 // Apps spawn a PinnedCell as a child task.Context of amp.AppContext.Context or as a child of another PinnedCell. 87 // This means an AppContext contains all its PinnedCells and thus Close() will close all PinnedCells. 88 Context() task.Context 89 90 // Pins the requested cell (typically a child cell). 91 PinCell(req PinReq) (PinnedCell, error) 92 93 // Pushes this cell and child cells to the client. 94 // Exits when either: 95 // - ctx.Closing() is signaled, 96 // - state has been pushed to the client AND ctx.MaintainSync() == false, or 97 // - an error is encountered 98 ServeState(ctx PinContext) error 99 100 // Merges a set of incoming changes into this pinned cell. -- a "write" operation 101 MergeUpdate(tx *Msg) error 102 } 103 104 // Serialization abstraction 105 type PbValue interface { 106 Size() int 107 MarshalToSizedBuffer(dAtA []byte) (int, error) 108 Unmarshal(dAtA []byte) error 109 } 110 111 // ElemVal wraps cell attribute element name and serialization. 112 type ElemVal interface { 113 114 // Returns the element type name (a degenerate AttrSpec). 115 TypeName() string 116 117 // Marshals this ElemVal to a buffer, reallocating if needed. 118 MarshalToBuf(dst *[]byte) error 119 120 // Unmarshals and merges value state from a buffer. 121 Unmarshal(src []byte) error 122 123 // Creates a default instance of this same ElemVal type 124 New() ElemVal 125 } 126 127 // MultiTx is a multi-cell state update for a pinned cell or a container of meta attrs. 128 type MultiTx struct { 129 ReqID uint64 // allows replies to be routed to the originator 130 Status ReqStatus 131 CellTxs []CellTx 132 } 133 134 // CellTx is a state update for a cell pushed to a client. 135 type CellTx struct { 136 Op CellTxOp // The tx operation to perform 137 TargetCell CellID // The cell being modified 138 ElemsPb []*AttrElemPb // Attr element run (serialized) 139 } 140 141 type AttrElem struct { 142 Val ElemVal // Val is the abstraction interface allowing serialization and type string-ification 143 SI int64 // SI is the SeriesIndex, which is described in the AttrSpec.SeriesIndexType 144 AttrID uint32 // AttrID is the native ID (AttrSpec.DefID) that fully names an AttrSpec 145 } 146 147 type AttrDef struct { 148 Client AttrSpec 149 Native AttrSpec 150 } 151 152 type AttrSet struct { 153 ClientDefID uint32 // READ-ONLY 154 NativeDefID uint32 // READ-ONLY 155 Attrs []AttrDef // READ-ONLY 156 } 157 158 /* 159 type UID3 [3]uint64 160 161 type AttrSeriesEntry struct { 162 SeriesID UID3 163 ElemTypeID UID3 164 AttrSpec AttrSpec 165 166 167 CellID UID3 168 AttrID UID3 169 SI UID3 170 Height int64 171 Hash UID3 // HAshes from the previous revision 172 } 173 */